]> mj.ucw.cz Git - libucw.git/commitdiff
Split the top-level Makefile to three parts.
authorMartin Mares <mj@ucw.cz>
Wed, 18 Jul 2007 14:20:58 +0000 (16:20 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 18 Jul 2007 14:20:58 +0000 (16:20 +0200)
Maketop and Makebottom contain the generic parts, which are useful for
other projects as well, while Makefile includes them and contains the
parts specific for Sherlock.

build/Makebottom [new file with mode: 0644]
build/Maketop [new file with mode: 0644]

diff --git a/build/Makebottom b/build/Makebottom
new file mode 100644 (file)
index 0000000..b15ce14
--- /dev/null
@@ -0,0 +1,193 @@
+# Bottom part of Makefile for the UCW Libraries
+# (c) 1997--2007 Martin Mares <mj@ucw.cz>
+
+# The run tree
+
+runtree: run/.tree-stamp $(addsuffix /.dir-stamp,$(addprefix $(o)/,$(DIRS)))
+
+run/.tree-stamp: $(o)/config.mk
+       $(M)Creating runtree
+       $(Q)mkdir -p run $(addprefix run/, cf $(EXTRA_RUNDIRS) $(INSTALL_RUNDIRS))
+       $(Q)touch run/.tree-stamp
+
+# Miscellaneous targets
+
+programs: $(PROGS)
+datafiles: $(DATAFILES)
+tests: $(TESTS)
+configs: $(addprefix run/cf/,$(CONFIGS))
+
+tags:
+       etags `find . -name "*.[ch]"`
+
+# Black magic with dependencies. It would be more correct to make "depend.new"
+# a prerequisite for "depend", but "depend.new" often has the same timestamp
+# as "depend" which would confuse make a lot and either force remaking anyway
+# or (as in current versions of GNU make) erroneously skipping the remaking.
+
+-include $(o)/depend
+
+$(o)/depend: force
+       $(Q)if [ -s $(o)/depend.new ] ; then $(s)/build/mergedeps $(o)/depend $(o)/depend.new ; >$(o)/depend.new ; fi
+
+force:
+
+# Rules for directories
+
+%.dir-stamp:
+       $(Q)mkdir -p $(@D) && touch $@
+
+# Rules for configuration files
+
+run/cf/%: custom/cf/% $(o)/config.mk $(s)/build/genconf
+       $(M)CF $<
+       $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
+
+run/cf/%: $(s)/cf/% $(o)/config.mk $(s)/build/genconf
+       $(M)CF $<
+       $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
+
+# Rules for libraries
+
+%.a:
+       $(M)AR $@
+       $(Q)rm -f $@
+       $(Q)ar rcs $@ $^
+ifdef CONFIG_INSTALL_API
+       $(Q)$(call symlink,$@,run/lib)
+endif
+
+%.so:
+       $(M)LD $@
+       $(Q)$(CC) $(LSHARED) $(LDFLAGS) -o $@ $^
+       $(Q)$(call symlink,$@,run/lib)
+
+$(o)/%.pc: $(s)/%.pc $(o)/%.$(LS)
+       $(M)PC $<
+       $(Q)DEPS="$(shell $(s)/build/lib-deps $^)" LIBDIR=$(@D) $(s)/build/genconf $< $@ $(o)/config.mk
+       $(Q)mkdir -p $(o)/pkgconfig
+       $(Q)$(call symlink,$@,$(o)/pkgconfig)
+
+# Rules for public API
+
+ifdef CONFIG_INSTALL_API
+
+API_ROOT:=$(shell cd run && pwd)
+INSTALL_RUNDIRS+=include lib/pkgconfig
+api: $(API_INCLUDES) $(addprefix run/lib/pkgconfig/,$(addsuffix .pc,$(API_LIBS)))
+
+$(o)/%/.include-stamp:
+       $(Q)$(s)/build/install-includes $(<D) run/include/$(IDST) $(?F)
+       $(Q)touch $@
+
+run/lib/pkgconfig/%.pc: $(o)/pkgconfig/%.pc
+       $(M)PC $@
+       $(Q)sed <$< >$@ "s@^libdir=.*@libdir=$(API_ROOT)/lib@;s@^incdir=.*@incdir=$(API_ROOT)/include@"
+
+else
+api:
+endif
+
+# Rules for compiling C
+
+$(o)/%.o: $(s)/%.c $(o)/lib/autoconf.h
+       $(M)CC $<
+       $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
+
+$(o)/%.o: %.c $(o)/lib/autoconf.h
+       $(M)CC $<
+       $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
+
+%.o: %.c $(o)/lib/autoconf.h
+       $(M)CC $<
+       $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
+
+$(o)/%.oo: $(s)/%.c $(o)/lib/autoconf.h
+       $(M)CC-SO $<
+       $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
+
+$(o)/%.oo: %.c $(o)/lib/autoconf.h
+       $(M)CC-SO $<
+       $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
+
+%.oo: %.c $(o)/lib/autoconf.h
+       $(M)CC-SO $<
+       $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
+
+$(o)/%-tt.o: $(s)/%.c $(o)/lib/autoconf.h
+       $(M)CC-TEST $<
+       $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -DTEST -c -o $@ $<
+
+# Rules for testing
+
+$(o)/%-t: $(o)/%-tt.o $(LIBSH)
+       $(M)LD-TEST $@
+       $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(shell $(s)/build/lib-flags $^) $(LIBS)
+
+$(o)/%.test: $(s)/%.t $(s)/build/tester
+       $(M)TEST $@
+       $(Q)$(s)/build/tester $< && touch $@
+
+# Rules for binaries
+
+BINDIR=bin
+
+$(o)/%: $(o)/%.o
+       $(M)LD $@
+       $(Q)$(CC) $(LDFLAGS) -o $@ $(shell $(s)/build/lib-flags $^) $(LIBS)
+       $(Q)$(call symlink,$@,run/$(BINDIR))
+
+$(o)/%: $(s)/%.sh $(o)/config.mk $(s)/build/genconf
+       $(M)PP $<
+       $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
+       $(Q)chmod +x $@
+       $(Q)$(call symlink,$@,run/$(BINDIR))
+
+$(o)/%: %.sh $(o)/config.mk $(s)/build/genconf
+       $(M)PP $<
+       $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
+       $(Q)chmod +x $@
+       $(Q)$(call symlink,$@,run/$(BINDIR))
+
+$(o)/%: $(s)/%.pl $(o)/config.mk $(s)/build/genconf
+       $(M)PP $<
+       $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
+       $(Q)chmod +x $@
+       $(Q)$(call symlink,$@,run/$(BINDIR))
+
+$(o)/%: %.pl $(o)/config.mk $(s)/build/genconf
+       $(M)PP $<
+       $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
+       $(Q)chmod +x $@
+       $(Q)$(call symlink,$@,run/$(BINDIR))
+
+$(o)/%.pm: $(s)/%.pm
+       $(M)PM $<
+       $(Q)cp $^ $@
+       $(Q)$(call symlink,$@,run/lib/perl5/Sherlock)
+
+$(o)/%.pm: %.pm
+       $(M)PM $<
+       $(Q)cp $^ $@
+       $(Q)$(call symlink,$@,run/lib/perl5/Sherlock)
+
+# Rules for data files
+
+DATADIR=lib
+
+$(DATAFILES): $(o)/%: $(s)/%
+       $(M)DATA $<
+       $(Q)cp $^ $@
+       $(Q)$(call symlink,$@,run/$(DATADIR))
+
+# Default installation target
+
+default-install:
+       SH_EXTRA_RUNDIRS="$(sort $(EXTRA_RUNDIRS))" SH_INSTALL_RUNDIRS="$(sort $(INSTALL_RUNDIRS))" SH_CONFIGS="$(sort $(CONFIGS))" $(s)/build/installer $(INSTALL_DIR)
+
+# Don't delete intermediate targets. There shouldn't be any, but due to bugs
+# in GNU Make rules with targets in not-yet-existing directories are ignored
+# when searching for implicit rules and thence targets considered intermediate.
+.SECONDARY:
+
+.PHONY: all clean distclean runtree programs api datafiles force tags configs dust install default-install
diff --git a/build/Maketop b/build/Maketop
new file mode 100644 (file)
index 0000000..6a7f121
--- /dev/null
@@ -0,0 +1,78 @@
+# Top part of Makefile for the UCW Libraries
+# (c) 1997--2007 Martin Mares <mj@ucw.cz>
+
+# Set to 1 if you want verbose output
+V=0
+
+# Disable all built-in rules and variables. Speeds up make and simplifies debugging.
+MAKEFLAGS+=-rR
+
+s=$(SRCDIR)
+o=obj
+
+CFLAGS=$(CLANG) $(COPT) $(CDEBUG) $(CWARNS) -I. -I$(o) -I$(s)
+LDFLAGS=$(LOPT)
+
+DIRS=
+PROGS=
+CONFIGS=
+TESTS=
+EXTRA_RUNDIRS=
+INSTALL_RUNDIRS=
+API_INCLUDES=
+API_LIBS=
+
+# Various files whose type does not fit into PROGS
+DATAFILES=
+
+ifdef CONFIG_SHARED
+LS=so
+OS=oo
+else
+LS=a
+OS=o
+endif
+
+ifdef CONFIG_DARWIN
+SOEXT=bundle
+else
+SOEXT=so
+endif
+
+# Whenever "make -s" (silent) is run, turn on verbose mode (paradoxical, but gives the right result)
+ifneq ($(findstring s,$(MAKEFLAGS)),)
+V=1
+endif
+
+# Define M (message) and Q (quiet command prefix) macros and also MAKESILENT passed to sub-makes
+ifeq ($(V),1)
+M=@\#
+Q=
+MAKESILENT=
+else
+M=@echo #
+Q=@
+MAKESILENT=-s
+endif
+
+# Clean needs to be a double-colon rule since we want sub-makefiles to be able
+# to define their own cleanup actions.
+dust::
+       rm -f `find . -path "*~" -or -name "\#*\#" -or -name core`
+       rm -f allocs.tmp cscope.out
+
+clean:: dust
+       rm -rf obj tests run/bin/* run/lib/* run/include/* run/.tree-stamp TAGS
+
+distclean:: clean
+       rm -rf run
+
+testclean::
+       rm -f `find obj -name "*.test"`
+
+# Relative symlinks and other pathname manipulation macros
+empty:=
+space:=$(empty) $(empty)
+backref=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(1))))
+tack-on=$(if $(patsubst /%,,$(2)),$(1)/$(2),$(2))
+symlink=ln -sf $(call tack-on,$(call backref,$(2)),$(1)) $(2)/