Linux下非集成开发环境编译工程文件 在具有依赖关系的文件中, make可以防止C程序的不必要的重新编译 makefile可以编写make自动化编译的规则, 即当源程序一部分进行更新编译时如何编译整个源程序 make的运行环境 : make程序和一个文本文件Makefile
make操作Makefile文件的规则:
- 工程没有编译过, 所有的C文件需要编译和连接
- 工程的某几个C文件被修改,需要编译被修改过的C文件并连接目标程序
- 工程的头文件被改变, 需要编译引用了这几个头文件的C文件并连接目标程序
测试1:
#### main.c#include<stdio.h>int main(void){char c;char str[20];enter_string(str);printf("The delete string is:");scanf("%c", &c);delete_string(str, c);print_string(str);}#### foo1.c#include<stdio.h>int enter_string(char str[20]){printf("Input the strings:");gets(str);return 0;}#### foo2.cint delete_string(char str[], char ch){int i,j;for(i=j=0; str[i]!='\0';i++){if(str[i]!=ch)str[j++]=str[i];}str[j]='\0';return 0;}#### foo3.c#include<stdio.h>int print_string(char str[]){printf("Result: %s\n", str);return 0;}
Makefile:
all: main.c foo1.c foo2.c foo3.c #依赖性文件gcc main.c foo1.c foo2.c foo3.c -o all #执行命令
执行: make, 生成all可执行文件
示例2:
all :最终执行目标 main.o …. 所需要的依赖文件 gcc 执行的编译命名 main.o : main.c defs.h main.o文件依赖的文件 gcc -c main.c 执行的方法 clean: rm all main.o 删除文件
make命令
语法:
make [option] [target]
option:
- -f : 指定文件为Makefile
常用命令:
- make clean 清除make产生的object文件
- make install 将编译成功的可执行文件安装到系统目录中
Makefile
语法:
targets:prerequisities[tab]command...
targets 目标文件名 prerequisities 依赖目标文件
备注
参考: https://blog.csdn.net/weixin_34548449/article/details/116251993
两个包 autoconf automake
autoscan 扫描源代码目录生成configure.scan文件 configure.scan 包含系统配置的基本选项,里面为宏定义 aclocal perl脚本程序, 根据configure.in文件生成aclocal.m4 autoconf 生成configure文件(根据configure.in) .configure脚本设置源程序适应不同的操作系统并生成Makefile Makefile.am 生成Makefile.in , 需要手动写 automake 根据Makefile.am生成Makefile.in ./configure根据Makefile.in生成Makefile文件

