-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (38 loc) · 1.44 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
SHELL = /bin/sh
CC = g++
CPPFLAGS = -g -Wall -Iinclude -DHAVE_TCP_CONNECTION
OLDFLAGS = -std=c++11
CFLAGS = $(CPPFLAGS)
LDLIBS = -lutil -lpam
TARGET = protocol options tcpclient parameters daemon authent runnable
SOURCES = $(shell echo src/*.cpp)
HEADERS = $(shell echo include/*.h)
OBJECTS = $(SOURCES:.cpp=.o)
MAIN = $(shell echo main/*.cpp)
MAINOBJ = $(MAIN:.cpp=.o)
DEBUGFLAGS = -g
all: $(TARGET)
clean:
-echo "clean"
-rm -f $(OBJECTS)
-rm -f gmon.out
-rm -f main/*.o
-rm -f $(TARGET)
distclean: clean
-rm -f $(TARGET)
gitadd:
-git add src/*.cpp
-git add include/*.h
-git add main/*.cpp
-git add Makefile
.SECONDARY: $(OBJECTS) $(MAINOBJ)
.PHONY : all install uninstall clean distclean gitadd
.SECONDEXPANSION:
$(foreach TGT, $(TARGET), $(eval $(TGT)_HEADERS = $(filter $(shell $(CC) $(CFLAGS) -MM main/$(TGT).cpp | sed s/.*://), $(HEADERS))))
$(foreach TGT, $(TARGET), $(eval $(TGT)_OBJECTS = $(filter $(subst include, src, $($(TGT)_HEADERS:.h=.o)), $(OBJECTS))))
$(foreach OBJ,$(OBJECTS),$(eval $(OBJ)_HEADERS = $(filter $(shell $(CC) $(CFLAGS) -MM $(OBJ:.o=.cpp) | sed s/.*://), $(HEADERS))))
$(foreach OBJ,$(OBJECTS),$(eval $(OBJ)_OBJECTS = $(filter-out $(OBJ), $(filter $(subst include, src, $($(OBJ)_HEADERS:.h=.o)), $(OBJECTS)))))
%: main/%.o $$($$@_OBJECTS) $$($$@_HEADERS)
$(CC) $(CFLAGS) -o $@ $($@_OBJECTS) $< $(LDLIBS)
%.o: %.cpp $$($$@_OBJECTS) $$($$@_HEADERS)
$(CC) $(CFLAGS) $(LDLIBS) -c -o $@ $<