repository cleanup
[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 ifeq ($(DEP_TRACKING),true)
70 COMPILE = ./tools/compile.lua
71 endif
72
73 COMMAND_CC = $(COMPILE) $(CC) $(CFLAGS) $(CF_TGT) -o $@ -c $<
74 COMMAND_CXX = $(COMPILE) $(CXX) $(CXXFLAGS) $(CF_TGT) -o $@ -c $<
75 COMMAND_LD = $(CC) $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
76 COMMAND_LDX = $(CXX) $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
77 COMMAND_CCLD = $(COMPILE) $(CC) $(CFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
78 COMMAND_CXXLD = $(COMPILE) $(CXX) $(CXXFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
79 COMMAND_AR = $(AR) rcs $@ $^; $(RANLIB) $@
80 COMMAND_RC = $(WINDRES) $(DDEFINES) $(DF_TGT) -o $@ -i $<
81 COMMAND_INSTALL = ./tools/install.sh -m $1 $2 -d $3
82 COMMAND_RM = rm -f $1
83 COMMAND_IN = sed -f config.sed <"$1" >"$2"
84
85 ifeq ($(verbose),yes)
86 DO_CC = $(COMMAND_CC)
87 DO_CXX = $(COMMAND_CXX)
88 DO_LD = $(COMMAND_LD)
89 DO_LDX = $(COMMAND_LDX)
90 DO_CCLD = $(COMMAND_CCLD)
91 DO_CXXLD = $(COMMAND_CXXLD)
92 DO_AR = $(COMMAND_AR)
93 DO_RC = $(COMMAND_RC)
94 DO_INSTALL = $(COMMAND_INSTALL)
95 DO_RM = $(COMMAND_RM)
96 DO_IN = $(COMMAND_IN)
97 SHELL_LINE_PREFIX =
98 else
99 DO_CC = @echo -e " CC \t$@"; $(COMMAND_CC)
100 DO_CXX = @echo -e " CXX \t$@"; $(COMMAND_CXX)
101 DO_LD = @echo -e " LD \t$@"; $(COMMAND_LD)
102 DO_LDX = @echo -e " LD \t$@"; $(COMMAND_LDX)
103 DO_CCLD = @echo -e " CCLD \t$@"; $(COMMAND_CCLD)
104 DO_CXXLD = @echo -e " CXXLD \t$@"; $(COMMAND_CXXLD)
105 DO_AR = @echo -e " AR \t$@"; $(COMMAND_AR)
106 DO_RC = @echo -e " RC \t$@"; $(COMMAND_RC)
107 DO_INSTALL = @echo -e " CP \t$2"; $(COMMAND_INSTALL)
108 DO_RM = @echo -e " RM \t$1"; $(COMMAND_RM)
109 DO_IN = @echo -e " MAKE \t$2"; $(COMMAND_IN)
110 SHELL_LINE_PREFIX = @
111 endif
112
113
114 #
115 # Define the implicit rules.
116 #
117
118 %.o: %.c
119 $(DO_CC)
120 %.o: %.cc
121 $(DO_CXX)
122 %.o: %.cpp
123 $(DO_CXX)
124 %.o: %.rc
125 $(DO_RC)
126 %: %.o
127 $(DO_LD)
128 %: %.c
129 $(DO_CCLD)
130 %: %.cc
131 $(DO_CXXLD)
132 %: %.cpp
133 $(DO_CXXLD)
134 %.a: %.o
135 $(DO_AR)
136 %: %.in
137 $(call DO_IN,$<,$@)
138
139
140 #
141 # Define the phony targets.
142 #
143
144 .PHONY: clean
145 clean:
146 $(SHELL_LINE_PREFIX)files='$(CLEAN)'; for file in $$files; \
147 do \
148 $(call remove_silencer,$(call DO_RM,$$file)); \
149 done
150
151 .PHONY: distclean
152 distclean: clean
153 $(call DO_RM,config.h)
154 $(call DO_RM,config.mk)
155 $(call DO_RM,config.sed)
156
157 .PHONY: all_
158 all_: $(BINARIES) $(MANPAGES)
159
160 .PHONY: install
161 install: all
162 $(SHELL_LINE_PREFIX)files='$(DATAFILES)'; for file in $$files; \
163 do \
164 full=`echo "$$file" | cut -d\; -f1`; \
165 base=`echo "$$file" | cut -d\; -f2`; \
166 $(call remove_silencer,$(call DO_INSTALL,644,$$full,$(DESTDIR)$(datadir)$$base)); \
167 done
168 $(SHELL_LINE_PREFIX)files='$(BINARIES)'; for file in $$files; \
169 do \
170 $(call remove_silencer,$(call DO_INSTALL,755,$$file,$(DESTDIR)$(bindir))); \
171 done
172 $(SHELL_LINE_PREFIX)files='$(MANPAGES)'; for file in $$files; \
173 do \
174 $(call remove_silencer,$(call DO_INSTALL,644,$$file,$(DESTDIR)$(mandir))); \
175 done
176
177 .PHONY: uninstall
178 uninstall:
179 $(SHELL_LINE_PREFIX)files='$(BINARIES)'; for file in $$files; \
180 do \
181 base="/`basename $$file`"; \
182 $(call remove_silencer,$(call DO_RM,$(DESTDIR)$(bindir)$$base)); \
183 done
184 $(SHELL_LINE_PREFIX)files='$(DATAFILES)'; for file in $$files; \
185 do \
186 full="`echo "$$file" | cut -d\; -f1`"; \
187 base="`echo "$$file" | cut -d\; -f2`/`basename $$full`"; \
188 $(call remove_silencer,$(call DO_RM,$(DESTDIR)$(datadir)$$base)); \
189 done
190
191
192 #
193 # Prevent make from removing any build targets.
194 #
195
196 .SECONDARY: $(CLEAN)
197
This page took 0.043115 seconds and 4 git commands to generate.