ead9c51cc3c5d1d9b52e4ee09878d25b4b8fd904
[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, cleandist, run, debug
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 `yes' to echo each build command in full.
14 verbose := no
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 no_config:
28 $(error You must run the configure script before you can make anything)
29 endif
30
31
32 #
33 # Declare the default targets and implicit rules.
34 #
35
36 .PHONY: all
37 all: all_
38
39 .SUFFIXES:
40 .SUFFIXES: .a .c .cc .cpp .in .o .rc
41
42
43 #
44 # Define some useful functions.
45 #
46
47 add_exe_suffix = $(addsuffix $(EXEEXT),$1)
48 remove_silencer = $(1:@%=%)
49
50
51 #
52 # Include the subdirectories--order is not important.
53 #
54
55 dir := src
56 include $(dir)/rules.mk
57
58 dir := data
59 include $(dir)/rules.mk
60
61 dir := doc
62 include $(dir)/rules.mk
63
64
65 #
66 # Define some common rules.
67 #
68
69 CC_WRAPPER = ./build/compile.sh $(CC)
70 CXX_WRAPPER = ./build/compile.sh $(CXX)
71
72 COMMAND_CC = $(CC_WRAPPER) $(CFLAGS) $(CF_TGT) -o $@ -c $<
73 COMMAND_CXX = $(CXX_WRAPPER) $(CXXFLAGS) $(CF_TGT) -o $@ -c $<
74 COMMAND_LD = $(CC) $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
75 COMMAND_LDX = $(CXX) $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
76 COMMAND_CCLD = $(CC_WRAPPER) $(CFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
77 COMMAND_CXXLD = $(CXX_WRAPPER) $(CXXFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
78 COMMAND_AR = $(AR) rcs $@ $^; $(RANLIB) $@
79 COMMAND_RC = $(WINDRES) $(DDEFINES) $(DF_TGT) -o $@ -i $<
80 COMMAND_INSTALL = ./build/install.sh -m $1 $2 -d $3
81 COMMAND_RM = rm -f $1
82 COMMAND_IN = ./build/process.sh $1 $2
83
84 ifeq ($(verbose),yes)
85 DO_CC = $(COMMAND_CC)
86 DO_CXX = $(COMMAND_CXX)
87 DO_LD = $(COMMAND_LD)
88 DO_LDX = $(COMMAND_LDX)
89 DO_CCLD = $(COMMAND_CCLD)
90 DO_CXXLD = $(COMMAND_CXXLD)
91 DO_AR = $(COMMAND_AR)
92 DO_RC = $(COMMAND_RC)
93 DO_INSTALL = $(COMMAND_INSTALL)
94 DO_RM = $(COMMAND_RM)
95 DO_IN = $(COMMAND_IN)
96 SHELL_LINE_PREFIX =
97 else
98 DO_CC = @echo -e " CC \t$@"; $(COMMAND_CC)
99 DO_CXX = @echo -e " CXX \t$@"; $(COMMAND_CXX)
100 DO_LD = @echo -e " LD \t$@"; $(COMMAND_LD)
101 DO_LDX = @echo -e " LD \t$@"; $(COMMAND_LDX)
102 DO_CCLD = @echo -e " CCLD \t$@"; $(COMMAND_CCLD)
103 DO_CXXLD = @echo -e " CXXLD \t$@"; $(COMMAND_CXXLD)
104 DO_AR = @echo -e " AR \t$@"; $(COMMAND_AR)
105 DO_RC = @echo -e " RC \t$@"; $(COMMAND_RC)
106 DO_INSTALL = @echo -e " CP \t$2"; $(COMMAND_INSTALL)
107 DO_RM = @echo -e " RM \t$1"; $(COMMAND_RM)
108 DO_IN = @echo -e " MAKE \t$2"; $(COMMAND_IN)
109 SHELL_LINE_PREFIX = @
110 endif
111
112
113 #
114 # Define the implicit rules.
115 #
116
117 %.o: %.c
118 $(DO_CC)
119 %.o: %.cc
120 $(DO_CXX)
121 %.o: %.cpp
122 $(DO_CXX)
123 %.o: %.rc
124 $(DO_RC)
125 %: %.o
126 $(DO_LD)
127 %: %.c
128 $(DO_CCLD)
129 %: %.cc
130 $(DO_CXXLD)
131 %: %.cpp
132 $(DO_CXXLD)
133 %.a: %.o
134 $(DO_AR)
135 %: %.in
136 $(call DO_IN,$<,$@)
137
138
139 #
140 # Define the phony targets.
141 #
142
143 .PHONY: clean
144 clean:
145 $(SHELL_LINE_PREFIX)files='$(CLEAN)'; for file in $$files; \
146 do \
147 $(call remove_silencer,$(call DO_RM,$$file)); \
148 done
149
150 .PHONY: distclean
151 distclean: clean
152 $(call DO_RM,config.mk)
153
154 .PHONY: all_
155 all_: $(BINARIES) $(MANPAGES)
156
157 .PHONY: install
158 install: all
159 $(SHELL_LINE_PREFIX)files='$(DATAFILES)'; for file in $$files; \
160 do \
161 full=`echo "$$file" | cut -d\; -f1`; \
162 base=`echo "$$file" | cut -d\; -f2`; \
163 $(call remove_silencer,$(call DO_INSTALL,644,$$full,$(DESTDIR)$(datadir)$$base)); \
164 done
165 $(SHELL_LINE_PREFIX)files='$(BINARIES)'; for file in $$files; \
166 do \
167 $(call remove_silencer,$(call DO_INSTALL,755,$$file,$(DESTDIR)$(bindir))); \
168 done
169 $(SHELL_LINE_PREFIX)files='$(MANPAGES)'; for file in $$files; \
170 do \
171 $(call remove_silencer,$(call DO_INSTALL,644,$$file,$(DESTDIR)$(mandir))); \
172 done
173
174 .PHONY: uninstall
175 uninstall:
176 $(SHELL_LINE_PREFIX)files='$(BINARIES)'; for file in $$files; \
177 do \
178 base="/`basename $$file`"; \
179 $(call remove_silencer,$(call DO_RM,$(DESTDIR)$(bindir)$$base)); \
180 done
181 $(SHELL_LINE_PREFIX)files='$(DATAFILES)'; for file in $$files; \
182 do \
183 full="`echo "$$file" | cut -d\; -f1`"; \
184 base="`echo "$$file" | cut -d\; -f2`/`basename $$full`"; \
185 $(call remove_silencer,$(call DO_RM,$(DESTDIR)$(datadir)$$base)); \
186 done
187
188
189 #
190 # Prevent make from removing any build targets.
191 #
192
193 .SECONDARY: $(CLEAN)
194
This page took 0.03921 seconds and 4 git commands to generate.