当前位置:网站首页>Record a Makefile just written
Record a Makefile just written
2022-08-11 07:01:00 【Thousands of copies】
Makefile
.PHONY:all
export MY_VAR="who are you"
all:
@echo "hello world"
a1=abc
b1=$(a1)def
a1=gh
test1:
@echo ${b1}
a2:=abc
b2:=$(a2)def
a2:=gh
test2:
@echo ${b2}
VPATH=./ protocol
path:
@echo `pwd`
@echo ${VPATH}
objs:=main.o calc.o server.o client.o pipe.o
objs+=stack.o
include protocol/child.mk
app:${objs}
gcc -o app $^ -pthread -lm
echo ${MY_VAR}
%.o:%.c
gcc -o [email protected] $< -c -DMY_VAR=\"$(MY_VAR)\"
.PHONY:test3
test3:main.c a.c
echo *.c
echo ?.c
echo [12].c
echo [email protected]
echo $<
echo $^
# echo {1 2 main}.c
.PHONY: clean
clean:
rm -f *.o app
=和:=的执行区别
[email protected]:~/learn/makefile/01$ make test1
ghdef
[email protected]:~/learn/makefile/01$ make test2
abcdef
Then there are the contents of the files contained within
main.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
extern int add(int a,int b);
extern int server_init();
extern int client_init();
extern int stack_init();
extern int pipe_init();
extern int protocol_init();
int main(int argc,char *argv[])
{
double my_d = -5;
server_init();
client_init();
stack_init();
pipe_init();
protocol_init();
#ifdef MY_VAR
//在这里获取MakefileThe passed macro
printf("MY_VAR = %s\n",MY_VAR);
#else
printf("no MY_VAR\n");
#endif
printf("hello c\n");
//验证:这里尝试获取MY_VAR,执行结果为空,说明获取不到
printf("%s \n",getenv("MY_VAR"));
printf("5 + 10 =%d c\n",add(5,10));
printf("my_double = %g fabs(my_double) = %g\n",
my_d,fabs(my_d));
return 0;
}
calc.c
#include <stdio.h>
int add(int a,int b)
{
return a + b;
}
server.c
#include <stdio.h>
int server_init(void)
{
printf("server_init\n");
return 0;
}
client.c
#include <stdio.h>
int client_init(void)
{
printf("client_init\n");
return 0;
}
stack.c
#include <stdio.h>
int stack_init(void)
{
printf("stack_init\n");
return 0;
}
pipe.c
#include <stdio.h>
int pipe_init(void)
{
printf("pipe_init\n");
return 0;
}
protocol子目录中的文件
[email protected]:~/learn/makefile/01/protocol$ ls
child.mk protocol.c
protocol.c
#include <stdio.h>
int protocol_init(void)
{
printf("protocol_init\n");
return 0;
}
child.mk:This is in a subdirectoryMakefile
objs += protocol.o
执行结果
先make app
[email protected]:~/learn/makefile/01$ make app
gcc -o main.o main.c -c -DMY_VAR=\""who are you"\"
gcc -o calc.o calc.c -c -DMY_VAR=\""who are you"\"
gcc -o server.o server.c -c -DMY_VAR=\""who are you"\"
gcc -o client.o client.c -c -DMY_VAR=\""who are you"\"
gcc -o pipe.o pipe.c -c -DMY_VAR=\""who are you"\"
gcc -o stack.o stack.c -c -DMY_VAR=\""who are you"\"
gcc -o protocol.o protocol/protocol.c -c -DMY_VAR=\""who are you"\"
gcc -o app main.o calc.o server.o client.o pipe.o stack.o protocol.o -pthread -lm
echo "who are you"
who are you
然后执行app
[email protected]:~/learn/makefile/01$ ./app
server_init
client_init
stack_init
pipe_init
protocol_init
MY_VAR = who are you //This line indicates that the macro has been obtained
hello c
(null) //This line verifiesMakefileenvironment variables and runtime environment variables are different,Runtime environment variables are terminal-dependent,不能搞混
5 + 10 =15 c
my_double = -5 fabs(my_double) = 5
Test automatic variables
This node is used to test some automatic [email protected] $< $^,Look at the test results first
Prepare a few test files first
[email protected]:~/learn/makefile/01$ touch 1.c 2.c 3.c a.c 11.c
执行测试
[email protected]:~/learn/makefile/01$ make test3
echo *.c
1.c 11.c 2.c 3.c a.c calc.c client.c main.c pipe.c server.c stack.c
echo ?.c
1.c 2.c 3.c a.c
echo [12].c
1.c 2.c
echo test3 //[email protected] 目标名
test3
echo main.c //$< The first filename of the dependency
main.c
echo main.c a.c //@^ A collection of dependent files
main.c a.c
总结
这个代码,The following issues were verified
1.如何include子目录
2.How to get macro definitions
3.MakefileGlobal variables defined in cannot be equivalent to runtime environment variables,app运行时的环境变量,Depends on the environment variables of the terminal or device it is running on,It can be known from the basic definition.This place cannot be confused.
Why write so much,Certainly not for word count,只是说明,这样写,Just to write test code,正式项目,还是算了吧
边栏推荐
- CLUSTER DAY03( Ceph概述 、 部署Ceph集群 、 Ceph块存储)
- Solve win10 installed portal v13 / v15 asked repeatedly to restart problem.
- 局域网文件传输
- SECURITY DAY03 (one-click deployment of zabbix)
- ETCD单节点故障应急恢复
- vnc远程桌面安装(2021-10-20日亲测可用)
- 项目笔记——随机2
- SECURITY DAY06( iptables防火墙 、 filter表控制 、 扩展匹配、nat表典型应用 )
- SECURITY DAY05 (Kali system, scanning and caught, SSH basic protection, service SECURITY)
- [HTB]渗透Backdoor靶机
猜你喜欢
(3) Software testing theory (understanding the knowledge of software defects)
CLUSTER DAY03 (Ceph overview, the deployment of Ceph CLUSTER, Ceph block storage)
ramdisk实践1:将根文件系统集成到内核中
slurm cluster construction
SSL证书部署后,为什么还是显示不安全?
查看可执行文件依赖的库ldd
不同类型SSL证书怎么选?
中小微企业需要使用SSL证书吗?
照片的35x45,300dpi怎么弄
FusionCompute8.0.0实验(0)CNA及VRM安装(2280v2)
随机推荐
分页查询模型
uboot sets the default bootdelay
ovnif摄像头修改ip
无胁科技-TVD每日漏洞情报-2022-7-26
HPC平台搭建
uboot设置默认的bootdelay
Threatless Technology-TVD Daily Vulnerability Intelligence-2022-7-25
文本三剑客——sed 修改、替换
无胁科技-TVD每日漏洞情报-2022-8-5
MySQL中忘记用户密码怎么办?
不同类型SSL证书怎么选?
(三)软件测试理论(了解软件的缺陷知识)
slurm集群搭建
软件使用代码签名证书的好处和必要性
项目笔记——随机2
(二)软件测试理论(*重点用例方法编写)
slurm cluster construction
GoAhead Server 环境变量注入(CVE-2021-42342)漏洞复现
vi display line number in buildroot embedded file system
分布式事物学习