Posted on 2010-07-16 20:01
beauty9235 閱讀(280)
評論(0) 編輯 收藏
lxq@lxq:~/tmp$ tree
.
|-- Makefile
|-- bin
| `-- Makefile
|-- hello
| |-- Makefile
| |-- hello
| `-- hello.c
`-- tmp
3 directories, 5 files
cat Makefile
SRCBASE := $(shell pwd) #獲取當(dāng)前目錄
ELEASEDIR := $(shell (cd $(SRCBASE)/.. && pwd -P))
print:
echo ${ELEASEDIR}
install: all
install -d ${ELEASEDIR}/tmp
$(MAKE) -C ./hello clean #切換到hello目錄執(zhí)行clean目標(biāo)
$(MAKE) -C ./hello hello #切換到hello目錄執(zhí)行hello目標(biāo)
$(MAKE) -C ./hello $@ #切換到hello目錄執(zhí)行install目標(biāo)
all clean:
ifneq ($(wildcard hell),) #如果有hell這個文件就執(zhí)行里面的動作
$(MAKE) -C ./bin $@ #切換到hello目錄執(zhí)行all\clean目標(biāo)
endif
.PHONY: all clean install
cat hello/Makefile
clean:
ifneq ($(wildcard hello),)
rm hello
endif
hello:
gcc -o hello hello.c
install:
-cp hello ../bin/
cat hello/hello.c
#include <stdio.h>
int main()
{
printf("hello");
exit(0);
}