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 读取指定文件的信息并拼接成指定格式
随机推荐
- Oprofile安装与使用探索
本文分别尝试了oprofile在x86平台和龙芯平台上的安装 一:oprofile的安装与配置(intel+ubuntu12.04) I. Oprofile 安装 Oprofile 包含在 Linux ...
- gcc常用命令集
引用:http://developer.51cto.com/art/200609/32317_1.htm 对于GUN编译器来说,程序的编译要经历预处理.编译.汇编.连接四个阶段 假设源程序文件名为te ...
- jq插件第二款来袭 图片滚动
这第二款也是非常实用的插件,也是与图片相关,关于图片的需求太多了,这个是图片滚动哦,不过不是无缝滚动,是左像右滚动,到头的话再往回滚动,利用scrollLeft实现的,支持自动滚动和每次滚动的个数默认 ...
- Samba服务器
Windows操作系统下:DOC命令下:netstat -an查看端口 (一)简介 文件服务器 (二)端口 smbd: 为clinet提高资源访问 tcp 139 445 (类似于windo ...
- 无法关闭的QT程序——思路开阔一下,原来这么简单!
做一个无法关闭的QT程序(想关闭时要在任务管理器里关闭),看似很难, 其实它并不难,只要让程序在关闭时启动它自身就可以了. 上代码: #include <QtGui> class Temp ...
- c# 正则表达式对网页进行内容抓取
原文 c# 正则表达式对网页进行内容抓取 搜索引擎中一个比较重要的环节就是从网页中抽取出有效内容.简单来说,就是吧HTML文本中的HTML标记去掉,留下我们用IE等浏览器打开HTML文档看到的部分(我 ...
- 蓝桥杯之JAM的计数法
题目描述 Jam是个喜欢标新立异的科学怪人.他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩.在他的计数法中,每个数字的位数都是相同的(使用相同个数的字母),英文字 ...
- 【LeetCode练习题】Scramble String
Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two no ...
- python mysqlDB
1,Description MySQLdb is a Python DB API-2.0-compliant interface Supported versions: * MySQL version ...
- 基于winform的二进制图片数据的存取(用于数据库照片的读写处理)
编程目的:文本框1中输入id号,则从openFileDialog中选择的图片会以二进制数据存进SQL数据库的对应表的id列:文本框2中输入姓名,从数据库读取对应name的照片并显示在pictureBo ...