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 读取指定文件的信息并拼接成指定格式
随机推荐
- mysql 互为主从复制常见问题
报错:1)change master导致的: Last_IO_Error: error connecting to master - retry-time: 60 retr ...
- AngularJS中serivce,factory,provider的区别
一.service引导 刚开始学习Angular的时候,经常被误解和被初学者问到的组件是 service(), factory(), 和 provide()这几个方法之间的差别.This is whe ...
- javascript事件委托和jQuery事件绑定on、off 和one
一. 事件委托什么是事件委托?用现实中的理解就是:有100 个学生同时在某天中午收到快递,但这100 个学生不可能同时站在学校门口等,那么都会委托门卫去收取,然后再逐个交给学生.而在jQuery 中, ...
- has leaked ServiceConnection com.baidu.location.LocationClient
02-06 05:01:52.806: E/ActivityThread(1120): Activity com.project.xxxActivity $1@45fc5af8 that was or ...
- FTP配置参数
格式 vsftpd.conf 的格式非常简单,每行要么是一个注释,要么是一个指令.注释行以#开始并被忽略掉.指令行格式如下: 配置项=参数值 很重要的一点是,这个格式里不存在任何空格. 默认的,每一个 ...
- FMDB将对象放进数据库[一]
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- AprioriTID algorithm
What is AprioriTID? AprioriTID is an algorithm for discovering frequent itemsets (groups of items ap ...
- Unix主机syslog配置
将下面的内容附加到/etc/syslog.conf文件中(注意*和@之间是有空格的): *.* @ip 修改/etc/services文件中的syslog服务的端口号为上面提到的Syslog监听端口. ...
- TagBuilder 性能如此低下?
本文来自:http://www.cnblogs.com/zhuisha/archive/2010/03/12/1684022.html 需要通过ASP.NET MVC生成一个列表,MVC里面根正苗红的 ...
- 【最大点独立集】【poj1419】【Graph Coloring】
题意: 最多能选取多少点,没有边相连. 解法: 取反图,求最大团 代码: #include<cstdio> #include<cstring> #include<iost ...