【发布时间】:2014-02-23 07:35:15
【问题描述】:
我正在尝试为我的项目创建一个 makefile,但我真的不明白这个鬼东西。
当我在 Java 中使用 ant 时,它要简单得多。
我的程序结构是:http://imageshack.com/a/img39/6592/jsxa.png
我阅读了有关创建 makefile 的信息,但是,当他们回答类似的问题时,他们只是将完成的 makefile 放入,并没有详细解释他们在做什么。
所以,我需要做的是创建一个 makefile,它与 src 文件夹 (foo/src/) 一起位于名为 foo (foo/makefile) 的文件夹中。 makefile 需要创建一个名为 bin (foo/bin/) 的文件夹并将 *.o 文件放入其中。然后构建程序(DisqueRango.cpp 包含主函数)并使用 4 个参数运行它:“-e couriers.csv -c menu.csv”。
我不是要求完成的 makefile。我需要的是解释我需要自己做什么。
真的谢谢你。
src/clients/的makefile
CC := g++
OBJ = *.cpp
all: prog
prog:
$(CC) -c $(OBJ)
src/disquerango/的makefile(包含main函数)
CC := g++
BASEDIR := ..
MODULES := clients couriers products read requests
OBJS := $(addsuffix /*.o, $(addprefix $(BASEDIR)/,$(MODULES)))
.PHONY: clean
all:
$(CC) -o disquer DisqueRango.cpp $(OBJS)
以及调用它们的makefile(src的同一文件夹):
CC := g++
BASEDIR := src
PROJN := disquerango
MODULES := clients couriers products read requests disquerango
OBJS := $(addprefix $(BASEDIR)/,$(MODULES))
all: compila run limpa
compila:
for dir in $(OBJS); do (cd $$dir; ${MAKE} all); done
run: compila
./$(BASEDIR)/$(PROJN)/disquer -e entregadores.csv -c cardapio.csv
limpa:
rm -f $(BASEDIR)/$(PROJN)/disquer
for dir in $(OBJS); do (cd $$dir; rm -f *.o); done
【问题讨论】:
-
我有目录,因为老师想要它。这是一个毕业班的项目。
-
您是否尝试过阅读手册?它有很好的介绍材料。 gnu.org/software/make/manual/html_node/index.html
-
Basil:这是一篇好文章,但它是为已经知道如何编写 makefile 的人写的,讨论特定样式的 makefile 的优缺点。我不认为这是向任何人解释 makefile 的好文本。