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
19 # if WVSTREAMS_SRC is set assume everything else is set.
20 # For packages that use WvStreams use WVSTREAMS_SRC=. for distribution.
22 WVSTREAMS_SRC
=$(WVSTREAMS
)
23 WVSTREAMS_LIB
=$(WVSTREAMS
)
24 WVSTREAMS_INC
=$(WVSTREAMS
)/include
25 WVSTREAMS_BIN
=$(WVSTREAMS
)
27 export WVSTREAMS WVSTREAMS_SRC WVSTREAMS_LIB WVSTREAMS_INC WVSTREAMS_BIN
31 include $(WVSTREAMS_SRC
)/config.defaults.mk
32 -include $(WVSTREAMS_SRC
)/config.mk
33 -include $(WVSTREAMS_SRC
)/config.overrides.mk
34 -include $(WVSTREAMS_SRC
)/local.mk
36 ifeq ($(wildcard $(WVSTREAMS_SRC
)/config.mk
),)
37 __junk
:=$(shell echo
"Warning: $(WVSTREAMS_SRC)/config.mk doesn't exist" >&2)
40 include $(WVSTREAMS_SRC
)/wvrules-
$(COMPILER_STANDARD
).mk
43 include $(WVSTREAMS_SRC
)/wvrules-win32.mk
47 WVTESTRUN
=$(WVSTREAMS_BIN
)/wvtesthelper
50 # macros that expand to the object files in the given directories
51 objects
=$(sort $(foreach type
,c
cc,$(call objects_
$(type
),$1)))
52 objects_c
=$(patsubst %.c
,%.o
,$(wildcard $(addsuffix /*.c
,$1)))
53 objects_cc
=$(patsubst %.
cc,%.o
,$(wildcard $(addsuffix /*.
cc,$1)))
55 # default "test" rule does nothing...
61 $(MAKE
) -C
$(dir $@
) test
63 INCFLAGS
=$(addprefix -I
,$(WVSTREAMS_INC
) $(XPATH
))
64 CPPFLAGS
+=$(INCFLAGS
) \
65 -D_BSD_SOURCE
-D_GNU_SOURCE
$(OSDEFINE
) \
66 -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS
=64
74 COMPILE_MSG
= @echo compiling
$@...
;
75 LINK_MSG
= @echo linking
$@...
;
76 #DEPEND_MSG = @echo " depending $@...";
81 # any rule that depends on FORCE will always run
92 # Create symbolic links
93 # usage: $(wvlns,source,dest)
94 wvlns
=$(SYMLINK_MSG
)$(LN_S
) -f
$1 $2
97 # usage: $(wvln,source,dest)
98 wvln
=$(SYMLINK_MSG
)$(LN
) -f
$1 $2
100 # usage: $(wvcc_base,outfile,infile,stem,compiler cflags,mode)
101 # eg: $(wvcc,foo.o,foo.cc,foo,$(CC) $(CFLAGS) -fPIC,-c)
102 DEPFILE
= $(if
$(filter %.o
,$1),$(dir $1).
$(notdir $(1:.o
=.d
)),/dev
/null
)
103 wvcc
=$(call wvcc_base
,$1,$2,$3,$(CC
) $(CFLAGS
) $($1-CFLAGS
) $(CPPFLAGS
) $($1-CPPFLAGS
) $4,$(if
$5,$5,-c
))
104 wvcxx
=$(call wvcc_base
,$1,$2,$3,$(CXX
) $(CXXFLAGS
) $($1-CFLAGS
) $(CPPFLAGS
) $($1-CPPFLAGS
) $($1-CXXFLAGS
) $4,$(if
$5,$5,-c
))
106 %.so
: SONAME
=$@
$(if
$(SO_VERSION
),.
$(SO_VERSION
))
108 wvsoname
=$(if
$($1-SONAME
),$($1-SONAME
),$(if
$(SONAME
),$(SONAME
),$1))
110 $(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
)
111 $(if
$(filter-out $(call wvsoname
,$1),$1),$(call wvlns
,$1,$(call wvsoname
,$1)))
114 ..
/%.so
:; @echo
"Shared library $@ does not exist!"; exit
1
115 ..
/%.a
:; @echo
"Library $@ does not exist!"; exit
1
116 ..
/%.o
:; @echo
"Object $@ does not exist!"; exit
1
117 /%.a
:; @echo
"Library $@ does not exist!"; exit
1
119 %.o
: %.c
; $(call wvcc
,$@
,$<,$*)
120 %.fpic.o
: %.c
; $(call wvcc
,$@
,$<,$*,-fPIC
)
121 %.o
: %.
cc; $(call wvcxx
,$@
,$<,$*)
122 %.fpic.o
: %.
cc; $(call wvcxx
,$@
,$<,$*,-fPIC
)
123 %.o
: %.
cpp; $(call wvcxx
,$@
,$<,$*)
124 %.fpic.o
:%.
cpp; $(call wvcxx
,$@
,$<,$*,-fPIC
)
125 %.s
: %.c
; $(call wvcc
,$@
,$<,$*,,-S
)
126 %.s
: %.
cc; $(call wvcxx
,$@
,$<,$*,,-S
)
127 %.s
: %.
cpp; $(call wvcxx
,$@
,$<,$*,,-S
)
128 %.E
: %.c
; $(call wvcc
,$@
,$<,$*,,-E
)
129 %.E
: %.
cc; $(call wvcxx
,$@
,$<,$*,,-E
)
130 %.E
: %.
cpp; $(call wvcxx
,$@
,$<,$*,,-E
)
132 %.moc
: %.h
; moc
-o
$@
$<
134 %: %.o
; $(call wvlink
,$@
,$^
)
135 %.t
: %.t.o
; $(call wvlink
,$@
,$(call reverse
,$(filter %.o
,$^
)) $(filter-out %.o
,$^
) $(LIBWVTEST
))
136 %.a
%.libs
:; $(call wvlink_ar
,$@
,$^
)
137 %.so
:; $(call wvlink_so
,$@
,$^
)
139 # Force objects to be built before final binaries
140 $(addsuffix .o
,$(basename $(wildcard *.c
) $(wildcard *.
cc) $(wildcard *.
cpp))):
148 # We automatically generate header dependencies for .c and .cc files. The
149 # dependencies are stored in the file ".filename.d", and we include them
150 # automatically here if they exist.
152 depfiles_sf
= $(wildcard .
*.d t
/.
*.d
)
153 ifneq ($(depfiles_sf
),)
154 -include $(depfiles_sf
)
159 # A macro for compiling subdirectories listed in the SUBDIRS variable.
160 # Tries to make the target ($@) in each subdir, unless the target is called
161 # "subdirs" in which case it makes "all" in each subdir.
164 +@OLDDIR
="$$(pwd)"; set
-e
; \
165 for d in __fx__
$2; do \
166 if
[ "$$d" = "__fx__" ]; then continue
; fi
; \
169 echo
"--> Making $1 in $$(pwd)..."; \
170 $(MAKE
) --no-print-directory
$1 || exit
1; \
174 @echo
"--> Back in $$(pwd)..."
177 subdirs
= $(call subdirs_func
,$(subst subdirs
,all,$(if
$1,$1,$@
)),$(if
$2,$2,$(SUBDIRS
)))
181 for
word in
$(1) ; do \
182 revlist
="$${word} $${revlist}"; \
186 reverse
= $(shell $(call shell_reverse
,$(1)))
188 clean_subdirs
= $(call subdirs
,clean,$(call reverse
,$(SUBDIRS
)),keep
)
191 @cd
"$@"; echo
; echo
"--> Making all in $$(pwd)..."; \
192 $(MAKE
) --no-print-directory
all
197 # Auto-clean rule. Feel free to append to this in your own directory, by
198 # defining your own "clean" and/or "distclean" rules.
200 .PHONY
: clean _wvclean
205 @echo
'--> Cleaning $(shell pwd)...'
206 @
rm -f
*~
*.tmp
*.o
*.a
*.so
*.so.
* *.libs
*.dll
*.lib
*.moc
*.d .
*.d .depend \
207 .\
#* .tcl_paths pkgIndex.tcl gmon.out core build-stamp \
209 @
rm -f
$(patsubst %.t.
cc,%.t
,$(wildcard *.t.
cc) $(wildcard t
/*.t.
cc)) \
210 t
/*.o t
/*~ t
/.
*.d t
/.\
#*
211 @
rm -f valgrind.log.pid
*
212 @
rm -f semantic.cache
tags
220 @echo
'--> Making dist in ../build/$(PKGDIR)...'
221 @
test -d ..
/build || mkdir ..
/build
222 @rsync
-a
--delete
--force '$(shell pwd)/' '../build/$(PKGDIR)'
223 @find
'../build/$(PKGDIR)' -name .svn
-type d
-print0 | xargs
-0 rm -rf
--
224 @find
'../build/$(PKGDIR)' -name .cvsignore
-type f
-print0 | xargs
-0 rm -f
--
225 @
$(MAKE
) -C
'../build/$(PKGDIR)' distclean
226 @
rm -f
'../build/$(PKGDIR).tar.gz'
227 @cd ..
/build
; tar -zcf
'$(PKGDIR).tar.gz' '$(PKGDIR)'
228 @echo
'--> Created tarball in ../build/$(PKGDIR).tar.gz.'