一個可以自動生成靜態庫,自動安裝程式的Makefile

期待一片自己的藍天發表於2014-08-08
.PHONY:clean install
CC=g++
CFLAGS=-Wall -g
BIN=libecho.a
INCLUDE=echo
SRC=src
OBJS=Socket.o Rio.o TcpConnection.o PollPoller.o InetAddress.o TcpServer.o Thread.o Condition.o ThreadPool.o Exception.o Timer.o TimerThread.o
STARD=-std=c++0x -rdynamic
$(BIN):$(OBJS)
	ar -crv $@ -o $^
	chmod 0777 $@
	rm -f *.o
	rm -rf $(INCLUDE)
	mkdir $(INCLUDE)
	cp src/*.h $(INCLUDE)/
%.o:$(SRC)/%.cpp
	$(CC) $(CFLAGS) -c $< -o $@ $(STARD)
install:
	sudo cp $(BIN) /usr/lib/
	sudo cp $(INCLUDE) /usr/include/ -r
clean:
	rm -rf *.o $(BIN) echo

相關文章