3 # Copyright (C) 1998-2007 by Avery Pennarun <apenwarr@alumnit.ca>
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
21 # if WVSTREAMS_SRC is set assume everything else is set.
22 # For packages that use WvStreams use WVSTREAMS_SRC=. for distribution.
24 WVSTREAMS_SRC
=$(WVSTREAMS
)
25 WVSTREAMS_LIB
=$(WVSTREAMS
)
26 WVSTREAMS_INC
=$(WVSTREAMS
)/include
27 WVSTREAMS_BIN
=$(WVSTREAMS
)
29 export WVSTREAMS WVSTREAMS_SRC WVSTREAMS_LIB WVSTREAMS_INC WVSTREAMS_BIN
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
52 XPATH
+= $(WVSTREAMS
)/win32
$(WVSTREAMS
)/win32
/cominclude
53 AR
=i586-mingw32msvc-ar
54 LIBS
+= -lssl
-lcrypto
-lz
-lole32
-lrpcrt4
-lwsock32
-lgdi32
-limagehlp \
61 include $(WVSTREAMS_SRC
)/wvrules-
$(COMPILER_STANDARD
).mk
64 WVTESTRUN
=$(WVSTREAMS_BIN
)/wvtestrun
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...
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 \
96 COMPILE_MSG
= @echo compiling
$@...
;
97 LINK_MSG
= @echo linking
$@...
;
98 #DEPEND_MSG = @echo " depending $@...";
103 # any rule that depends on FORCE will always run
114 # Create symbolic links
115 # usage: $(wvlns,source,dest)
116 wvlns
=$(SYMLINK_MSG
)$(LN_S
) -f
$1 $2
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)
126 .
/CC
$(if
$5,$5,-c
) $3 $($1-CFLAGS
) $($1-CPPFLAGS
) $4
130 .
/CXX
$(if
$5,$5,-c
) $3 $($1-CXXFLAGS
) $($1-CPPFLAGS
) $4
133 %.so
: SONAME
=$@
$(if
$(SO_VERSION
),.
$(SO_VERSION
))
135 wvsoname
=$(if
$($1-SONAME
),$($1-SONAME
),$(if
$(SONAME
),$(SONAME
),$1))
139 @echo
"Skipping $@ on win32 (can't build shared libraries)"
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
)
149 $(LINK_MSG
)$(WVLINK_CC
) $(LDFLAGS
) $($1-LDFLAGS
) -dynamiclib
-o
$1 $(filter %.o
%.a
%.so
,$2) $($1-LIBS
) $(LIBS
) $(XX_LIBS
)
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)))
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))):
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.
205 +@OLDDIR
="$$(pwd)"; set
-e
; \
206 for d in __fx__
$2; do \
207 if
[ "$$d" = "__fx__" ]; then continue
; fi
; \
210 echo
"--> Making $1 in $$(pwd)..."; \
211 $(MAKE
) --no-print-directory
$1 || exit
1; \
215 @echo
"--> Back in $$(pwd)..."
218 subdirs
= $(call subdirs_func
,$(subst subdirs
,all,$(if
$1,$1,$@
)),$(if
$2,$2,$(SUBDIRS
)))
222 for
word in
$(1) ; do \
223 revlist
="$${word} $${revlist}"; \
227 reverse
= $(shell $(call shell_reverse
,$(1)))
229 clean_subdirs
= $(call subdirs
,clean,$(call reverse
,$(SUBDIRS
)),keep
)
232 @cd
"$@"; echo
; echo
"--> Making all in $$(pwd)..."; \
233 $(MAKE
) --no-print-directory
all
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
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 \
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
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.'