jmake 编译当前目录c/c++单文件 指定文件 可加选项
基础版本的jmake是将所有当前文件夹下的C/C++文件生成单文件编译命令,并且jmake命令不可加选项。
现在做的改进是能在输入命令jmake时加上一些选项了,‘-’开头的选项加入到每个编译单文件的生成命令中去,其他的选项则是指定要编译的源文件。当然,如果没有指定源文件,就把所有.c,.cc,.cpp文件都分别编译。
代码如下:
/*
* author: huanglianjing
*
* this is a program to compile all single c/c++ file of current directory
*
* usage: jmake <files> <-options>
* if no files assigned, all files in directory will be searched
* any option will be added to every instruction
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
][], option[][];
int filenum, optionnum;
];
int file_in_argv(char *filename)//whether filename in argv
{
int i;
; i<filenum; ++i) {
) ;
}
;
}
void suffix(char *filename)//get filetype, return empty string if not has
{
int len = strlen(filename);
int pos;
; pos>=; --pos) {
if (filename[pos] == '.') break;
}
|| pos == len-) suf[] = ;
else {
int i;
; i<len--pos; ++i) suf[i] = filename[pos++i];
suf[len--pos] = ;
}
}
int main(int argc, char *argv[])
{
struct dirent *entry;
struct stat statbuf;
int i;
filenum = optionnum = ;
; i<argc; ++i) {
] == '-') {//option
strcpy(option[optionnum++],argv[i]);
}
else {//file
strcpy(file[filenum++],argv[i]);
}
}
DIR *dp = opendir(".");
;
while ((entry=readdir(dp)) != NULL) {
lstat(entry->d_name,&statbuf);
if (!S_ISDIR(statbuf.st_mode)) {
], ename[], instruction[];
strcpy(fname,entry->d_name);
strcpy(ename,entry->d_name);
|| file_in_argv(fname)) ;//consider this file
else continue;//not consider this file
int len = strlen(fname);
suffix(fname);
) {//.c
ename[len-] = '\0';
sprintf(instruction,"gcc %s -o %s",fname,ename);
; i<optionnum; ++i) {
strcat(instruction," ");
strcat(instruction,option[i]);
}
++insnum;
printf("%s\n",instruction);
system(instruction);
}
) {//.cc
ename[len-] = '\0';
sprintf(instruction,"g++ %s -o %s",fname,ename);
; i<optionnum; ++i) {
strcat(instruction," ");
strcat(instruction,option[i]);
}
++insnum;
printf("%s\n",instruction);
system(instruction);
}
) {//.cpp
ename[len-] = '\0';
sprintf(instruction,"g++ %s -o %s",fname,ename);
; i<optionnum; ++i) {
strcat(instruction," ");
strcat(instruction,option[i]);
}
++insnum;
printf("%s\n",instruction);
system(instruction);
}
}
}
) puts("no file compiled");
closedir(dp);
exit();
}
jmake 编译当前目录c/c++单文件 指定文件 可加选项的更多相关文章
- jmake 编译当前目录所有c/c++单文件
在一个目录下写一些单文件的c或者c++文件时,每次敲出命令如g++ a.cpp -o a感觉比较麻烦. 所以就模仿makefile的功能,实现了扫描当前目录,并将所有c文件.cc文件.cpp文件直接调 ...
- Nginx下载文件指定文件名称
配置 location ^~/TEMP/ { alias/share/files/; if ($request_uri ~* ^.*\/(.*)\.(txt|doc|pdf|rar|gz|zip|do ...
- scala 读取文件加下的指定文件
1,获取指定类型文件 def getFile(file:File): Array[File] ={ val files = file.listFiles().filter(! _.isDirector ...
- python实现在目录中查找指定文件的方法
python实现在目录中查找指定文件的方法 本文实例讲述了python实现在目录中查找指定文件的方法.分享给大家供大家参考.具体实现方法如下: 1. 模糊查找 代码如下: import os from ...
- dos 下删除文件、文件夹
删除文件 /p 删除每一个文件之前提示确认/f 强制删除只读文件 /s 从当前目录及所有子目录删除指定文件/q 安静模式.删除全局通配符时,不要求确认/a 根据属性选择要删除的文件 指定下列文件属性中 ...
- php清理当前目录下的指定文件和空目录(源码),建议服务器端执行
<?php /** * @desc 解析当前目录并递归删除目录下的指定文件 * @author mengdj<mengdj@outlook.com> 2014.10.02 1530 ...
- 如何解决Visual Studio2010 编译时提示系统找不到指定文件问题
前一段时间,开始使用vs2010编写程序,可是在编译的时候总是报错,提示系统找不到指定文件,导致无法正常运行程序,花了好久时间终于找到原因解决,是因为常规的输出目录 要与链接的常规的输出文件要相对应. ...
- [问题解决]gradle编译失败系统找不到指定的文件
[问题解决]gradle编译失败系统找不到指定的文件 问题描述 Error:C:\Users\diql.gradle\caches\2.14.1\scripts-remapped\settings_9 ...
- bat 读取当前目录指定文件信息并拼接
bat 读取指定文件的信息并拼接成指定格式
随机推荐
- USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)
这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我 ...
- Windows 端口和任务 查看 相关命令
netstat -aon|findstr " //查看端口 tasklist|findstr " //根据PID找到对应的程序 taskkill /f /t /im netbox. ...
- jquery操作session的方法
jquery.session.js使用 //此方法在java中不能使用 // jquery.session.js 简单使用方法 添加数据 $.session.set('key', 'value ...
- 关于微信小程序的一些思考
### 怎么样理解小程序? * 微信的重点产品* 一个事实OS,目前并不知道小程序的入口在哪里?* 小程序的入口可能在如下三个地方: 1. 发现入口 2. 扫码 3. 搜索框 * 小程序没有关注, 意 ...
- HTML5的结构学习(3) --- 综合运用
前面学习了HTML5新增的主体结构元素和新增的非主体结构元素, 而这里我们来学习如何去综合的运用这些新增元素. 1.大纲 HMTL5元素的关键就是将显示内容和便签类型紧密相关,提高了代码的语义化和可读 ...
- mac/linux install hg
MAC OSX 10.9: sudo port -v install mercurial or easy_install mercurial
- CKfinder中文乱码的解决.
最近在写一个类似博客的系统,使用了ckeditor和ckfinder,但是发现ckfinder在上传中文文件名的文件过程中会出现中文乱码的情况. 于是百度google乎,发现大多数的解决办法都是将文件 ...
- Ubuntu安装与初始配置
转载请注明作者:梦里风林 更多文章查看我的个人站: ahangchen.site 适用于Ubuntu版本 14.04/16.04LTS 64位 先上图 双系统安装 划分空闲磁盘,U盘安装ubuntu ...
- SQL Server 与 Windows 内存使用上的约定
什么时候SQL Server 会释放出自己的内存!以提供给别的程序用呢? --------------------------------------------------------------- ...
- 微软源代码管理工具TFS2013安装与使用图文教程
微软源代码管理工具TFS2013安装与使用图文教程 这篇文章主要介绍了微软源代码管理工具TFS2013安装与使用图文教程,本文详细的给出了TFS2013的安装配置过程.使用教程,需要的朋友可以参考下 ...