If you're hacky enough, you can now call into auto-generated interfaces from
[wvapps.git] / xplcidl / wvrules.mk
blobf4a8eac98ee50781262483df750f8381fb531b34
1 # wvrules.mk: 2003 09 09
3 # Copyright (C) 1998-2003 by Avery Pennarun <apenwarr@worldvisions.ca>.
4 # Use, distribute, modify, and redistribute freely. (But if you're nice,
5 # you'll send all your changes back to me.)
7 # This is a complicated-looking set of Makefile rules that should make your
8 # own Makefiles simpler, by providing for several useful features (like
9 # autodependencies and a 'clean' target) without any extra effort.
11 # It will only work with GNU make.
14 # if WVSTREAMS_SRC is set assume everything else is set.
15 # For packages that use WvStreams use WVSTREAMS_SRC=. for distribution.
16 ifeq ($(WVSTREAMS_SRC),)
17 ifeq ($(WVSTREAMS),)
18 $(error The WVSTREAMS variable is not defined)
19 endif
20 WVSTREAMS_SRC=$(WVSTREAMS)
21 WVSTREAMS_LIB=$(WVSTREAMS)
22 WVSTREAMS_INC=$(WVSTREAMS)/include
23 WVSTREAMS_BIN=$(WVSTREAMS)
24 endif
25 export WVSTREAMS WVSTREAMS_SRC WVSTREAMS_LIB WVSTREAMS_INC WVSTREAMS_BIN
27 SHELL=/bin/bash
29 ifeq (${WVTESTRUN},)
30 WVTESTRUN=$(WVSTREAMS_BIN)/wvtesthelper
31 endif
33 #ifneq "$(filter-out $(NO_CONFIGURE_TARGETS),$(if $(MAKECMDGOALS),$(MAKECMDGOALS),default))" ""
34 # -include config.mk
35 #endif
37 ifneq ($(wildcard $(WVSTREAMS_SRC)/config.mk),)
38 include $(WVSTREAMS_SRC)/config.mk
39 endif
41 ifneq ("$(with_xplc)", "no")
42 LDFLAGS+=-L$(with_xplc)
43 LIBXPLC=-lxplc-cxx -lxplc
44 endif
46 LIBWVBASE=$(WVSTREAMS_LIB)/libwvbase.so $(LIBXPLC)
47 LIBWVUTILS=$(WVSTREAMS_LIB)/libwvutils.so $(LIBWVBASE)
48 LIBWVSTREAMS=$(WVSTREAMS_LIB)/libwvstreams.so $(LIBWVUTILS)
49 LIBWVOGG=$(WVSTREAMS_LIB)/libwvoggvorbis.so $(LIBWVSTREAMS)
50 LIBUNICONF=$(WVSTREAMS_LIB)/libuniconf.so $(LIBWVSTREAMS)
51 LIBWVQT=$(WVSTREAMS_LIB)/libwvqt.so $(LIBWVSTREAMS)
54 # Initial C compilation flags
56 CPPFLAGS += $(CPPOPTS)
57 C_AND_CXX_FLAGS += -D_BSD_SOURCE -D_GNU_SOURCE $(OSDEFINE) \
58 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
59 CFLAGS += $(COPTS) $(C_AND_CXX_FLAGS)
60 CXXFLAGS += $(CXXOPTS) $(C_AND_CXX_FLAGS)
61 LDFLAGS += $(LDOPTS) -L$(WVSTREAMS_LIB)
63 # FIXME: what does this do??
64 XX_LIBS := $(XX_LIBS) $(shell $(CC) -lsupc++ -lgcc_eh 2>&1 | grep -q "undefined reference" && echo " -lsupc++ -lgcc_eh")
66 ifeq ("$(enable_debug)", "yes")
67 DEBUG:=1
68 else
69 DEBUG:=0
70 endif
72 ifeq ("$(enable_fatal_warnings)", "yes")
73 CXXFLAGS+=-Werror
74 # FIXME: not for C, because our only C file, crypto/wvsslhack.c, has
75 # a few warnings on purpose.
76 #CFLAGS+=-Werror
77 endif
79 ifneq ("$(enable_optimization)", "no")
80 CXXFLAGS+=-O2
81 #CXXFLAGS+=-felide-constructors
82 CFLAGS+=-O2
83 endif
85 ifneq ("$(enable_warnings)", "no")
86 CXXFLAGS+=-Wall -Woverloaded-virtual
87 CFLAGS+=-Wall
88 endif
90 ifneq ("$(enable_rtti)", "yes")
91 CXXFLAGS+=-fno-rtti
92 endif
94 ifneq ("$(enable_exceptions)", "yes")
95 CXXFLAGS+=-fno-exceptions
96 endif
98 ifeq ("$(enable_efence)", "yes")
99 EFENCE:=-lefence
100 USE_EFENCE:=1
101 endif
103 ifeq (USE_EFENCE,1)
104 LDLIBS+=$(EFENCE)
105 endif
107 ifeq ("$(enable_verbose)", "yes")
108 VERBOSE:=1
109 endif
111 ifdef DONT_LIE
112 VERBOSE:=1 $(warning DONT_LIE is deprecated, use VERBOSE instead)
113 endif
115 STRIP=strip --remove-section=.note --remove-section=.comment
116 #STRIP=echo
118 # macros that expand to the object files in the given directories
119 objects=$(sort $(foreach type,c cc,$(call objects_$(type),$1)))
120 objects_c=$(patsubst %.c,%.o,$(wildcard $(addsuffix /*.c,$1)))
121 objects_cc=$(patsubst %.cc,%.o,$(wildcard $(addsuffix /*.cc,$1)))
123 # macro that expands to the subdir.mk files to include
124 xsubdirs=$(sort $(wildcard $1/*/subdir.mk)) /dev/null
126 # we need a default rule, since the 'includes' below causes trouble
127 .PHONY: default all
128 default: all
130 # default "test" rule does nothing...
131 .PHONY: test runtests
132 test:
133 runtests:
135 %/test:
136 $(MAKE) -C $(dir $@) test
138 $(WVSTREAMS_SRC)/rules.local.mk:
139 @true
141 -include $(WVSTREAMS_SRC)/rules.local.mk
144 # Figure out which OS we're running (for now, only picks out Linux or BSD)
146 OS:=$(shell uname -a | awk '{print $$1}' | sed -e 's/^.*BSD/BSD/g' )
149 # (Just BSD and LINUX clash with other symbols, so use ISLINUX and ISBSD)
150 # This sucks. Use autoconf for most things!
152 ifeq ($(OS),Linux)
153 OSDEFINE:=-DISLINUX
154 endif
156 ifeq ($(OS),BSD)
157 OSDEFINE:=-DISBSD
158 endif
160 ifeq ($(CCMALLOC),1)
161 ifeq ($(DEBUG),1)
162 XX_LIBS += -lccmalloc -ldl
163 endif
164 endif
166 ifeq ($(DEBUG),1)
167 C_AND_CXX_FLAGS += -ggdb -DDEBUG=1
168 LDFLAGS += -ggdb
169 else
170 C_AND_CXX_FLAGS += -g -DDEBUG=0
171 #CFLAGS += -DNDEBUG # I don't like disabling assertions...
172 #CFLAGS += -fomit-frame-pointer # really evil
173 #CXXFLAGS += -fno-implement-inlines # causes trouble with egcs 1.0
174 LDFLAGS += -g
175 endif
177 ifeq ($(PROFILE),1)
178 CFLAGS += -pg
179 LDFLAGS += -pg
180 endif
182 ifeq ($(STATIC),1)
183 LDFLAGS += -static
184 endif
186 INCFLAGS=$(addprefix -I,$(WVSTREAMS_INC) $(XPATH))
187 CPPFLAGS+=$(INCFLAGS)
188 CFLAGS+=$(CPPFLAGS)
189 CXXFLAGS+=$(CPPFLAGS)
191 ifeq ($(VERBOSE),1)
192 COMPILE_MSG =
193 LINK_MSG =
194 DEPEND_MSG=
195 else
196 COMPILE_MSG = @echo compiling $@...;
197 LINK_MSG = @echo linking $@...;
198 #DEPEND_MSG = @echo " depending $@...";
199 DEPEND_MSG = @
200 endif
202 # any rule that depends on FORCE will always run
203 .PHONY: FORCE
204 FORCE:
206 # usage: $(wvcc_base,outfile,infile,stem,compiler cflags,mode)
207 # eg: $(wvcc,foo.o,foo.cc,foo,$(CC) $(CFLAGS) -fPIC,-c)
208 DEPFILE = $(if $(filter %.o,$1),$(dir $1).$(notdir $(1:.o=.d)),/dev/null)
209 define wvcc_base
210 @rm -f "$1"
211 $(COMPILE_MSG)$4 $5 $2 -o $1
212 $(DEPEND_MSG)$4 -M -E $< \
213 | sed -e 's|^[^:]*:|$1:|' >$(DEPFILE)
214 endef
215 wvcc=$(call wvcc_base,$1,$2,$3,$(CC) $(CFLAGS) $($1-CPPFLAGS) $($1-CFLAGS) $4,$(if $5,$5,-c))
216 wvcxx=$(call wvcc_base,$1,$2,$3,$(CXX) $(CFLAGS) $(CXXFLAGS) $($1-CPPFLAGS) $($1-CFLAGS) $($1-CXXFLAGS) $4,$(if $5,$5,-c))
218 define wvlink_ar
219 $(LINK_MSG)set -e; rm -f $1 $(patsubst %.a,%.libs,$1); \
220 echo $2 >$(patsubst %.a,%.libs,$1); \
221 ar q $1 $(filter %.o,$2); \
222 for d in $(filter %.libs,$2); do \
223 cd $$(dirname "$$d"); \
224 ar q $(shell pwd)/$1 $$(cat $$(basename $$d)); \
225 cd $(shell pwd); \
226 done; \
227 ranlib $1
228 endef
229 wvsoname=$(if $($1-SONAME),$($1-SONAME),$(if $(SONAME),$(SONAME),$1))
230 define wvlink_so
231 $(LINK_MSG)$(CC) $(LDFLAGS) $($1-LDFLAGS) -Wl,-soname,$(call wvsoname,$1) -shared -o $1 $(filter %.o %.a %.so,$2) $($1-LIBS) $(LIBS) $(XX_LIBS)
232 $(if $(filter-out $(call wvsoname,$1),$1),ln -sf $1 $(call wvsoname,$1))
233 endef
235 wvlink=$(LINK_MSG)$(CC) $(LDFLAGS) $($1-LDFLAGS) -o $1 $(filter %.o %.a %.so, $2) $($1-LIBS) $(LIBS) $(XX_LIBS) $(LDLIBS)
237 %.o: %.c; $(call wvcc ,$@,$<,$*)
238 %.fpic.o: %.c; $(call wvcc ,$@,$<,$*,-fPIC)
239 %.o: %.cc; $(call wvcxx,$@,$<,$*)
240 %.fpic.o: %.cc; $(call wvcxx,$@,$<,$*,-fPIC)
241 %.o: %.cpp; $(call wvcxx,$@,$<,$*)
242 %.fpic.o:%.cpp; $(call wvcxx,$@,$<,$*,-fPIC)
243 %.s: %.c; $(call wvcc ,$@,$<,$*,,-S)
244 %.s: %.cc; $(call wvcxx,$@,$<,$*,,-S)
245 %.s: %.cpp; $(call wvcxx,$@,$<,$*,,-S)
246 %.E: %.c; $(call wvcc,$@,$<,$*,,-E)
247 %.E: %.cc; $(call wvcxx,$@,$<,$*,,-E)
248 %.E: %.cpp; $(call wvcxx,$@,$<,$*,,-E)
250 %.moc: %.h; moc -o $@ $<
252 ../%.so:; @echo "Shared library $@ does not exist!"; exit 1
253 ../%.a:; @echo "Library $@ does not exist!"; exit 1
254 ../%.o:; @echo "Object $@ does not exist!"; exit 1
255 /%.a:; @echo "Library $@ does not exist!"; exit 1
257 %: %.o; $(call wvlink,$@,$^)
258 %.t: %.t.o; $(call wvlink,$@,$(WVSTREAMS_SRC)/wvtestmain.o $(call reverse,$(filter %.o,$^)) $(filter-out %.o,$^) $(LIBWVUTILS))
259 %.a %.libs:; $(call wvlink_ar,$@,$^)
260 %.so:; $(call wvlink_so,$@,$^)
262 # Force objects to be built before final binaries
263 $(addsuffix .o,$(basename $(wildcard *.c) $(wildcard *.cc) $(wildcard *.cpp))):
265 %.gz: FORCE %
266 @rm -f $@
267 gzip -f $*
268 @ls -l $@
271 # Header files for tcl/tk packages
273 pkgIndex.tcl: $(filter-out pkgIndex.tcl,$(wildcard *.tcl))
274 @echo Generating pkgIndex.tcl...
275 @rm -f $@
276 @echo pkg_mkIndex . \
277 $$(echo $^ | sed 's,\.tcl_paths,,') | tclsh
279 pkgIndex.tcl $(wildcard *.tcl): .tcl_paths
280 .tcl_paths:
281 @echo Generating .tcl_paths...
282 @rm -f $@
283 @find . $(TOPDIR) -name '*.tcl' -printf '%h\n' | sort | uniq | \
284 (echo lappend auto_path \\; sed 's/^.*$$/ & \\/'; echo) >$@.tmp
285 @mv $@.tmp $@
288 # We automatically generate header dependencies for .c and .cc files. The
289 # dependencies are stored in the file ".filename.d"
291 depfiles_sf = $(wildcard .*.d t/.*.d)
293 ifneq ($(depfiles_sf),)
294 -include $(depfiles_sf)
295 endif
299 # A macro for compiling subdirectories listed in the SUBDIRS variable.
300 # Tries to make the target ($@) in each subdir, unless the target is called
301 # "subdirs" in which case it makes "all" in each subdir.
303 define subdirs_func
304 +@OLDDIR="$$(pwd)"; set -e; \
305 for d in __fx__ $2; do \
306 if [ "$$d" = "__fx__" ]; then continue; fi; \
307 cd "$$d"; \
308 echo ; \
309 echo "--> Making $1 in $$(pwd)..."; \
310 $(MAKE) --no-print-directory $1 || exit 1; \
311 cd "$$OLDDIR"; \
312 done
313 @echo
314 @echo "--> Back in $$(pwd)..."
315 endef
317 subdirs = $(call subdirs_func,$(subst subdirs,all,$(if $1,$1,$@)),$(if $2,$2,$(SUBDIRS)))
319 # # $(call reverse,$(SUBDIRS)) works since GNU make 3.80 only
320 # reverse = \
321 # $(if $(1),$(call reverse,$(wordlist 2, 999, $(1))) $(firstword $(1)))
323 define shell_reverse
324 revlist="" ; \
325 for word in $(1) ; do \
326 revlist="$${word} $${revlist}"; \
327 done ; \
328 echo "$${revlist}"
329 endef
331 reverse = $(shell $(call shell_reverse,$(1)))
333 clean_subdirs = $(call subdirs,clean,$(call reverse,$(SUBDIRS)),keep)
335 %: %/Makefile FORCE
336 @cd "$@"; echo; echo "--> Making all in $$(pwd)..."; \
337 $(MAKE) --no-print-directory all
339 subdirs: ${SUBDIRS}
342 # Auto-clean rule. Feel free to append to this in your own directory, by
343 # defining your own "clean" rule.
345 clean: FORCE _wvclean
347 _wvclean: FORCE
348 rm -f *~ *.tmp *.o *.a *.so *.so.* *.libs *.moc *.d .*.d .depend .\#* \
349 .tcl_paths pkgIndex.tcl gmon.out core build-stamp wvtestmain
350 rm -f $(patsubst %.t.cc,%.t,$(wildcard *.t.cc) $(wildcard t/*.t.cc)) \
351 t/*.o t/*~ t/.*.d t/.\#*
352 rm -rf debian/tmp
355 # default dist rules.
356 distclean: clean
358 dist: distclean ChangeLog
360 ChangeLog: FORCE
361 rm -f ChangeLog ChangeLog.bak
362 cvs2cl --utc
365 # Make 'tags' file using the ctags program - useful for editing
367 #tags: $(shell find -name '*.cc' -o -name '*.[ch]')
368 # @echo '(creating "tags")'
369 # @if [ -x /usr/bin/ctags ]; then /usr/bin/ctags $^; fi