b5a149f4df2c706fc60ea14e6dbbae72b5823987
[chaz/yoink] / Makefile
1
2 #
3 # Yoink
4 # Use this file with make to compile and install Yoink.
5 #
6 # This makefile supports these targets:
7 # all, install, clean, distclean, run, debug, dist, dist-gzip, dist-bzip2
8 #
9 # This build system incorporates the ideas written by Emile van Bergen:
10 # http://www.xs4all.nl/~evbergen/nonrecursive-make.html
11 #
12
13 # Set this to `true' to echo each build command in full.
14 verbose := false
15
16
17 #
18 # Include the configuration file, config.mk.
19 #
20
21 SHELL := /bin/sh
22
23 have_config := $(wildcard config.mk)
24 ifneq ($(strip $(have_config)),)
25 include config.mk
26 else
27 $(error You must run the configure script before you can make anything)
28 endif
29
30
31 #
32 # Declare the default targets and implicit rules.
33 #
34
35 .PHONY: all
36 all: all_
37
38 .SUFFIXES:
39 .SUFFIXES: .a .c .cc .cpp .in .o .rc
40
41
42 #
43 # Define some useful functions.
44 #
45
46 add_exe_suffix = $(addsuffix $(EXEEXT),$1)
47 remove_silencer = $(1:@%=%)
48
49
50 #
51 # Include the subdirectories--order is not important.
52 #
53
54 dir := src
55 include $(dir)/rules.mk
56
57 dir := data
58 include $(dir)/rules.mk
59
60 dir := doc
61 include $(dir)/rules.mk
62
63
64 #
65 # Define some common rules.
66 #
67
68 ifeq ($(DEP_TRACKING),true)
69 COMPILE = ./tools/compile.lua
70 endif
71
72 # Include current directory to allow sources to #include "config.h".
73 CFLAGS += -I.
74 CXXFLAGS += -I.
75
76 COMMAND_CC = $(COMPILE) $(CC) $(CFLAGS) $(CF_TGT) -o $@ -c $<
77 COMMAND_CXX = $(COMPILE) $(CXX) $(CXXFLAGS) $(CF_TGT) -o $@ -c $<
78 COMMAND_LD = $(CC) $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
79 COMMAND_LDX = $(CXX) $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
80 COMMAND_CCLD = $(COMPILE) $(CC) $(CFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
81 COMMAND_CXXLD = $(COMPILE) $(CXX) $(CXXFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
82 COMMAND_AR = $(AR) rcs $@ $^; $(RANLIB) $@
83 COMMAND_RC = $(WINDRES) -I. $(DF_TGT) -o $@ -i $<
84 COMMAND_INSTALL = ./tools/install.sh -m $1 $2 -d $3
85 COMMAND_RM = rm -f $1
86 COMMAND_IN = sed -f config.sed <"$1" >"$2"
87
88 ifeq ($(verbose),true)
89 DO_CC = $(COMMAND_CC)
90 DO_CXX = $(COMMAND_CXX)
91 DO_LD = $(COMMAND_LD)
92 DO_LDX = $(COMMAND_LDX)
93 DO_CCLD = $(COMMAND_CCLD)
94 DO_CXXLD = $(COMMAND_CXXLD)
95 DO_AR = $(COMMAND_AR)
96 DO_RC = $(COMMAND_RC)
97 DO_INSTALL = $(COMMAND_INSTALL)
98 DO_RM = $(COMMAND_RM)
99 DO_IN = $(COMMAND_IN)
100 SHELL_LINE_PREFIX =
101 else
102 DO_CC = @echo " CC $@"; $(COMMAND_CC)
103 DO_CXX = @echo " CXX $@"; $(COMMAND_CXX)
104 DO_LD = @echo " LINK $@"; $(COMMAND_LD)
105 DO_LDX = @echo " LINK $@"; $(COMMAND_LDX)
106 DO_CCLD = @echo " LINK $@"; $(COMMAND_CCLD)
107 DO_CXXLD = @echo " LINK $@"; $(COMMAND_CXXLD)
108 DO_AR = @echo " AR $@"; $(COMMAND_AR)
109 DO_RC = @echo " RC $@"; $(COMMAND_RC)
110 DO_INSTALL = @echo " CP $2"; $(COMMAND_INSTALL)
111 DO_RM = @echo " RM $1"; $(COMMAND_RM)
112 DO_IN = @echo " GEN $2"; $(COMMAND_IN)
113 SHELL_LINE_PREFIX = @
114 endif
115
116
117 #
118 # Define the implicit rules.
119 #
120
121 %.o: %.c
122 $(DO_CC)
123 %.o: %.cc
124 $(DO_CXX)
125 %.o: %.cpp
126 $(DO_CXX)
127 %.o: %.rc
128 $(DO_RC)
129 %$(EXEEXT): %.o
130 $(DO_LD)
131 %$(EXEEXT): %.c
132 $(DO_CCLD)
133 %$(EXEEXT): %.cc
134 $(DO_CXXLD)
135 %$(EXEEXT): %.cpp
136 $(DO_CXXLD)
137 %.a: %.o
138 $(DO_AR)
139 %: %.in config.sed
140 $(call DO_IN,$<,$@)
141
142
143 #
144 # Define the phony targets.
145 #
146
147 .PHONY: clean
148 clean:
149 $(SHELL_LINE_PREFIX)files='$(CLEAN)'; for file in $$files; \
150 do \
151 $(call remove_silencer,$(call DO_RM,$$file)); \
152 done
153
154 .PHONY: distclean
155 distclean: clean
156 $(call DO_RM,config.h)
157 $(call DO_RM,config.mk)
158 $(call DO_RM,config.sed)
159
160 .PHONY: all_
161 all_: $(BINARIES) $(MANPAGES)
162
163 .PHONY: install
164 install: all
165 $(SHELL_LINE_PREFIX)files='$(DATAFILES)'; for file in $$files; \
166 do \
167 full=`echo "$$file" | cut -d\; -f1`; \
168 base=`echo "$$file" | cut -d\; -f2`; \
169 $(call remove_silencer,$(call DO_INSTALL,644,$$full,$(DESTDIR)$(datadir)$$base)); \
170 done
171 $(SHELL_LINE_PREFIX)files='$(BINARIES)'; for file in $$files; \
172 do \
173 $(call remove_silencer,$(call DO_INSTALL,755,$$file,$(DESTDIR)$(bindir))); \
174 done
175 $(SHELL_LINE_PREFIX)files='$(MANPAGES)'; for file in $$files; \
176 do \
177 $(call remove_silencer,$(call DO_INSTALL,644,$$file,$(DESTDIR)$(mandir))); \
178 done
179
180 .PHONY: uninstall
181 uninstall:
182 $(SHELL_LINE_PREFIX)files='$(BINARIES)'; for file in $$files; \
183 do \
184 base="/`basename $$file`"; \
185 $(call remove_silencer,$(call DO_RM,$(DESTDIR)$(bindir)$$base)); \
186 done
187 $(SHELL_LINE_PREFIX)files='$(DATAFILES)'; for file in $$files; \
188 do \
189 full="`echo "$$file" | cut -d\; -f1`"; \
190 base="`echo "$$file" | cut -d\; -f2`/`basename $$full`"; \
191 $(call remove_silencer,$(call DO_RM,$(DESTDIR)$(datadir)$$base)); \
192 done
193
194 .PHONY: dist-bzip2
195 dist-bzip2:
196 $(SHELL_LINE_PREFIX)git archive HEAD --prefix='$(TARNAME)/' | bzip2 > "$(TARNAME).tar.bz2"
197
198 .PHONY: dist-gzip
199 dist-gzip:
200 $(SHELL_LINE_PREFIX)git archive HEAD --prefix='$(TARNAME)/' | gzip > "$(TARNAME).tar.gz"
201
202 .PHONY: dist
203 dist: dist-bzip2
204
205
206 #
207 # Prevent make from removing any build targets.
208 #
209
210 .SECONDARY: $(CLEAN)
211
This page took 0.039208 seconds and 3 git commands to generate.