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
38 ifeq ($(wildcard $(WVSTREAMS_SRC
)/config.mk
),)
39 __junk
:=$(shell echo
"Warning: $(WVSTREAMS_SRC)/config.mk doesn't exist" >&2)
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
++
53 include $(WVSTREAMS_SRC
)/wvrules-
$(COMPILER_STANDARD
).mk
56 WVTESTRUN
=$(WVSTREAMS_BIN
)/wvtestrunner.pl
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...
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
87 COMPILE_MSG
= @echo compiling
$@...
;
88 LINK_MSG
= @echo linking
$@...
;
89 #DEPEND_MSG = @echo " depending $@...";
94 # any rule that depends on FORCE will always run
105 # Create symbolic links
106 # usage: $(wvlns,source,dest)
107 wvlns
=$(SYMLINK_MSG
)$(LN_S
) -f
$1 $2
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)
117 .
/CC
$(if
$5,$5,-c
) $3 $($1-CFLAGS
) $($1-CPPFLAGS
) $4
121 .
/CXX
$(if
$5,$5,-c
) $3 $($1-CXXFLAGS
) $($1-CPPFLAGS
) $4
124 %.so
: SONAME
=$@
$(if
$(SO_VERSION
),.
$(SO_VERSION
))
126 wvsoname
=$(if
$($1-SONAME
),$($1-SONAME
),$(if
$(SONAME
),$(SONAME
),$1))
129 @echo
"Skipping $@ on win32 (can't build shared libraries)"
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)))
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))):
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.
185 +@OLDDIR
="$$(pwd)"; set
-e
; \
186 for d in __fx__
$2; do \
187 if
[ "$$d" = "__fx__" ]; then continue
; fi
; \
190 echo
"--> Making $1 in $$(pwd)..."; \
191 $(MAKE
) --no-print-directory
$1 || exit
1; \
195 @echo
"--> Back in $$(pwd)..."
198 subdirs
= $(call subdirs_func
,$(subst subdirs
,all,$(if
$1,$1,$@
)),$(if
$2,$2,$(SUBDIRS
)))
202 for
word in
$(1) ; do \
203 revlist
="$${word} $${revlist}"; \
207 reverse
= $(shell $(call shell_reverse
,$(1)))
209 clean_subdirs
= $(call subdirs
,clean,$(call reverse
,$(SUBDIRS
)),keep
)
212 @cd
"$@"; echo
; echo
"--> Making all in $$(pwd)..."; \
213 $(MAKE
) --no-print-directory
all
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
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 \
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
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.'