Make WvStreams compile with gcc 4.4.
[wvstreams.git] / wvrules.mk
blob72cccb314c957440467bb738314e29ae4da2f568
1 # wvrules.mk
3 # Copyright (C) 1998-2007 by Avery Pennarun <apenwarr@alumnit.ca>
4 # and contributors.
5 # Use, distribute, modify, and redistribute freely. (But if you're nice,
6 # you'll send all your changes back to me.)
8 # This is a complicated-looking set of Makefile rules that should make your
9 # own Makefiles simpler, by providing for several useful features (like
10 # autodependencies and a 'clean' target) without any extra effort.
12 # It will only work with GNU make.
15 # we need a default rule, since the 'includes' below can cause trouble
16 .PHONY: default all
17 default: all
19 all: CC CXX
21 # if WVSTREAMS_SRC is set assume everything else is set.
22 # For packages that use WvStreams use WVSTREAMS_SRC=. for distribution.
23 ifneq ($(WVSTREAMS),)
24 WVSTREAMS_SRC=$(WVSTREAMS)
25 WVSTREAMS_LIB=$(WVSTREAMS)
26 WVSTREAMS_INC=$(WVSTREAMS)/include
27 WVSTREAMS_BIN=$(WVSTREAMS)
28 endif
29 export WVSTREAMS WVSTREAMS_SRC WVSTREAMS_LIB WVSTREAMS_INC WVSTREAMS_BIN
31 SHELL=/bin/bash
33 include $(WVSTREAMS_SRC)/config.defaults.mk
34 -include $(WVSTREAMS_SRC)/config.mk
35 -include $(WVSTREAMS_SRC)/config.overrides.mk
36 -include $(WVSTREAMS_SRC)/local.mk
38 ifeq (${OS},SOLARIS)
39 _SOLARIS= _SOLARIS
40 AR=gar
41 endif
43 ifeq (${OS},MACOS)
44 _MACOS=_MACOS
45 endif
47 ifeq (${OS},WIN32)
48 _WIN32=_WIN32
49 endif
51 ifdef _WIN32
52 XPATH += $(WVSTREAMS)/win32 $(WVSTREAMS)/win32/cominclude
53 AR=i586-mingw32msvc-ar
54 LIBS += -lssl -lcrypto -lz -lole32 -lrpcrt4 -lwsock32 -lgdi32 -limagehlp \
55 -lstdc++
56 else
57 CFLAGS += -fPIC
58 CXXFLAGS += -fPIC
59 endif
61 include $(WVSTREAMS_SRC)/wvrules-$(COMPILER_STANDARD).mk
63 ifeq (${WVTESTRUN},)
64 WVTESTRUN=$(WVSTREAMS_BIN)/wvtestrun
65 endif
67 # macros that expand to the object files in the given directories
68 objects=$(sort $(foreach type,c cc,$(call objects_$(type),$1)))
69 objects_c=$(filter-out $(WV_EXCLUDES), \
70 $(patsubst %.c,%.o,$(wildcard $(addsuffix /*.c,$1))))
71 objects_cc=$(filter-out $(WV_EXCLUDES), \
72 $(patsubst %.cc,%.o,$(wildcard $(addsuffix /*.cc,$1))))
73 tests_cc=$(filter-out $(WV_EXCLUDES), \
74 $(patsubst %.cc,%,$(wildcard $(addsuffix /*.cc,$1))))
76 # default "test" rule does nothing...
77 .PHONY: test runtests
78 test:
79 runtests:
81 %/test:
82 $(MAKE) -C $(dir $@) test
84 INCFLAGS=$(addprefix -I,$(WVSTREAMS_INC) $(XPATH))
85 CPPFLAGS+=$(INCFLAGS) \
86 -D_BSD_SOURCE -D_GNU_SOURCE $(OSDEFINE) \
87 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
88 -DUNSTABLE
90 ifeq ($(VERBOSE),1)
91 COMPILE_MSG :=
92 LINK_MSG :=
93 DEPEND_MSG :=
94 SYMLINK_MSG :=
95 else
96 COMPILE_MSG = @echo compiling $@...;
97 LINK_MSG = @echo linking $@...;
98 #DEPEND_MSG = @echo " depending $@...";
99 DEPEND_MSG := @
100 SYMLINK_MSG := @
101 endif
103 # any rule that depends on FORCE will always run
104 .PHONY: FORCE
105 FORCE:
107 ifeq ($(LN_S),)
108 LN_S := ln -s
109 endif
110 ifeq ($(LN),)
111 LN := ln
112 endif
114 # Create symbolic links
115 # usage: $(wvlns,source,dest)
116 wvlns=$(SYMLINK_MSG)$(LN_S) -f $1 $2
118 # Create hard links
119 # usage: $(wvln,source,dest)
120 wvln=$(SYMLINK_MSG)$(LN) -f $1 $2
122 # usage: $(wvcc,outfile,infile,stem,extra_cflags,mode)
123 # eg: $(wvcc,foo.o,foo.cc,foo,-fPIC,-c)
125 define wvcc
126 ./CC $(if $5,$5,-c) $3 $($1-CFLAGS) $($1-CPPFLAGS) $4
127 endef
129 define wvcxx
130 ./CXX $(if $5,$5,-c) $3 $($1-CXXFLAGS) $($1-CPPFLAGS) $4
131 endef
133 %.so: SONAME=$@$(if $(SO_VERSION),.$(SO_VERSION))
135 wvsoname=$(if $($1-SONAME),$($1-SONAME),$(if $(SONAME),$(SONAME),$1))
137 ifdef _WIN32
138 define wvlink_so
139 @echo "Skipping $@ on win32 (can't build shared libraries)"
140 endef
141 else ifdef _SOLARIS
142 define wvlink_so
143 @echo "Solaris Link!"
144 $(LINK_MSG)$(WVLINK_CC) $(LDFLAGS) $($1-LDFLAGS) -shared -o $1 $(filter %.o %.a %.so,$2) $($1-LIBS) $(LIBS) $(XX_LIBS)
145 endef
146 else ifdef _MACOS
147 define wvlink_so
148 @echo "MacOS Link!"
149 $(LINK_MSG)$(WVLINK_CC) $(LDFLAGS) $($1-LDFLAGS) -dynamiclib -o $1 $(filter %.o %.a %.so,$2) $($1-LIBS) $(LIBS) $(XX_LIBS)
150 endef
151 else
152 define wvlink_so
153 $(LINK_MSG)$(WVLINK_CC) $(LDFLAGS) $($1-LDFLAGS) -Wl,-z,defs -Wl,-soname,$(call wvsoname,$1) -shared -o $1 $(filter %.o %.a %.so,$2) $($1-LIBS) $(LIBS) $(XX_LIBS)
154 $(if $(filter-out $(call wvsoname,$1),$1),$(call wvlns,$1,$(call wvsoname,$1)))
155 endef
156 endif
158 ../%.so:; @echo "Shared library $@ does not exist!"; exit 1
159 ../%.a:; @echo "Library $@ does not exist!"; exit 1
160 ../%.o:; @echo "Object $@ does not exist!"; exit 1
161 /%.a:; @echo "Library $@ does not exist!"; exit 1
163 %.o: %.c; $(call wvcc ,$@,$<,$*)
164 %.fpic.o: %.c; $(call wvcc ,$@,$<,$*,-fPIC)
165 %.o: %.cc; $(call wvcxx,$@,$<,$*)
166 %.fpic.o: %.cc; $(call wvcxx,$@,$<,$*,-fPIC)
167 %.o: %.cpp; $(call wvcxx,$@,$<,$*)
168 %.fpic.o:%.cpp; $(call wvcxx,$@,$<,$*,-fPIC)
169 %.s: %.c; $(call wvcc ,$@,$<,$*,,-S)
170 %.s: %.cc; $(call wvcxx,$@,$<,$*,,-S)
171 %.s: %.cpp; $(call wvcxx,$@,$<,$*,,-S)
172 %.E: %.c; $(call wvcc,$@,$<,$*,,-E)
173 %.E: %.cc; $(call wvcxx,$@,$<,$*,,-E)
174 %.E: %.cpp; $(call wvcxx,$@,$<,$*,,-E)
176 %.moc: %.h; $(MOC) -o $@ $<
178 %: %.o; $(call wvlink,$@,$^)
179 %.t: %.t.o; $(call wvlink,$@,$(call reverse,$(filter %.o,$^)) $(filter-out %.o,$^) $(LIBWVTEST))
180 %.a %.libs:; $(call wvlink_ar,$@,$^)
181 %.so:; $(call wvlink_so,$@,$^)
183 # Force objects to be built before final binaries
184 $(addsuffix .o,$(basename $(wildcard *.c) $(wildcard *.cc) $(wildcard *.cpp))):
186 %.gz: FORCE %
187 @rm -f $@
188 gzip -f $*
189 @ls -l $@
192 # We automatically generate header dependencies for .c and .cc files. The
193 # dependencies are stored in the file ".filename.d", and we include them
194 # automatically here if they exist.
196 -include $(shell find . -name '.*.d') /dev/null
200 # A macro for compiling subdirectories listed in the SUBDIRS variable.
201 # Tries to make the target ($@) in each subdir, unless the target is called
202 # "subdirs" in which case it makes "all" in each subdir.
204 define subdirs_func
205 +@OLDDIR="$$(pwd)"; set -e; \
206 for d in __fx__ $2; do \
207 if [ "$$d" = "__fx__" ]; then continue; fi; \
208 cd "$$d"; \
209 echo ; \
210 echo "--> Making $1 in $$(pwd)..."; \
211 $(MAKE) --no-print-directory $1 || exit 1; \
212 cd "$$OLDDIR"; \
213 done
214 @echo
215 @echo "--> Back in $$(pwd)..."
216 endef
218 subdirs = $(call subdirs_func,$(subst subdirs,all,$(if $1,$1,$@)),$(if $2,$2,$(SUBDIRS)))
220 define shell_reverse
221 revlist="" ; \
222 for word in $(1) ; do \
223 revlist="$${word} $${revlist}"; \
224 done ; \
225 echo "$${revlist}"
226 endef
227 reverse = $(shell $(call shell_reverse,$(1)))
229 clean_subdirs = $(call subdirs,clean,$(call reverse,$(SUBDIRS)),keep)
231 %: %/Makefile FORCE
232 @cd "$@"; echo; echo "--> Making all in $$(pwd)..."; \
233 $(MAKE) --no-print-directory all
235 subdirs: ${SUBDIRS}
238 # Auto-clean rule. Feel free to append to this in your own directory, by
239 # defining your own "clean" and/or "distclean" rules.
241 .PHONY: clean _wvclean
243 clean: _wvclean
245 _wvclean:
246 @echo '--> Cleaning $(shell pwd)...'
247 @rm -f *~ *.tmp *.o *.a *.so *.so.* *.libs *.dll *.lib *.moc *.d .*.d .depend \
248 .\#* .tcl_paths pkgIndex.tcl gmon.out core build-stamp \
249 CC CXX \
250 wvtestmain
251 @rm -f $(patsubst %.t.cc,%.t,$(wildcard *.t.cc) $(wildcard t/*.t.cc)) \
252 t/*.o t/*~ t/.*.d t/.\#*
253 @rm -f valgrind.log.pid*
254 @rm -f semantic.cache tags
255 @rm -rf debian/tmp
257 dist-hook:
259 PKGDIR=$(WVPACKAGE_TARNAME)-$(WVPACKAGE_VERSION)
261 dist: config.mk dist-hook
262 @echo '--> Making dist in ../build/$(PKGDIR)...'
263 @test -d ../build || mkdir ../build
264 @rsync -a --delete --force '$(shell pwd)/' '../build/$(PKGDIR)'
265 cd ../build/$(PKGDIR) && git clean -d -f -x
266 cd ../build/$(PKGDIR) && git log > ChangeLog
267 cd ../build/$(PKGDIR) && ./autogen.sh
268 @find '../build/$(PKGDIR)' -name .git -type d -print0 | xargs -0 rm -rf --
269 @find '../build/$(PKGDIR)' -name .gitignore -type f -print0 | xargs -0 rm -f --
270 @rm -f '../build/$(PKGDIR).tar.gz'
271 @cd ../build; tar -zcf '$(PKGDIR).tar.gz' '$(PKGDIR)'
272 @echo '--> Created tarball in ../build/$(PKGDIR).tar.gz.'