-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
145 lines (107 loc) · 3.37 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Windows/Cygwin support
ifdef windir
WINDOWS := 1
CYGWIN := 0
else
ifdef WINDIR
WINDOWS := 1
CYGWIN := 1
else
WINDOWS := 0
endif
endif
ifeq ($(WINDOWS),1)
EXEEXT := .exe
DLLEXT := .dll
DEVNUL := nul
ifeq ($(CYGWIN),1)
PATHSEP := /
else
PATHSEP := $(strip \ )
endif
else
EXEEXT :=
DLLEXT := .so
DEVNUL := /dev/null
endif
CFG ?= Debug
ifeq ($(CFG),Debug)
all: debug
else
all: release
endif
OLDGCC ?= N
DEBUG := DebugDir
RELEASE := ReleaseDir
$(DEBUG)/%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(DBGFLAGS) $(TARGET_ARCH) -c -o $@ $<
$(RELEASE)/%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(RELFLAGS) $(TARGET_ARCH) -c -o $@ $<
$(DEBUG)/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(DBGFLAGS) $(TARGET_ARCH) -c -o $@ $<
$(RELEASE)/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(RELFLAGS) $(TARGET_ARCH) -c -o $@ $<
ifeq ($(OLDGCC),N)
$(DEBUG)/%.dep: %.c
$(CC) -MM -MT $(patsubst %.dep,%.o,$@) $(CFLAGS) $(CPPFLAGS) $(DBGFLAGS) $(TARGET_ARCH) -o $@ $<
$(RELEASE)/%.dep: %.c
$(CC) -MM -MT $(patsubst %.dep,%.o,$@) $(CFLAGS) $(CPPFLAGS) $(RELFLAGS) $(TARGET_ARCH) -o $@ $<
$(DEBUG)/%.dep: %.cpp
$(CXX) -MM -MT $(patsubst %.dep,%.o,$@) $(CXXFLAGS) $(CPPFLAGS) $(DBGFLAGS) $(TARGET_ARCH) -o $@ $<
$(RELEASE)/%.dep: %.cpp
$(CXX) -MM -MT $(patsubst %.dep,%.o,$@) $(CXXFLAGS) $(CPPFLAGS) $(RELFLAGS) $(TARGET_ARCH) -o $@ $<
else
$(DEBUG)/%.dep: %.c
$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(DBGFLAGS) $(TARGET_ARCH) $< | sed "s!^!$(DEBUG)/!" > $@
$(RELEASE)/%.dep: %.c
$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(RELFLAGS) $(TARGET_ARCH) $< | sed "s!^!$(RELEASE)/!" > $@
$(DEBUG)/%.dep: %.cpp
$(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $(DBGFLAGS) $(TARGET_ARCH) $< | sed "s!^!$(DEBUG)/!" > $@
$(RELEASE)/%.dep: %.cpp
$(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $(RELFLAGS) $(TARGET_ARCH) $< | sed "s!^!$(RELEASE)/!" > $@
endif
CC = gcc
CXX = g++
AR = ar
LD = $(CC) $(CXXFLAGS) $(TARGET_ARCH)
INCLUDE = $(patsubst %,-I%,$(VPATH))
CFLAGS = -W -Wall $(INCLUDE)
CXXFLAGS = $(CFLAGS)
DBGFLAGS = -D_DEBUG -g
RELFLAGS = -DNDEBUG -O2
CPPFLAGS =
ifeq ($(OLDGCC),N)
CFLAGS += -fmessage-length=0
endif
HFILES = $(wildcard $(patsubst -I%,%/*.h,$(INCLUDE)))
OBJFILES = $(CFILES:.c=.o) $(CXXFILES:.cpp=.o)
DEBUG_OBJS = $(patsubst %.o,$(DEBUG)/%.o,$(OBJFILES))
RELEASE_OBJS = $(patsubst %.o,$(RELEASE)/%.o,$(OBJFILES))
DEBUG_DEPS = $(patsubst %.o,%.dep,$(DEBUG_OBJS))
RELEASE_DEPS = $(patsubst %.o,%.dep,$(RELEASE_OBJS))
CFILES := breaktext.c
CXXFILES :=
LINEBREAK_LIBNAME := unibreak
LIBS := -l$(LINEBREAK_LIBNAME)
TARGET = breaktext
DEBUG_TARGET = $(patsubst %,$(DEBUG)/%$(EXEEXT),$(TARGET))
RELEASE_TARGET = $(patsubst %,$(RELEASE)/%$(EXEEXT),$(TARGET))
debug: $(DEBUG) $(DEBUG_TARGET)
release: $(RELEASE) $(RELEASE_TARGET)
$(DEBUG):
mkdir $(DEBUG)
$(RELEASE):
mkdir $(RELEASE)
$(DEBUG_TARGET): $(DEBUG_DEPS) $(DEBUG_OBJS)
$(LD) $(DBGFLAGS) -o $(DEBUG_TARGET) $(DEBUG_OBJS) $(LIBS)
$(RELEASE_TARGET): $(RELEASE_DEPS) $(RELEASE_OBJS)
$(LD) $(RELFLAGS) -o $(RELEASE_TARGET) $(RELEASE_OBJS) $(LIBS) -s
.PHONY: all debug release clean distclean
clean:
$(RM) $(DEBUG)/*.o $(DEBUG)/*.dep $(DEBUG_TARGET)
$(RM) $(RELEASE)/*.o $(RELEASE)/*.dep $(RELEASE_TARGET)
distclean: clean
$(RM) $(DEBUG)/* $(RELEASE)/* tags
-rmdir $(DEBUG) 2> $(DEVNUL)
-rmdir $(RELEASE) 2> $(DEVNUL)
-include $(wildcard $(DEBUG)/*.dep) $(wildcard $(RELEASE)/*.dep)