(1)创建目录结构
(2)输入"tree"命令,查看目录;若没有则安装tree命令 (sudo apt-get install tree )
- //f1.c
- #include "../include/myinclude.h"
- void print1()
- {
- printf("Message f1.c\n");
- return;
- }
- //Makefile (/f1目录下的)
- ../$(OBJS_DIR)/f1.o:f1.c
- $(CC) -c $^ -o $@
- //main.c
- #include <stdio.h>
- int main()
- {
- print1();
- print2();
- return 0;
- }
- //Makefile (/man目录下的Makefile)
- ../$(OBJS_DIR)/main.o:main.c
- $(CC) -c $^ -o $@
- //顶层目录下的Makeflie文件
- cc=gcc
- SUBDIRS=f1 \
- f2 \
- main \
- obj
- OBJS=f1.o f2.o main.o
- BIN=myapp
- OBJS_DIR=obj
- BIN_DIR=bin
- export CC OBJS BIN OBJS_DIR BIN_DIR
- all:CHECK_DIR $(SUBDIRS)
- CHECK_DIR:
- mkdir -p $(BIN_DIR)
- $(SUBDIRS):ECHO
- make -C $@
- ECHO:
- @echo $(SUBDIRS)
- @echo begin compile
- CLEAN:
- @$(RM) $(OBJS_DIR)/*.o
- @rm -rf $(BIN_DIR)
- //Obj目录下的Makefile
- ../$(BIN_DIR)/$(BIN):$(OBJS)
- $(CC) -o $@ $^
- include目录下的myinclude.h 文件
- #include <stdio.h>
原文地址:http://blog.csdn.net/zplove003/article/details/7066595