-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
61 lines (50 loc) · 1.51 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
51
52
53
54
55
56
57
58
59
60
61
TARGET = myprogram
SRCDIRS = src
INCDIRS = include
OBJDIR = /tmp/$(TARGET)-build
LIBDIRS =
DYNLIBS =
LIBS =
DEFINES =
PKGS =
CFLAGS = -std=c++98 -Wall -W -fvisibility=hidden -fvisibility-inlines-hidden
LINKFLAGS =
ifeq ($(strip $(DEBUG)),)
CFLAGS += -Os -fomit-frame-pointer
DEFINES += NDEBUG
else
CFLAGS += -ggdb
endif
PKG_CFLAGS = $(foreach pkg,$(PKGS),$(shell pkg-config --cflags $(pkg)))
PKG_LIBS = $(foreach pkg,$(PKGS),$(shell pkg-config --libs $(pkg)))
CFLAGS += $(PKG_CFLAGS) $(DEFINES:%=-D%) $(INCDIRS:%=-I%)
LIBFLAGS = $(PKG_LIBS) $(LIBDIRS:%=-L%) $(DYNLIBS:%=-l%)
SRCFILES = $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)) \
$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cxx))
DEPFILES = $(SRCFILES:%=$(OBJDIR)/%.d)
OBJFILES = $(SRCFILES:%=$(OBJDIR)/%.o)
.PHONY : all clean
all : $(TARGET)
clean :
@rm -rf $(TARGET) $(OBJDIR)
$(OBJDIR)/%.c.o : %.c
@echo " GCC $<"
@gcc -c -pipe -fPIC $(CFLAGS) -o $@ $<
$(OBJDIR)/%.cxx.o : %.cxx
@echo " G++ $<"
@g++ -c -pipe -fPIC $(CFLAGS) -o $@ $<
$(OBJDIR)/%.c.d : %.c
@mkdir -p $(dir $@)
@gcc -MM -MP -MT "$(OBJDIR)/$<.o" $(CFLAGS) $< > $@ || (rm -f $@; exit 1)
$(OBJDIR)/%.cxx.d : %.cxx
@mkdir -p $(dir $@)
@g++ -MM -MP -MT "$(OBJDIR)/$<.o" $(CFLAGS) $< > $@ || (rm -f $@; exit 1)
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPFILES)
endif
$(TARGET) : $(OBJFILES)
@echo " EXE $@"
@g++ -pipe $(LINKFLAGS) $(LIBFLAGS) -o $@ $(OBJFILES) $(LIBS)
ifeq ($(strip $(DEBUG)),)
@strip -s -R .comment $@
endif