-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
236 lines (182 loc) · 5.06 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# $Id$
# $MyId$
# $Source$
######################################################################
# You'll need these:
# make.darwin-i386
# make.solaris-sparc
# include make.$(OSTYPE)-$(MACHTYPE)
REPO:=$(shell basename ${PWD})
GITVERSION:='$(shell git show -s --date=format:"%F %T %z" --format="$(REPO) %ad %d %h %an %aE")'
GITVERSION:=$(shell git show -s --date=format:"%F %T %z" --format="$(REPO) %h %d %ad %an %aE")
GITVERSION:="\#define GKW_VERSION \"GKW_VERSION $(GITVERSION)\""
CC_DEBUG_FLAGS = -g3 -DDEBUG_ALL
CC_CHECK_FLAGS = --analyzer-output text --analyze -I$(HOME)/Build/include -I$(SRC)
CC_RELEASE_FLAGS = -O3
VERSION = Source/version.h
stamp: $(VERSION)
@ echo GITVERSION: ${GITVERSION}
.PHONY: update_version
$(VERSION): update_version
@ [ -f $@ ] || touch $@
@ echo ${GITVERSION}
@ echo $(GITVERSION) | cmp -s $@ - || echo $(GITVERSION) > $@
RLS = release
DBG = debug
PTH := $(RLS)
RUN = all
list:
column = sed 's/ / /g' | tr ' |' '\n\n'
DIR = $(shell basename $(CURDIR))
BLD = $(HOME)/Build
INC = $(BLD)/include
MCH = $(BLD)/$(MACHTYPE)
BAS = $(MCH)/$(PTH)/$(DIR)
DEP = $(MCH)/.dep/$(DIR)
DST = $(BAS)/bin
OBJ = $(BAS)/obj
LIB = $(BAS)/lib
# Override this on the cmdline with: make prefix=/some/where/else
prefix = $(BLD)
SRC = Source
NST = $(prefix)/bin
MYINC = -I$(BLD)/include -I$(SRC)
MYLIB = -L$(BLD)/lib -lmylib
.PHONY: check
check: CFLAGS = $(CC_CHECK_FLAGS)
check: .analyze
.PHONY: check_all
check_all: CFLAGS = $(CC_CHECK_FLAGS)
check_all: make_check_all
.PHONY: debug
debug: CFLAGS += $(CC_DEBUG_FLAGS) $(MYINC)
debug: PTH := $(DBG)
debug: make_it
.PHONY: release
release: CFLAGS += $(CC_RELEASE_FLAGS) $(MYINC)
release: PTH := $(RLS)
release: make_it
# All C programs
DST_PROGS = \
# $(DST)/wg \
# All Scripts (basename, no extensions ie: foo, not foo.pl)
DST_SCRPT = \
$(DST)/gitkwexpand \
$(DST)/gitkwshrink \
DIRS = \
$(DEP) \
$(OBJ) \
$(BAS) \
$(DST) \
$(NST) \
$(DST)/%: $(SRC)/%.pl
install -m ugo+rx $< $@
$(DST)/%: $(SRC)/%.sh
install -m ugo+rx $< $@
$(DST)/%: $(SRC)/%.awk
install -m ugo+rx $< $@
$(DST)/%: $(SRC)/%.py
install -m ugo+rx $< $@
$(DST)/%: $(SRC)/%.zsh
install -m ugo+rx $< $@
$(NST)/%: $(DST)/%
install -m ugo+rx $< $@
test:
@echo $(NST_SCRPT)
NST_PROGS = $(subst $(DST), $(NST), $(DST_PROGS))
NST_SCRPT = $(subst $(DST), $(NST), $(DST_SCRPT))
.PHONY: install real_install help
list:
@echo all install
@echo $(DST_PROGS)
@echo $(DST_SCRPT)
#@echo $(NST_PROGS)
#@echo $(NST_SCRPT)
all: \
$(DIRS) \
$(DST_PROGS) \
$(DST_SCRPT) \
show_install \
stamp \
# tags types \
install: real_install
@true
real_install: \
$(NST) \
$(NST_SCRPT) \
$(NST_PROGS) \
$(DIRS):
mkdir -p $@
show_install:
@echo ""
@echo "These programs need to be installed:"
@make -sn install
help:
@make -sn
@echo "These programs are made:"
@echo $(DST_PROGS) | tr ' ' '\n'
@echo $(DST_SCRPT) | tr ' ' '\n'
@echo
@echo "Try: make install"
help_install:
@echo "These programs are installed:"
@echo
@echo $(NST_PROGS) | tr ' ' '\n'
@echo $(NST_SCRPT) | tr ' ' '\n'
@echo
clean:
$(RM) $(DEP)/*.d $(OBJ)/*.o $(DST_PROGS) $(DST_SCRPT)
rmdir $(OBJ) $(DST)
foo:
@ echo "OBJ " $(OBJ)
@ echo "SRC " $(SRC)
@ echo "HOST " $(HOST)
@ echo "NSTS " $(NST_SCRPT) | $(column)
.analyze: $(wildcard $(SRC)/*.c)
gcc $(CFLAGS) $?
@ touch .analyze
make_check_all:
@ rm .analyze || true
@ make CFLAGS="$(CFLAGS)" check
make_it:
make PTH=$(PTH) CFLAGS="$(CFLAGS)" $(RUN)
#We don't need to clean up when we're making these targets
NODEPS:=clean svn install
#Find all the C++ files in the $(SRC)/ directory
SOURCES:=$(shell find $(SRC) -name "*.c")
#These are the dependency files, which make will clean up after it creates them
DEPFILES:=$(patsubst %.c,%.d,$(patsubst $(SRC)/%,$(DEP)/%, $(SOURCES)))
#Don't create dependencies when we're cleaning, for instance
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
#Chances are, these files don't exist. GMake will create them and
#clean up automatically afterwards
-include $(DEPFILES)
endif
#This is the rule for creating the dependency files
$(DEP)/%.d: $(SRC)/%.c $(DEP)
@echo "START DEP: $@"
@echo $(CC) $(CFLAGS) -MG -MM -MT '$(patsubst $(SRC)/%,$(OBJ)/%, $(patsubst %.c,%.o,$<))' $(MYINC) $<
$(CC) $(CFLAGS) -MG -MM -MT '$(patsubst $(SRC)/%,$(OBJ)/%, $(patsubst %.c,%.o,$<))' $(MYINC) $< > $@
@echo "END DEP: $@"
# End of - Dependency code added here
# Make a highlight file for types. Requires Exuberant ctags and awk
# Make a highlight file for types. Requires Universal ctags and awk
types: $(SRC)/.types.vim
$(SRC)/.types.vim: $(SRC)/*.[ch]
ctags --kinds-c=gstu -o- \
$(SRC)/*.[ch] \
$(INC)/*.h \
| grep -v "^__anon" \
| awk 'BEGIN{printf("syntax keyword Type\t")} \
{printf("%s ", $$1)}END{print ""}' > $@
ctags --kinds-c=d -o- \
$(SRC)/*.h \
$(INC)/*.h \
| grep -v "^__anon" \
| awk 'BEGIN{printf("syntax keyword Debug\t")}\
{printf("%s ", $$1)}END{print ""}' >> $@
# End types
tags: $(SRC)/*.[ch]
ctags --fields=+l --langmap=c:.c.h \
$(SRC)/* \
$(INC)/*