谁帮我简化下这个makefile文件文件分布:CS (顶层目录):ByteStream(目录):ByteStream.h, ByteStream.cppTCo
谁帮我简化下这个makefile文件
文件分布:
CS (顶层目录):
ByteStream(目录): ByteStream.h, ByteStream.cpp
TConnection(目录): TConnection.h, TConnection.cpp
FileServer(目录): FileServer.h, FileServer.cpp, Server.cpp(main函数所在文件), makefile(想简化的文件)
当前makefile内容:
- C/C++ code
objects=Server.o FileServer.o TConnection.o ByteStream.oserver:$(objects) g++ -o server $(objects) Server.o:Server.cpp FileServer.h g++ -c Server.cppFileServer.o:FileServer.cpp ../Head/Command.h ../ByteStream/ByteStream.h FileServer.h g++ -c FileServer.cppTConnection.o:../TConnection/TConnection.cpp ../ByteStream/ByteStream.h ../TConnection/TConnection.h g++ -c ../TConnection/TConnection.cppByteStream.o:../ByteStream/ByteStream.cpp ../ByteStream/ByteStream.h g++ -c ../ByteStream/ByteStream.cpprebuild:clean serverclean: -rm server $(objects)
../directory/file这种:写着累,看着丑
很长一行怎么分行写? "\" ?
求简化!
[解决办法]
obj = a.o b.o
project : $(obj)
用类似这中方式把目录定义成变量,然后替换到应该用到的位置即可
[解决办法]
搜“跟我一起写MakeFile”
[解决办法]
- C/C++ code
CC = gccCFLAGS = -g -I./includeLIBS = -lpthread -lm -lzSOURCES = $(wildcard src/*.c)OBJS = ${SOURCES:%.c=%.o}BIN = outputall : $(BIN) @echo "Makefile done."$(BIN) : $(OBJS) $(CC) -o $@ $^ $(LIBS)clean: rm -f $(BIN) $(OBJS) 