In a directory to write some of the single-file C or C + + files, each time to knock out commands such as g++ a.cpp-o a feeling more troublesome.
So just imitate makefile function, realize scan current directory, and all C file, cc file, CPP file directly call gcc/g++ compile.
One of the drawbacks of this program is that it cannot be used for inter-file include cases, because it is cumbersome to scan the code for other files. And you cannot add options for other libraries in the compile command.
How to use:
1 Jmake
Source:
1 /*2 * author:huanglianjing3 * 4 * This was a program-to-compile all single C + + file of current directory5 * 6 * Usage:jmake7 */8 9#include <stdio.h>Ten#include <stdlib.h> One#include <unistd.h> A#include <dirent.h> -#include <string.h> -#include <sys/stat.h> the - intMain () - { - structDirent *entry; + structstat statbuf; - +DIR *DP = Opendir ("."); A while((Entry=readdir (DP))! =NULL) { atLstat (entry->d_name,&statbuf); - if(!S_isdir (Statbuf.st_mode)) { - Charfname[ $], ename[ $], instruction[207]; -strcpy (fname,entry->d_name); -strcpy (ename,entry->d_name); - intLen =strlen (fname); in if(len>=3&& fname[len-1]=='C'&& fname[len-2]=='.') {//. C -ename[len-2] =' /'; tosprintf (instruction,"gcc%s-o%s", fname,ename); +printf"%s\n", instruction); - system (instruction); the } * Else if(len>=4&& fname[len-1]=='C' $&& fname[len-2]=='C'&& fname[len-3]=='.') {//. CCPanax Notoginsengename[len-3] =' /'; -sprintf (instruction,"g++%s-o%s", fname,ename); theprintf"%s\n", instruction); + system (instruction); A } the Else if(len>=5&& fname[len-1]=='P'&& fname[len-2]=='P' +&& fname[len-3]=='C'&& fname[len-4]=='.') {//. cpp -ename[len-4] =' /'; $sprintf (instruction,"g++%s-o%s", fname,ename); $printf"%s\n", instruction); - system (instruction); - } the } - }Wuyi Closedir (DP); the return 0; -}
Jmake compiling the current directory for all C + + single files