Get rid of autoconf --datarootdir related warning.
[wvstreams.git] / wvrules.mk
blob4e317500c97bc2f4939818af968b3034092abb17
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 ($(wildcard $(WVSTREAMS_SRC)/config.mk),)
39 __junk:=$(shell echo "Warning: $(WVSTREAMS_SRC)/config.mk doesn't exist" >&2)
40 endif
42 ifeq (${EXEEXT},.exe)
43 _WIN32=_WIN32
44 XPATH += $(WVSTREAMS)/win32 $(WVSTREAMS)/win32/cominclude
45 AR=i586-mingw32msvc-ar
46 LIBS += -lssl -lcrypto -lz -lole32 -lrpcrt4 -lwsock32 -lgdi32 -limagehlp \
47 -lxplc-cxx -lxplc -lstdc++
48 else
49 CFLAGS += -fPIC
50 CXXFLAGS += -fPIC
51 endif
53 include $(WVSTREAMS_SRC)/wvrules-$(COMPILER_STANDARD).mk
55 ifeq (${WVTESTRUN},)
56 WVTESTRUN=$(WVSTREAMS_BIN)/wvtestrunner.pl
57 endif
59 # macros that expand to the object files in the given directories
60 objects=$(sort $(foreach type,c cc,$(call objects_$(type),$1)))
61 objects_c=$(filter-out $(WV_EXCLUDES), \
62 $(patsubst %.c,%.o,$(wildcard $(addsuffix /*.c,$1))))
63 objects_cc=$(filter-out $(WV_EXCLUDES), \
64 $(patsubst %.cc,%.o,$(wildcard $(addsuffix /*.cc,$1))))
65 tests_cc=$(filter-out $(WV_EXCLUDES), \
66 $(patsubst %.cc,%,$(wildcard $(addsuffix /*.cc,$1))))
68 # default "test" rule does nothing...
69 .PHONY: test runtests
70 test:
71 runtests:
73 %/test:
74 $(MAKE) -C $(dir $@) test
76 INCFLAGS=$(addprefix -I,$(WVSTREAMS_INC) $(XPATH))
77 CPPFLAGS+=$(INCFLAGS) \
78 -D_BSD_SOURCE -D_GNU_SOURCE $(OSDEFINE) \
79 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
81 ifeq ($(VERBOSE),1)
82 COMPILE_MSG :=
83 LINK_MSG :=
84 DEPEND_MSG :=
85 SYMLINK_MSG :=
86 else
87 COMPILE_MSG = @echo compiling $@...;
88 LINK_MSG = @echo linking $@...;
89 #DEPEND_MSG = @echo " depending $@...";
90 DEPEND_MSG := @
91 SYMLINK_MSG := @
92 endif
94 # any rule that depends on FORCE will always run
95 .PHONY: FORCE
96 FORCE:
98 ifeq ($(LN_S),)
99 LN_S := ln -s
100 endif
101 ifeq ($(LN),)
102 LN := ln
103 endif
105 # Create symbolic links
106 # usage: $(wvlns,source,dest)
107 wvlns=$(SYMLINK_MSG)$(LN_S) -f $1 $2
109 # Create hard links
110 # usage: $(wvln,source,dest)
111 wvln=$(SYMLINK_MSG)$(LN) -f $1 $2
113 # usage: $(wvcc,outfile,infile,stem,extra_cflags,mode)
114 # eg: $(wvcc,foo.o,foo.cc,foo,-fPIC,-c)
116 define wvcc
117 ./CC $(if $5,$5,-c) $3 $($1-CFLAGS) $($1-CPPFLAGS) $4
118 endef
120 define wvcxx
121 ./CXX $(if $5,$5,-c) $3 $($1-CXXFLAGS) $($1-CPPFLAGS) $4
122 endef
124 %.so: SONAME=$@$(if $(SO_VERSION),.$(SO_VERSION))
126 wvsoname=$(if $($1-SONAME),$($1-SONAME),$(if $(SONAME),$(SONAME),$1))
127 ifdef _WIN32
128 define wvlink_so
129 @echo "Skipping $@ on win32 (can't build shared libraries)"
130 endef
131 else
132 define wvlink_so
133 $(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)
134 $(if $(filter-out $(call wvsoname,$1),$1),$(call wvlns,$1,$(call wvsoname,$1)))
135 endef
136 endif
138 ../%.so:; @echo "Shared library $@ does not exist!"; exit 1
139 ../%.a:; @echo "Library $@ does not exist!"; exit 1
140 ../%.o:; @echo "Object $@ does not exist!"; exit 1
141 /%.a:; @echo "Library $@ does not exist!"; exit 1
143 %.o: %.c; $(call wvcc ,$@,$<,$*)
144 %.fpic.o: %.c; $(call wvcc ,$@,$<,$*,-fPIC)
145 %.o: %.cc; $(call wvcxx,$@,$<,$*)
146 %.fpic.o: %.cc; $(call wvcxx,$@,$<,$*,-fPIC)
147 %.o: %.cpp; $(call wvcxx,$@,$<,$*)
148 %.fpic.o:%.cpp; $(call wvcxx,$@,$<,$*,-fPIC)
149 %.s: %.c; $(call wvcc ,$@,$<,$*,,-S)
150 %.s: %.cc; $(call wvcxx,$@,$<,$*,,-S)
151 %.s: %.cpp; $(call wvcxx,$@,$<,$*,,-S)
152 %.E: %.c; $(call wvcc,$@,$<,$*,,-E)
153 %.E: %.cc; $(call wvcxx,$@,$<,$*,,-E)
154 %.E: %.cpp; $(call wvcxx,$@,$<,$*,,-E)
156 %.moc: %.h; moc -o $@ $<
158 %: %.o; $(call wvlink,$@,$^)
159 %.t: %.t.o; $(call wvlink,$@,$(call reverse,$(filter %.o,$^)) $(filter-out %.o,$^) $(LIBWVTEST))
160 %.a %.libs:; $(call wvlink_ar,$@,$^)
161 %.so:; $(call wvlink_so,$@,$^)
163 # Force objects to be built before final binaries
164 $(addsuffix .o,$(basename $(wildcard *.c) $(wildcard *.cc) $(wildcard *.cpp))):
166 %.gz: FORCE %
167 @rm -f $@
168 gzip -f $*
169 @ls -l $@
172 # We automatically generate header dependencies for .c and .cc files. The
173 # dependencies are stored in the file ".filename.d", and we include them
174 # automatically here if they exist.
176 -include $(shell find . -name '.*.d') /dev/null
180 # A macro for compiling subdirectories listed in the SUBDIRS variable.
181 # Tries to make the target ($@) in each subdir, unless the target is called
182 # "subdirs" in which case it makes "all" in each subdir.
184 define subdirs_func
185 +@OLDDIR="$$(pwd)"; set -e; \
186 for d in __fx__ $2; do \
187 if [ "$$d" = "__fx__" ]; then continue; fi; \
188 cd "$$d"; \
189 echo ; \
190 echo "--> Making $1 in $$(pwd)..."; \
191 $(MAKE) --no-print-directory $1 || exit 1; \
192 cd "$$OLDDIR"; \
193 done
194 @echo
195 @echo "--> Back in $$(pwd)..."
196 endef
198 subdirs = $(call subdirs_func,$(subst subdirs,all,$(if $1,$1,$@)),$(if $2,$2,$(SUBDIRS)))
200 define shell_reverse
201 revlist="" ; \
202 for word in $(1) ; do \
203 revlist="$${word} $${revlist}"; \
204 done ; \
205 echo "$${revlist}"
206 endef
207 reverse = $(shell $(call shell_reverse,$(1)))
209 clean_subdirs = $(call subdirs,clean,$(call reverse,$(SUBDIRS)),keep)
211 %: %/Makefile FORCE
212 @cd "$@"; echo; echo "--> Making all in $$(pwd)..."; \
213 $(MAKE) --no-print-directory all
215 subdirs: ${SUBDIRS}
218 # Auto-clean rule. Feel free to append to this in your own directory, by
219 # defining your own "clean" and/or "distclean" rules.
221 .PHONY: clean _wvclean
223 clean: _wvclean
225 _wvclean:
226 @echo '--> Cleaning $(shell pwd)...'
227 @rm -f *~ *.tmp *.o *.a *.so *.so.* *.libs *.dll *.lib *.moc *.d .*.d .depend \
228 .\#* .tcl_paths pkgIndex.tcl gmon.out core build-stamp \
229 CC CXX \
230 wvtestmain
231 @rm -f $(patsubst %.t.cc,%.t,$(wildcard *.t.cc) $(wildcard t/*.t.cc)) \
232 t/*.o t/*~ t/.*.d t/.\#*
233 @rm -f valgrind.log.pid*
234 @rm -f semantic.cache tags
235 @rm -rf debian/tmp
237 distclean: clean
239 dist-hook:
241 dist: dist-hook
242 @echo '--> Making dist in ../build/$(PKGDIR)...'
243 @test -d ../build || mkdir ../build
244 @rsync -a --delete --force '$(shell pwd)/' '../build/$(PKGDIR)'
245 @find '../build/$(PKGDIR)' -name .svn -type d -print0 | xargs -0 rm -rf --
246 @find '../build/$(PKGDIR)' -name .cvsignore -type f -print0 | xargs -0 rm -f --
247 @$(MAKE) -C '../build/$(PKGDIR)' distclean
248 @rm -f '../build/$(PKGDIR).tar.gz'
249 @cd ../build; tar -zcf '$(PKGDIR).tar.gz' '$(PKGDIR)'
250 @echo '--> Created tarball in ../build/$(PKGDIR).tar.gz.'