]> Dogcows Code - chaz/yoink/blob - Makefile
a0c754b694dbf64e9d42fc277ec02fcacfcbd9a7
[chaz/yoink] / Makefile
1
2 #
3 # Yoink
4 # Use this file with GNU make to compile and install Yoink.
5 #
6
7 # Set V to `1' to echo each build command in full. The default behavior
8 # will keep output minimal.
9 V = 0
10
11 SHELL = /bin/sh
12
13
14 ifeq (menuconfig,$(MAKECMDGOALS))
15 menuconfig:
16 ./configure --interactive
17 .PHONY: menuconfig
18 else
19
20 config.h: config.mk
21 $(Q)$(configure) --export-header=$@
22
23 config.sed: config.mk
24 $(Q)$(configure) --export-terms=$@
25
26 config.mk:
27 $(Q)$(configure) --interactive --print-instructions=no
28
29 include config.mk
30
31
32 #
33 # Define some useful functions.
34 #
35
36 DATA_TARGETS :=
37 EXEC_TARGETS :=
38 SUBDIRS :=
39
40 define include_func =
41 ifeq (,$$d)
42 dir := $1
43 else
44 dir := $$d/$1
45 endif
46 sp := $$(sp).x
47 dirstack_$$(sp) := $$d
48 datstack_$$(sp) := $$(data)
49 exestack_$$(sp) := $$(exec)
50 d := $$(dir)
51 data :=
52 exec :=
53 include $$(dir)/rules.mk
54 SUBDIRS += $$d $$b
55 data := $$(sort $$(data) $$(appdir_$$b) $$(mandir_$$b) $$(pkgdatadir_$$b) $$(desktop_$$b))
56 exec := $$(sort $$(exec) $$(bindir_$$b) $$(libdir_$$b))
57 deps := $$(filter %.d,$$(exec:%.o=%.d))
58 clean := $$(clean) $$(deps) $$(exec) $$(data)
59 DEPFILE := $$(DEPFILE) $$(deps)
60 DATA_TARGETS += $$(data)
61 EXEC_TARGETS += $$(exec)
62 d := $$(dirstack_$$(sp))
63 data := $$(datstack_$$(sp))
64 exec := $$(exestack_$$(sp))
65 sp := $$(basename $$(sp))
66 endef
67 include = $(foreach i,$1,$(eval $(call include_func,$i)))
68
69 targets = $(EXEC_TARGETS) $(DATA_TARGETS)
70 builddir = build/obj
71 b = $(builddir)/$(d)
72 this = $(d)/rules.mk
73
74 ifeq (gzip,$(manCompression))
75 MANEXT=.gz
76 else
77 ifeq (bzip2,$(manCompression))
78 MANEXT=.bz2
79 endif
80 endif
81
82
83 #
84 # Include the subdirectories--order is not important.
85 #
86
87 $(call include,src data doc)
88 -include build/arch/$(platform)/rules.mk
89
90
91 #
92 # Define some common rules.
93 #
94
95 ifeq (true,$(tracking))
96 PKG_CFLAGS += -MD -MP -MF $(@:%.o=%.d) -MT $@
97 -include $(DEPFILE)
98 endif
99
100 # Include current directory to allow sources to include config.h.
101 override CPPFLAGS += -I. -DHAVE_CONFIG_H=1
102 TGT_CXXFLAGS = $(TGT_CFLAGS)
103 ARFLAGS = rc
104 INSTALL = install
105
106 tarname = $(TARNAME)-$(VERSION)
107
108 cmd_compile_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \
109 $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
110 cmd_compile_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \
111 $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
112 cmd_link_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \
113 $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \
114 $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
115 cmd_link_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \
116 $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \
117 $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
118 cmd_ar = $(AR) $(ARFLAGS) $@ $^; $(RANLIB) $@
119 cmd_compile_rc = $(WINDRES) $(CPPFLAGS) $(TARGET_ARCH) $(OUTPUT_OPTION) -i $<
120 cmd_sed = sed -f config.sed <$< >$@
121 cmd_gzip = gzip -c $< >$@
122 cmd_bzip2 = bzip2 -c $< >$@
123 cmd_xxd = id=$(subst .,_,$(notdir $<)); \
124 printf "\#include <stddef.h>\nsize_t\tdata_%s_size = %d;\nchar\tdata_%s[] = {\n" \
125 $$id $$(wc -c <$<) $$id >$@; \
126 xxd -i <$< >>$@; \
127 printf ", 0x00\n};\n" >>$@
128 cmd_configure = ./configure
129 func_install = mkdir -p $(DESTDIR)$3 && $(INSTALL) -m $1 $2 $(DESTDIR)$3
130 func_remove = rm -f $1
131 func_dist = git archive HEAD --prefix='$(tarname)/' | $1 >"$(tarname).tar.$2" && \
132 (md5 "$(tarname).tar.$2" 2>/dev/null || md5sum "$(tarname).tar.$2")
133
134 compile_c = $(call func_print,CC,$@) $(cmd_compile_c)
135 compile_cc = $(call func_print,CXX,$@) $(cmd_compile_cc)
136 compile_rc = $(call func_print,RC,$@) $(cmd_compile_rc)
137 link_c = $(call func_print,LINK,$@) $(cmd_link_c)
138 link_cc = $(call func_print,LINK,$@) $(cmd_link_cc)
139 ar = $(call func_print,AR,$@) $(cmd_ar)
140 sed = $(call func_print,SED,$@) $(cmd_sed)
141 gzip = $(call func_print,GZIP,$@) $(cmd_gzip)
142 bzip2 = $(call func_print,BZIP2,$@) $(cmd_bzip2)
143 xxd = $(call func_print,XXD,$@) $(cmd_xxd)
144 configure = $(call func_print,MAKE,$@) $(cmd_configure)
145 dist = $(call func_print,DIST,$1) $(func_dist)
146 install = $(call func_print,CP,$(DESTDIR:%/=%)$(3:%/=%)/$(notdir $2)) $(func_install)
147 remove = $(call func_print,RM,$1) $(func_remove)
148
149 ifeq (1,$V)
150 Q =
151 func_print =
152 else
153 Q = @
154 func_print = printf "\x20\x20$1\t%s\n" $2;
155 endif
156
157
158 #
159 # Define the implicit rules.
160 #
161
162 %.o: %.cc
163 $(Q)$(compile_cc)
164 %.o: %.cpp
165 $(Q)$(compile_cc)
166 %.o: %.c
167 $(Q)$(compile_c)
168 %.o: %.rc
169 $(Q)$(compile_rc)
170 %: %.in
171 $(Q)$(sed)
172 %.gz: %
173 $(Q)$(gzip)
174 %.bz2: %
175 $(Q)$(bzip2)
176
177 $(builddir)/%.o: %.cc
178 $(Q)$(compile_cc)
179 $(builddir)/%.o: %.cpp
180 $(Q)$(compile_cc)
181 $(builddir)/%.o: %.c
182 $(Q)$(compile_c)
183 $(builddir)/%.o: %.rc
184 $(Q)$(compile_rc)
185 $(builddir)/%: %.in
186 $(Q)$(sed)
187 $(builddir)/%.gz: %
188 $(Q)$(gzip)
189 $(builddir)/%.bz2: %
190 $(Q)$(bzip2)
191 $(builddir)/%: %
192 $(Q)if [ -d $< ]; then mkdir -p $@; elif [ -f $< ]; then cp -f $< $@; fi
193
194
195 #
196 # Define the phony targets.
197 #
198
199 .DEFAULT_GOAL :=
200 all: $(targets)
201
202 clean:
203 $(Q)$(foreach f,$(clean),$(call remove,$f);)
204 $(Q)if [ -d $(builddir) ]; then find $(builddir) -type d -empty -delete; fi
205
206 distclean: clean
207 $(Q)cd build && $(MAKE) clean
208 $(Q)$(call remove,config.h);$(call remove,config.mk);$(call remove,config.sed)
209
210
211 install: install-data install-exec
212
213 install-data: $(DATA_TARGETS)
214 $(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(pkgdatadir_$d),\
215 $(call install,644,$f,$(dir $(f:$d%=$(pkgdatadir)%)));))
216 $(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(mandir_$d),\
217 $(call install,644,$f,\
218 $(dir $(f:$d%=$(mandir)/man$(shell echo "$f" | sed 's/[^.]*\.\([^.]*\).*/\1/')%)));))
219
220 install-exec: $(EXEC_TARGETS)
221 $(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(bindir_$d),\
222 $(call install,755,$f,$(dir $(f:$d%=$(bindir)%)));))
223
224 install-desktop-entry: $(DATA_TARGETS)
225 $(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(desktop_$d),\
226 $(call install,644,$f,/usr/share/applications);))
227
228
229 dist-all: dist-bzip2 dist-gzip dist-lzma dist-xz
230
231 dist-bzip2:
232 $(Q)$(call dist,bzip2,bz2)
233
234 dist-gzip:
235 $(Q)$(call dist,gzip,gz)
236
237 dist-lzma:
238 $(Q)$(call dist,lzma,lzma)
239
240 dist-xz:
241 $(Q)$(call dist,xz,xz)
242
243 dist: dist-$(archiveFormat)
244
245
246 #
247 # Prevent make from removing any build targets.
248 #
249
250 .SECONDARY: $(clean)
251
252 .PHONY: all clean distclean install install-data install-exec
253 .PHONY: install-desktop-entry
254 .PHONY: dist dist-all dist-gzip dist-bzip2 dist-xz dist-lzma
255
256 endif # menuconfig
257
This page took 0.041695 seconds and 3 git commands to generate.