1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
|
# wvrules.mk: 2003 09 09
#
# Copyright (C) 1998-2003 by Avery Pennarun <apenwarr@worldvisions.ca>.
# Use, distribute, modify, and redistribute freely. (But if you're nice,
# you'll send all your changes back to me.)
#
# This is a complicated-looking set of Makefile rules that should make your
# own Makefiles simpler, by providing for several useful features (like
# autodependencies and a 'clean' target) without any extra effort.
#
# It will only work with GNU make.
#
# if WVSTREAMS_SRC is set assume everything else is set.
# For packages that use WvStreams use WVSTREAMS_SRC=. for distribution.
ifeq ($(WVSTREAMS_SRC),)
ifeq ($(WVSTREAMS),)
$(error The WVSTREAMS variable is not defined)
endif
WVSTREAMS_SRC=$(WVSTREAMS)
WVSTREAMS_LIB=$(WVSTREAMS)
WVSTREAMS_INC=$(WVSTREAMS)/include
WVSTREAMS_BIN=$(WVSTREAMS)
endif
export WVSTREAMS WVSTREAMS_SRC WVSTREAMS_LIB WVSTREAMS_INC WVSTREAMS_BIN
SHELL=/bin/bash
ifneq ($(wildcard $(WVSTREAMS_SRC)/config.mk),)
include $(WVSTREAMS_SRC)/config.mk
endif
ifeq (${EXEEXT},.exe)
include $(WVSTREAMS_SRC)/wvrules-win32.mk
endif
ifeq (${WVTESTRUN},)
WVTESTRUN=$(WVSTREAMS_BIN)/wvtesthelper
endif
ifneq ("$(with_xplc)", "no")
ifneq ("$(with_xplc)", "")
LDFLAGS:=-L$(with_xplc) $(LDFLAGS)
endif
LIBXPLC=-lxplc-cxx
endif
LIBWVBASE=$(WVSTREAMS_LIB)/libwvbase.so $(LIBXPLC)
LIBWVUTILS=$(WVSTREAMS_LIB)/libwvutils.so $(LIBWVBASE)
LIBWVSTREAMS=$(WVSTREAMS_LIB)/libwvstreams.so $(LIBWVUTILS)
LIBUNICONF=$(WVSTREAMS_LIB)/libuniconf.so $(LIBWVSTREAMS)
LIBWVQT=$(WVSTREAMS_LIB)/libwvqt.so $(LIBWVSTREAMS)
LIBWVTEST=$(WVSTREAMS_LIB)/libwvtest.a $(LIBWVUTILS)
#
# Initial C compilation flags
#
CPPFLAGS += $(CPPOPTS)
C_AND_CXX_FLAGS += -D_BSD_SOURCE -D_GNU_SOURCE $(OSDEFINE) \
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
CFLAGS += $(COPTS) $(C_AND_CXX_FLAGS)
CXXFLAGS += $(CXXOPTS) $(C_AND_CXX_FLAGS)
LDFLAGS += $(LDOPTS) -L$(WVSTREAMS_LIB)
# Default compiler we use for linking
WVLINK_CC = gcc
# FIXME: what does this do??
XX_LIBS := $(XX_LIBS) $(shell $(CC) -lsupc++ -lgcc_eh 2>&1 | grep -q "undefined reference" && echo " -lsupc++ -lgcc_eh")
ifeq ("$(enable_debug)", "yes")
DEBUG:=1
else
DEBUG:=0
endif
ifeq ("$(enable_fatal_warnings)", "yes")
CXXFLAGS+=-Werror
# FIXME: not for C, because our only C file, crypto/wvsslhack.c, has
# a few warnings on purpose.
#CFLAGS+=-Werror
endif
ifneq ("$(enable_optimization)", "no")
CXXFLAGS+=-O2
#CXXFLAGS+=-felide-constructors
CFLAGS+=-O2
endif
ifneq ("$(enable_warnings)", "no")
CXXFLAGS+=-Wall -Woverloaded-virtual
CFLAGS+=-Wall
endif
ifneq ("$(enable_rtti)", "yes")
CXXFLAGS+=-fno-rtti
endif
ifneq ("$(enable_exceptions)", "yes")
CXXFLAGS+=-fno-exceptions
endif
ifeq ("$(enable_efence)", "yes")
EFENCE:=-lefence
USE_EFENCE:=1
endif
ifeq (USE_EFENCE,1)
LDLIBS+=$(EFENCE)
endif
ifeq ("$(enable_verbose)", "yes")
VERBOSE:=1
endif
ifdef DONT_LIE
VERBOSE:=1 $(warning DONT_LIE is deprecated, use VERBOSE instead)
endif
STRIP=strip --remove-section=.note --remove-section=.comment
#STRIP=echo
# macros that expand to the object files in the given directories
objects=$(sort $(foreach type,c cc,$(call objects_$(type),$1)))
objects_c=$(patsubst %.c,%.o,$(wildcard $(addsuffix /*.c,$1)))
objects_cc=$(patsubst %.cc,%.o,$(wildcard $(addsuffix /*.cc,$1)))
# macro that expands to the subdir.mk files to include
xsubdirs=$(sort $(wildcard $1/*/subdir.mk)) /dev/null
# we need a default rule, since the 'includes' below causes trouble
.PHONY: default all
default: all
# default "test" rule does nothing...
.PHONY: test runtests clean-valgrind
test:
runtests: clean-valgrind
clean-valgrind:
@rm -f valgrind.log.pid*
%/test:
$(MAKE) -C $(dir $@) test
$(LIBXPLC):
$(WVSTREAMS_SRC)/rules.local.mk:
@true
-include $(WVSTREAMS_SRC)/rules.local.mk
#
# Figure out which OS we're running (for now, only picks out Linux or BSD)
#
OS:=$(shell uname -a | awk '{print $$1}' | sed -e 's/^.*BSD/BSD/g' )
#
# (Just BSD and LINUX clash with other symbols, so use ISLINUX and ISBSD)
# This sucks. Use autoconf for most things!
#
ifeq ($(OS),Linux)
OSDEFINE:=-DISLINUX
endif
ifeq ($(OS),BSD)
OSDEFINE:=-DISBSD
endif
ifeq ($(CCMALLOC),1)
ifeq ($(DEBUG),1)
XX_LIBS += -lccmalloc -ldl
endif
endif
ifeq ($(DEBUG),1)
C_AND_CXX_FLAGS += -ggdb -DDEBUG=1
LDFLAGS += -ggdb
else
C_AND_CXX_FLAGS += -g -DDEBUG=0
#CFLAGS += -DNDEBUG # I don't like disabling assertions...
#CFLAGS += -fomit-frame-pointer # really evil
#CXXFLAGS += -fno-implement-inlines # causes trouble with egcs 1.0
LDFLAGS += -g
endif
ifeq ($(PROFILE),1)
CFLAGS += -pg
LDFLAGS += -pg
endif
ifeq ($(STATIC),1)
LDFLAGS += -static
endif
INCFLAGS=$(addprefix -I,$(WVSTREAMS_INC) $(XPATH))
CPPFLAGS+=$(INCFLAGS)
CFLAGS+=$(CPPFLAGS)
CXXFLAGS+=$(CPPFLAGS)
ifeq ($(VERBOSE),1)
COMPILE_MSG :=
LINK_MSG :=
DEPEND_MSG :=
SYMLINK_MSG :=
else
COMPILE_MSG = @echo compiling $@...;
LINK_MSG = @echo linking $@...;
#DEPEND_MSG = @echo " depending $@...";
DEPEND_MSG := @
SYMLINK_MSG := @
endif
# any rule that depends on FORCE will always run
.PHONY: FORCE
FORCE:
ifeq ($(LN_S),)
LN_S := ln -s
endif
ifeq ($(LN),)
LN := ln
endif
# Create symbolic links
# usage: $(wvlns,source,dest)
wvlns=$(SYMLINK_MSG)$(LN_S) -f $1 $2
# Create hard links
# usage: $(wvln,source,dest)
wvln=$(SYMLINK_MSG)$(LN) -f $1 $2
# usage: $(wvcc_base,outfile,infile,stem,compiler cflags,mode)
# eg: $(wvcc,foo.o,foo.cc,foo,$(CC) $(CFLAGS) -fPIC,-c)
DEPFILE = $(if $(filter %.o,$1),$(dir $1).$(notdir $(1:.o=.d)),/dev/null)
define wvcc_base
@rm -f "$1"
$(COMPILE_MSG)$4 $5 $2 -o $1
@# The Perl script here generates the proper dependencies, including
@# null dependencies so Make doesn't complain
$(DEPEND_MSG)$4 -M -E $< \
| perl -we \
'$$a = '"'"'$1'"'"'; \
$$\ = $$/; \
local $$/; \
while (<>) { \
for (split(/(?<!\\)$$/m)) { \
s/^[^:]+:\s*/$$a: /; \
print; \
if (s/^$$a: //) { \
map {print "$$_:" unless m/^\\$$/} (split(/\s+/));\
} \
} \
}' >$(DEPFILE)
endef
wvcc=$(call wvcc_base,$1,$2,$3,$(CC) $(CFLAGS) $($1-CPPFLAGS) $($1-CFLAGS) $4,$(if $5,$5,-c))
wvcxx=$(call wvcc_base,$1,$2,$3,$(CXX) $(CFLAGS) $(CXXFLAGS) $($1-CPPFLAGS) $($1-CFLAGS) $($1-CXXFLAGS) $4,$(if $5,$5,-c))
define wvlink_ar
$(LINK_MSG)set -e; rm -f $1 $(patsubst %.a,%.libs,$1); \
echo $2 >$(patsubst %.a,%.libs,$1); \
$(AR) q $1 $(filter %.o,$2); \
for d in "" $(filter %.libs,$2); do \
if [ "$$d" != "" ]; then \
cd $$(dirname "$$d"); \
$(AR) q $(shell pwd)/$1 $$(cat $$(basename $$d)); \
cd $(shell pwd); \
fi; \
done; \
$(AR) s $1
endef
%.so: SONAME=$@$(if $(SO_VERSION),.$(SO_VERSION))
wvsoname=$(if $($1-SONAME),$($1-SONAME),$(if $(SONAME),$(SONAME),$1))
define wvlink_so
$(LINK_MSG)$(WVLINK_CC) $(LDFLAGS) $($1-LDFLAGS) -Wl,-soname,$(call wvsoname,$1) -shared -o $1 $(filter %.o %.a %.so,$2) $($1-LIBS) $(LIBS) $(XX_LIBS)
$(if $(filter-out $(call wvsoname,$1),$1),$(call wvlns,$1,$(call wvsoname,$1)))
endef
wvlink=$(LINK_MSG)$(CC) $(LDFLAGS) $($1-LDFLAGS) -o $1 $(filter %.o %.a %.so, $2) $($1-LIBS) $(LIBS) $(XX_LIBS) $(LDLIBS)
../%.so:; @echo "Shared library $@ does not exist!"; exit 1
../%.a:; @echo "Library $@ does not exist!"; exit 1
../%.o:; @echo "Object $@ does not exist!"; exit 1
/%.a:; @echo "Library $@ does not exist!"; exit 1
%.o: %.c; $(call wvcc ,$@,$<,$*)
%.fpic.o: %.c; $(call wvcc ,$@,$<,$*,-fPIC)
%.o: %.cc; $(call wvcxx,$@,$<,$*)
%.fpic.o: %.cc; $(call wvcxx,$@,$<,$*,-fPIC)
%.o: %.cpp; $(call wvcxx,$@,$<,$*)
%.fpic.o:%.cpp; $(call wvcxx,$@,$<,$*,-fPIC)
%.s: %.c; $(call wvcc ,$@,$<,$*,,-S)
%.s: %.cc; $(call wvcxx,$@,$<,$*,,-S)
%.s: %.cpp; $(call wvcxx,$@,$<,$*,,-S)
%.E: %.c; $(call wvcc,$@,$<,$*,,-E)
%.E: %.cc; $(call wvcxx,$@,$<,$*,,-E)
%.E: %.cpp; $(call wvcxx,$@,$<,$*,,-E)
%.moc: %.h; moc -o $@ $<
%: %.o; $(call wvlink,$@,$^)
%.t: %.t.o; $(call wvlink,$@,$(call reverse,$(filter %.o,$^)) $(filter-out %.o,$^) $(LIBWVTEST))
%.a %.libs:; $(call wvlink_ar,$@,$^)
%.so:; $(call wvlink_so,$@,$^)
# Force objects to be built before final binaries
$(addsuffix .o,$(basename $(wildcard *.c) $(wildcard *.cc) $(wildcard *.cpp))):
%.gz: FORCE %
@rm -f $@
gzip -f $*
@ls -l $@
#
# Header files for tcl/tk packages
#
pkgIndex.tcl: $(filter-out pkgIndex.tcl,$(wildcard *.tcl))
@echo Generating pkgIndex.tcl...
@rm -f $@
@echo pkg_mkIndex . \
$$(echo $^ | sed 's,\.tcl_paths,,') | tclsh
pkgIndex.tcl $(wildcard *.tcl): .tcl_paths
.tcl_paths:
@echo Generating .tcl_paths...
@rm -f $@
@find . $(TOPDIR) -name '*.tcl' -printf '%h\n' | sort | uniq | \
(echo lappend auto_path \\; sed 's/^.*$$/ & \\/'; echo) >$@.tmp
@mv $@.tmp $@
#
# We automatically generate header dependencies for .c and .cc files. The
# dependencies are stored in the file ".filename.d"
#
depfiles_sf = $(wildcard .*.d t/.*.d)
ifneq ($(depfiles_sf),)
-include $(depfiles_sf)
endif
#
# A macro for compiling subdirectories listed in the SUBDIRS variable.
# Tries to make the target ($@) in each subdir, unless the target is called
# "subdirs" in which case it makes "all" in each subdir.
#
define subdirs_func
+@OLDDIR="$$(pwd)"; set -e; \
for d in __fx__ $2; do \
if [ "$$d" = "__fx__" ]; then continue; fi; \
cd "$$d"; \
echo ; \
echo "--> Making $1 in $$(pwd)..."; \
$(MAKE) --no-print-directory $1 || exit 1; \
cd "$$OLDDIR"; \
done
@echo
@echo "--> Back in $$(pwd)..."
endef
subdirs = $(call subdirs_func,$(subst subdirs,all,$(if $1,$1,$@)),$(if $2,$2,$(SUBDIRS)))
# # $(call reverse,$(SUBDIRS)) works since GNU make 3.80 only
# reverse = \
# $(if $(1),$(call reverse,$(wordlist 2, 999, $(1))) $(firstword $(1)))
define shell_reverse
revlist="" ; \
for word in $(1) ; do \
revlist="$${word} $${revlist}"; \
done ; \
echo "$${revlist}"
endef
reverse = $(shell $(call shell_reverse,$(1)))
clean_subdirs = $(call subdirs,clean,$(call reverse,$(SUBDIRS)),keep)
%: %/Makefile FORCE
@cd "$@"; echo; echo "--> Making all in $$(pwd)..."; \
$(MAKE) --no-print-directory all
subdirs: ${SUBDIRS}
#
# Auto-clean rule. Feel free to append to this in your own directory, by
# defining your own "clean" rule.
#
.PHONY: clean _wvclean
clean: _wvclean
_wvclean:
@echo '--> Cleaning $(shell pwd)...'
@rm -f *~ *.tmp *.o *.a *.so *.so.* *.libs *.moc *.d .*.d .depend \
.\#* .tcl_paths pkgIndex.tcl gmon.out core build-stamp \
wvtestmain
@rm -f $(patsubst %.t.cc,%.t,$(wildcard *.t.cc) $(wildcard t/*.t.cc)) \
t/*.o t/*~ t/.*.d t/.\#*
@rm -f valgrind.log.pid*
@rm -f semantic.cache tags
@rm -rf debian/tmp
#
# default dist rules.
distclean: clean
PKGNAME := $(notdir $(shell pwd))
PPKGNAME := $(shell echo $(PKGNAME) | tr a-z A-Z | tr - _)
PKGVER := $(shell test -f wvver.h \
&& cat wvver.h | sed -ne "s/\#define $(PPKGNAME)_VER_STRING.*\"\([^ ]*\).*\".*/\1/p")
ifneq ($(PKGVER),)
PKGDIR := $(PKGNAME)-$(PKGVER)
else
PKGDIR := $(PKGNAME)
endif
ifneq ($(PKGSNAPSHOT),)
PKGDIR := $(PKGDIR)+$(shell date +%Y%m%d)
endif
dist-dir:
@echo $(PKGDIR)
dist-hook:
dist: dist-hook ChangeLog
@echo '--> Making dist in ../build/$(PKGDIR)...'
@test -d ../build || mkdir ../build
@rsync -a --delete --force '$(shell pwd)/' '../build/$(PKGDIR)'
@find '../build/$(PKGDIR)' -name .svn -type d -print0 | xargs -0 rm -rf --
@find '../build/$(PKGDIR)' -name .cvsignore -type f -print0 | xargs -0 rm -f --
@$(MAKE) -C '../build/$(PKGDIR)' distclean
@rm -f '../build/$(PKGDIR).tar.gz'
@cd ../build; tar -zcf '$(PKGDIR).tar.gz' '$(PKGDIR)'
@echo '--> Created tarball in ../build/$(PKGDIR).tar.gz.'
ChangeLog: FORCE
@echo '--> Generating ChangeLog from Subversion...'
@rm -f ChangeLog ChangeLog.bak
@svn log --xml --verbose | xsltproc svn2cl.xsl - > ChangeLog
#
# Make 'tags' file using the ctags program - useful for editing
#
#tags: $(shell find -name '*.cc' -o -name '*.[ch]')
# @echo '(creating "tags")'
# @if [ -x /usr/bin/ctags ]; then /usr/bin/ctags $^; fi
|