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
),)
18 $(error The WVSTREAMS variable is not defined
)
20 WVSTREAMS_SRC
=$(WVSTREAMS
)
21 WVSTREAMS_LIB
=$(WVSTREAMS
)
22 WVSTREAMS_INC
=$(WVSTREAMS
)/include
23 WVSTREAMS_BIN
=$(WVSTREAMS
)
25 export WVSTREAMS WVSTREAMS_SRC WVSTREAMS_LIB WVSTREAMS_INC WVSTREAMS_BIN
30 WVTESTRUN
=$(WVSTREAMS_BIN
)/wvtesthelper
33 #ifneq "$(filter-out $(NO_CONFIGURE_TARGETS),$(if $(MAKECMDGOALS),$(MAKECMDGOALS),default))" ""
37 ifneq ($(wildcard $(WVSTREAMS_SRC
)/config.mk
),)
38 include $(WVSTREAMS_SRC
)/config.mk
41 ifneq ("$(with_xplc)", "no")
42 LDFLAGS
+=-L
$(with_xplc
)
43 LIBXPLC
=-lxplc-cxx
-lxplc
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")
72 ifeq ("$(enable_fatal_warnings)", "yes")
74 # FIXME: not for C, because our only C file, crypto/wvsslhack.c, has
75 # a few warnings on purpose.
79 ifneq ("$(enable_optimization)", "no")
81 #CXXFLAGS+=-felide-constructors
85 ifneq ("$(enable_warnings)", "no")
86 CXXFLAGS
+=-Wall
-Woverloaded-virtual
90 ifneq ("$(enable_rtti)", "yes")
94 ifneq ("$(enable_exceptions)", "yes")
95 CXXFLAGS
+=-fno-exceptions
98 ifeq ("$(enable_efence)", "yes")
107 ifeq ("$(enable_verbose)", "yes")
112 VERBOSE
:=1 $(warning DONT_LIE is deprecated
, use VERBOSE instead
)
115 STRIP
=strip --remove-section
=.note
--remove-section
=.comment
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
130 # default "test" rule does nothing...
131 .PHONY
: test runtests
136 $(MAKE
) -C
$(dir $@
) test
138 $(WVSTREAMS_SRC
)/rules.local.mk
:
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!
162 XX_LIBS
+= -lccmalloc
-ldl
167 C_AND_CXX_FLAGS
+= -ggdb
-DDEBUG
=1
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
186 INCFLAGS
=$(addprefix -I
,$(WVSTREAMS_INC
) $(XPATH
))
187 CPPFLAGS
+=$(INCFLAGS
)
189 CXXFLAGS
+=$(CPPFLAGS
)
196 COMPILE_MSG
= @echo compiling
$@...
;
197 LINK_MSG
= @echo linking
$@...
;
198 #DEPEND_MSG = @echo " depending $@...";
202 # any rule that depends on FORCE will always run
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
)
211 $(COMPILE_MSG
)$4 $5 $2 -o
$1
212 $(DEPEND_MSG
)$4 -M
-E
$< \
213 | sed
-e
's|^[^:]*:|$1:|' >$(DEPFILE
)
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
))
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)); \
229 wvsoname
=$(if
$($1-SONAME
),$($1-SONAME
),$(if
$(SONAME
),$(SONAME
),$1))
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))
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))):
271 # Header files for tcl/tk packages
273 pkgIndex.tcl
: $(filter-out pkgIndex.tcl
,$(wildcard *.tcl
))
274 @echo Generating pkgIndex.tcl...
276 @echo pkg_mkIndex . \
277 $$(echo
$^ | sed
's,\.tcl_paths,,') | tclsh
279 pkgIndex.tcl
$(wildcard *.tcl
): .tcl_paths
281 @echo Generating .tcl_paths...
283 @find .
$(TOPDIR
) -name
'*.tcl' -printf
'%h\n' |
sort | uniq | \
284 (echo lappend auto_path
\\; sed
's/^.*$$/ & \\/'; echo
) >$@.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
)
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.
304 +@OLDDIR
="$$(pwd)"; set
-e
; \
305 for d in __fx__
$2; do \
306 if
[ "$$d" = "__fx__" ]; then continue
; fi
; \
309 echo
"--> Making $1 in $$(pwd)..."; \
310 $(MAKE
) --no-print-directory
$1 || exit
1; \
314 @echo
"--> Back in $$(pwd)..."
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
321 # $(if $(1),$(call reverse,$(wordlist 2, 999, $(1))) $(firstword $(1)))
325 for
word in
$(1) ; do \
326 revlist
="$${word} $${revlist}"; \
331 reverse
= $(shell $(call shell_reverse
,$(1)))
333 clean_subdirs
= $(call subdirs
,clean,$(call reverse
,$(SUBDIRS
)),keep
)
336 @cd
"$@"; echo
; echo
"--> Making all in $$(pwd)..."; \
337 $(MAKE
) --no-print-directory
all
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
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
/.\
#*
355 # default dist rules.
358 dist: distclean ChangeLog
361 rm -f ChangeLog ChangeLog.bak
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