main.c 文件如下:
#include <stdio.h>
int main()
{printf("=======soft infomation=======\n");//以下信息均在gcc时已预定义printf("soft_ver:\t%s\n",__VER__);printf("author:\t\t%s\n",__AUTHOR__);printf("sn_num:\t\t%d\n",__SN_NUM__);printf("make_time:\t%s\n",__MAKE_TIME__);printf("==============end=============\n");
return 0;}
makefile文件如下:
##########################################
VER=V1.23
AUTHOR=bnis
SN_NUM=1234
MAKE_TIME=$(shell date +%H:%M:%S )
MAKE_DATE=$(shell date +%Y-%m-%d )
CFLAGS += -D __VER__=\"$(VER)\"
CFLAGS += -D __AUTHOR__=\"$(AUTHOR)\"
CFLAGS += -D __SN_NUM__=$(SN_NUM)
CFLAGS += -D __MAKE_TIME__=\"$(MAKE_DATE)_$(MAKE_TIME)\"
#########################################
.PHONY:
all:gcc $(CFLAGS) main.c./a.out
clean:rm -rf *.out
make运行效果如下: