Update of /cvsroot/libfunutil/libfunutil/toc/make In directory sc8-pr-cvs1:/tmp/cvs-serv5483/toc/make Added Files: STATIC_LIBS.make SHARED_LIBS.make INSTALL_XXX.make C_DEPS.make C_BINS_FROM_SOURCES.make BIN_PROGRAMS.make Log Message: egg --- NEW FILE: STATIC_LIBS.make --- # cpp_static_libs.make: snippet for linking static libraries from # object files. # # This snippet defines the targets 'libs-static' and 'X.a' for each X in # $(STATIC_LIBS). libs-static simply depends on X.a. # # sample usage: # # STATIC_LIBS = foo bar # STATIC_LIBS_OBJECTS = # optional list of .o files to link to all $(STATIC_LIBS) # foo_a_OBJECTS = list of .o files # bar_a_OBJECTS = list of .o files # # all: libs #(or) all: foo.a bar.a # # that creates foo.a and bar.a and adds those files to $(INSTALL_LIBS) STATIC_LIBS_MAKEFILE = $(toc_makesdir)/STATIC_LIBS.make STATIC_LIBS_A = $(patsubst %,%.a,$(STATIC_LIBS)) CLEAN_FILES += $(STATIC_LIBS_A) # toc_link_static_lib call()able: # $1 = base name (e.g., foo) # links $(1).a from $($(1)_a_OBJECTS) and $(STATIC_LIBS_OBJECTS) toc_link_static_lib = $(AR) crs $(1).a $($(1)_a_OBJECTS) $(STATIC_LIBS_OBJECTS) ifneq (,$(STATIC_LIBS_A)) STATIC_LIBS_DEPSFILE = .toc.STATIC_LIBS.make STATIC_LIBS_RULES_GENERATOR = $(dir $(STATIC_LIBS_MAKEFILE))makerules.STATIC_LIBS STATIC_LIBS: $(STATIC_LIBS_DEPSFILE): Makefile $(STATIC_LIBS_MAKEFILE) $(STATIC_LIBS_RULES_GENERATOR) ifneq (,$(strip $(filter distclean clean,$(MAKECMDGOALS)))) @echo "$(MAKECMDGOALS): skipping STATIC_LIBS rules generation." else @echo "Generating STATIC_LIBS rules."; \ $(call toc_generate_rules,STATIC_LIBS,$(STATIC_LIBS)) > $@ endif -include $(STATIC_LIBS_DEPSFILE) deps: $(STATIC_LIBS_DEPSFILE) libs: STATIC_LIBS libs-static: STATIC_LIBS endif --- NEW FILE: SHARED_LIBS.make --- # Links objects into a dynamically-linked library using g++ # usage: # # SHARED_LIBS = foo # SHARED_LIBS_OBJECTS = # optional list of .o files to link to all $(SHARED_LIBS) # foo_so_OBJECTS = list of object files to link to foo.so # foo_so_LDADD = # optional libraries passed to linker (e.g., -lstdc++) # foo_so_LDFLAGS = # optional args to linker # foo_so_VERSION = # optional Major.Minor.Patch # e.g. "1.0.1" it MUST match this format! # include $(toc_makesdir)/cpp_dynamic_libs.make # # If foo_so_VERSION is not set then no numbered symlinks will be created. # # Run: # all: lib-shared # # Effect: # Creates foo.so and foo.so<version> by linking $(foo_so_OBJECTS). It # also sets up install/uninstall rules for handling the symlinks. SHARED_LIBS_MAKEFILE = $(toc_makesdir)/SHARED_LIBS.make # toc_link_shared_lib # $1 = basename # $2 = extra args to the linker toc_link_shared_lib = { soname=$(1).so; wholename=$${soname}.$($(1)_so_MAJOR).$($(1)_so_MINOR).$($(1)_so_PATCH); \ so_major=$${soname}.$($(1)_so_MAJOR); \ stamp=$${so_major}; \ test x = x$($(1)_so_MAJOR) && { wholename=$${soname}; stamp=$(1).so;}; \ cmd="$(CXX) $(CXXFLAGS) $($(1)_LDFLAGS) -o $${wholename} -export-dynamic -shared \ -Wl,-soname,$${stamp} $($(1)_so_OBJECTS) $(SHARED_LIBS_OBJECTS) $(SHARED_LIBS_LDADD) $($(1)_so_LDADD) $(2)"; \ test x1 = x$(configure_build_quietly) || echo $$cmd; \ $$cmd || exit; \ test x = x$($(1)_so_MAJOR) || { \ ln -fs $${wholename} $${soname}.$($(1)_so_MAJOR).$($(1)_so_MINOR); \ ln -fs $${wholename} $${soname}.$($(1)_so_MAJOR); \ ln -fs $${wholename} $${soname}; \ }; \ } # symlinking methods: # method 1: # ln -fs $${wholename} $${soname}.$($(1)_so_MAJOR).$($(1)_so_MINOR); \ # ln -fs $${soname}.$($(1)_so_MAJOR).$($(1)_so_MINOR) $${soname}.$($(1)_so_MAJOR); \ # ln -fs $${soname}.$($(1)_so_MAJOR) $${soname}; \ # method 1.5: # link1=$${soname}.$($(1)_so_MAJOR).$($(1)_so_MINOR); ln -fs $${wholename} $$link1; \ # link2=$${soname}.$($(1)_so_MAJOR); ln -fs $$link1 $$link2; \ # link3=$${soname}; ln -fs $$link2 $$link3; \ # method 2: # ln -fs $${wholename} $${soname}.$($(1)_so_MAJOR).$($(1)_so_MINOR); \ # ln -fs $${wholename} $${soname}.$($(1)_so_MAJOR); \ # ln -fs $${wholename} $${soname}; \ # for l in $${soname} \ # $${soname}.$($(1)_so_MAJOR) \ # $${soname}.$($(1)_so_MAJOR).$($(1)_so_MINOR) \ # ; do \ # ln -fs $${wholename} $$l; \ # done; \ ifneq ($(SHARED_LIBS),) SHARED_LIBS_SOFILES = $(patsubst %,%.so,$(SHARED_LIBS)) SHARED_LIBS_RULES_GENERATOR = $(dir $(SHARED_LIBS_MAKEFILE))makerules.SHARED_LIBS # to ensure that .so files are installed in a unix-friendly manner we need to implement # some install rules for them... SHARED_LIBS_DEPSFILE = .toc.SHARED_LIBS.make deps: $(SHARED_LIBS_INSTALL_RULES) $(SHARED_LIBS_DEPSFILE): Makefile $(SHARED_LIBS_MAKEFILE) $(SHARED_LIBS_RULES_GENERATOR) ifneq (,$(strip $(filter distclean clean,$(MAKECMDGOALS)))) @echo "$(MAKECMDGOALS): skipping SHARED_LIBS rules generation." else @echo "Generating SHARED_LIBS rules."; \ $(call toc_generate_rules,SHARED_LIBS,$(SHARED_LIBS)) > $@ endif -include $(SHARED_LIBS_DEPSFILE) CLEAN_FILES += $(SHARED_LIBS_SOFILES) $(wildcard $(patsubst %,%.*,$(SHARED_LIBS_SOFILES))) libs: SHARED_LIBS endif # ^^^ got SHARED_LIBS? --- NEW FILE: INSTALL_XXX.make --- #!/bin/make -f # To be included from the shared toc makefile. # # Sample usage: # INSTALL_BINS = mybin myotherbin # installs to $(prefix)/bin # INSTALL_LIBS = mylib.a myotherlib.a # installs to $(prefix)/lib # # There's a whole lot more to know, if you wanna poke around the code. # # Design note: the traditional xxx-local targets aren't really # necessary. If someone wants to customize install they can simply do # this: # # install: my-install # my-install: # .... # # # For each X in $(TOC_INSTALL_TARGET_BASENAMES) the following targets # are created: # # install-X: # uninstall-X: # install-X-symlink: # # Files will be installed to $(INSTALL_X_DEST) using install # arguments $(INSTALL_X_INSTALL_FLAGS). All of these vars are # set up by default, but may be customized: # # INSTALL_BINS_DEST = $(prefix)/$(PACKAGE_NAME)/bin # INSTALL_BINS_INSTALL_FLAGS = -m 0775 # # # Installation can be further customized by using the toc_make_xxx # call()able functions. TOC_INSTALL_TARGET_BASENAMES = BINS SBINS LIBS PACKAGE_LIBS LIBEXECS HEADERS PACKAGE_HEADERS PACKAGE_DATA DOCS ifeq (,$(wildcard $(INSTALLER_BIN))) $(error INSTALL_XXX.make requires that the variable INSTALLER_BIN point to a version of install which is vaguely compatible with GNU install.) endif #INSTALL_BINS_SUFFIX ?= #ifeq (1,$(configure_with_CYGWIN)) #INSTALL_BINS_SUFFIX = .exe #endif # This whole echo/grep thing is to force it to work on some of my # older machines where more sane approaches don't seem to work. # TOC_MAKE_INSTALL_GREP_KLUDGE = test $(shell echo $(1) "" | grep -q '[a-zA-Z0-9]'; echo $$?) = 0 || exit 0 TOC_MAKE_INSTALL_GREP_KLUDGE = # toc_make_install call()able: # $1=file list # $2=destdir # $3=flags for $(INSTALLER_BIN) toc_make_install = test "x$(1)" = x && exit 0; \ test -d $(2) || mkdir -p $(2) || exit; \ for b in $(1) "x"; do test "x$$b" = "xx" && break; \ b=$$(basename $$b); \ target=$(2)/$$b; \ cmd="$(INSTALLER_BIN) $(3) $$b $$target"; echo $$cmd; $$cmd || exit; \ done # toc_make_install_update: identical to toc_make_install # but does not update the target if it is the same as the source. toc_make_install_update = test "x$(1)" = x && exit 0; \ test -d $(2) || mkdir -p $(2) || exit; \ for b in $(1) ""; do test -z "$$b" && continue; \ b="$$(basename $$b)"; \ target="$(2)/$$b"; \ cmp "$$target" "$$b" > /dev/null 2>&1 && continue; \ cmd="$(INSTALLER_BIN) $(3) $$b $$target"; echo "$$cmd"; $$cmd || exit; \ done # toc_make_uninstall call()able: # removes all files listed in $(1) from target directory $(2) toc_make_uninstall = test "x$(1)" = x && exit 0; \ test -e "$(2)" || exit 0; \ for b in $(1) ""; do test -z "$$b" && continue; \ fp="$(2)/$$b"; test -e "$$fp" || continue; \ cmd="rm $$fp"; echo $$cmd; $$cmd || exit $$?; \ done # toc_make_install_symlink call()able: # Works similarly to toc_make_install, but symlinks back to the install source, # instead of copying. Arg $3 is ignored. # Note that symlinks must be linked to absolute paths here, because we cannot # easily/reliably make a relative path from the target directory back to # the install source: toc_make_install_symlink = test "x$(1)" = x && exit 0; \ test -d $(2) || mkdir -p $(2) || exit; \ for b in $(1) ""; do test -z "$$b" && continue; \ target="$(2)/$$b"; \ pwd="$$(pwd)"; \ src="$$pwd/$$b"; \ test "$$target" -ef "$$src" && continue; \ test -f "$$target" && rm "$$target"; \ echo "Symlinking $$target"; ln -s -f "$$src" "$$target" || exit $$?; \ done # toc_make_install_so: installs foo.so.X.Y.Z and symlinks foo.so, foo.so.X and foo.so.X.Y to it, # in traditional/common Unix style. # $1 = so name (foo.so) # $2-4 = Major, Minor, Patch version numbers # $5 = destination directory toc_make_install_so = test "x$(1)" = x && exit 0; \ test -d $(5) || mkdir -p $(5) || exit; \ wholename=$(1).$(2).$(3).$(4); \ target=$(5)/$$wholename; \ test $$wholename -ef $$target || { \ echo "Installing/symlinking $$target"; \ cmd="$(INSTALLER_BIN) -m 0755 $$wholename $$target"; \ $$cmd || exit; \ }; \ cd $(5); \ for i in $(1) $(1).$(2) $(1).$(2).$(3); do \ test -e $$i && rm $$i; \ cmd="ln -fs $$wholename $$i"; echo $$cmd; \ $$cmd || exit; \ done # symlinking method number 2: # { set -x; \ # ln -fs $(1).$(2).$(3).$(4) $(1).$(2).$(3); \ # ln -fs $(1).$(2).$(3) $(1).$(2); \ # ln -fs $(1).$(2) $(1); \ # } INSTALLER_BIN_FLAGS_BINS = -m 0755 INSTALLER_BIN_FLAGS_NONBINS = -m 0644 INSTALLER_BIN_FLAGS_LIBS = -m 0644 INSTALLER_BIN_FLAGS_LIBEXECS = -m 0755 # default install flags for the installable file categories: INSTALL_BINS_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_BINS) INSTALL_SBINS_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_BINS) INSTALL_LIBS_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_LIBS) INSTALL_PACKAGE_LIBS_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_LIBS) INSTALL_LIBEXECS_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_LIBEXECS) INSTALL_HEADERS_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_NONBINS) INSTALL_PACKAGE_HEADERS_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_NONBINS) INSTALL_PACKAGE_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_NONBINS) INSTALL_DOCS_INSTALL_FLAGS ?= $(INSTALLER_BIN_FLAGS_NONBINS) INSTALL_MAKEFILE = $(toc_makesdir)/INSTALL_XXX.make INSTALL_DEPS_FILE = $(toc_makesdir)/.toc.INSTALL_XXX.make INSTALL_XXX_GENERATOR = $(dir $(INSTALL_MAKEFILE))makerules.INSTALL_XXX # Set install paths for the installable file categories # and create installation rules. With make 3.80 we can do this with $(eval), # Make 3.79 is very common, but doesn't support $(eval). # todo? move this into the configure process? $(INSTALL_DEPS_FILE): $(INSTALL_MAKEFILE) $(INSTALL_XXX_GENERATOR) ifneq (,$(strip $(filter clean distclean,$(MAKECMDGOALS)))) # @echo "$(MAKECMDGOALS): skipping INSTALL_XXX rules generation." else @echo "Generating rules for INSTALL_XXX."; \ $(call toc_generate_rules,INSTALL_XXX,\ BINS=bin \ SBINS=sbin \ LIBS=lib \ PACKAGE_LIBS='lib/$$(PACKAGE_NAME)' \ LIBEXECS=lib \ HEADERS=include \ PACKAGE_HEADERS='include/$$(PACKAGE_NAME)' \ PACKAGE_DATA='share/$$(PACKAGE_NAME)' \ DOCS='share/doc/$$(PACKAGE_NAME)' \ ) > $@ endif -include $(INSTALL_DEPS_FILE) deps: $(INSTALL_DEPS_FILE) .PHONY: install-. uninstall-. subdirs-install: # implemented elsewhere install: install-. install-subdirs install-update: install-.-update install-subdirs-update install-symlink: install-.-symlink install-subdirs-symlink install-subdirs: subdirs-install install-subdirs-symlink: subdirs-install-symlink install-subdirs-update: subdirs-install-update uninstall-subdirs: subdirs-uninstall uninstall: uninstall-. uninstall-subdirs # implement these to hook in to the start of the install. Untested. :/ install-.: install-.-update: install-.-symlink: uninstall-.: --- NEW FILE: C_DEPS.make --- # makefile snippet # Usage: # include path/to/this/file # # That will set up a 'deps' target which deps all C/C++ files and updates # the deps when any of those files, or the Makefile, changes. # That's normally all there is to it. DEPS_C_SOURCES_GLOB ?= *.cpp *.c *.c++ *.C *.cc *.moc SOURCE_FILES_TO_DEP ?= $(sort $(wildcard $(DEPS_C_SOURCES_GLOB))) TOC_C_DEPS_MAKEFILE = $(toc_makesdir)/C_DEPS.make DEPSGEN_BIN = $(toc_tocdir)/bin/mkdep $(DEPSGEN_BIN): $(TOC_C_DEPS_MAKEFILE) @echo "Building $@"; cd $(toc_tocdir)/bin; \ $(CC) -o mkdep mkdep.c ifneq (,$(SOURCE_FILES_TO_DEP)) TOC_C_DEPSFILE = .toc.C_DEPS.make $(TOC_C_DEPSFILE): $(DEPSGEN_BIN) $(SOURCE_FILES_TO_DEP) Makefile $(TOC_C_DEPS_MAKEFILE) ifneq (,$(strip $(filter clean distclean,$(MAKECMDGOALS)))) @echo "$(MAKECMDGOALS): skipping C_DEPS rules generation." else @test -n "$(SOURCE_FILES_TO_DEP)" || exit 0; \ echo "Generating C_DEPS rules for $(DEPS_C_SOURCES_GLOB)"; \ $(call toc_make_c_deps,$(SOURCE_FILES_TO_DEP),) > $@ -include $(TOC_C_DEPSFILE) endif deps-c: $(TOC_C_DEPSFILE) deps: deps-c CLEAN_FILES += $(TOC_C_DEPSFILE) all: deps-c endif --- NEW FILE: C_BINS_FROM_SOURCES.make --- #!make # usage: # set: # C_BINS_FROM_SOURCES = foo bar # foo_bin_SOURCES = foo.c foo2.c # bar_bin_SOURCES = bar.c bar2.c foobar.c # optional: foo_bin_OBJECTS = somethingdifferent.o # optional: foo_bin_CFLAGS = -DCOMPILING_FOO=1 -I/somewhere/different # optional: foo_bin_LFLAGS = -lfl -lfoo # # all: bins # # This compiles, all in one go, 'bar' from $(bar_bin_SOURCES) C_BINS_FROM_SOURCES_MAKEFILE = $(toc_makesdir)/C_BINS_FROM_SOURCES.make ifneq (,$(C_BINS_FROM_SOURCES)) C_BINS_FROM_SOURCES_RULES_GENERATOR = $(toc_makesdir)/makerules.C_BINS_FROM_SOURCES C_BINS_FROM_SOURCES_COMMON_DEPS += Makefile $(C_BINS_FROM_SOURCES_MAKEFILE) C_BINS_FROM_SOURCES_DEPSFILE = .toc.C_BINS_FROM_SOURCES.make CLEAN_FILES += $(C_BINS_FROM_SOURCES_DEPSFILE) $(C_BINS_FROM_SOURCES_DEPSFILE): $(C_BINS_FROM_SOURCES_COMMON_DEPS) $(C_BINS_FROM_SOURCES_RULES_GENERATOR) ifneq (,$(strip $(filter distclean clean,$(MAKECMDGOALS)))) @echo "$(MAKECMDGOALS): skipping C_BINS_FROM_SOURCES rules generation." else @echo "Generating C_BINS_FROM_SOURCES rules."; \ $(call toc_generate_rules,C_BINS_FROM_SOURCES,$(C_BINS_FROM_SOURCES)) > $@ endif # ^^^ making clean? -include $(C_BINS_FROM_SOURCES_DEPSFILE) deps: $(C_BINS_FROM_SOURCES_DEPSFILE) endif # ^^^ got $(C_BINS_FROM_SOURCES)? --- NEW FILE: BIN_PROGRAMS.make --- # toc makefile snippet to link binaries. # # Usage: # define these vars: # BIN_PROGRAMS = somename anothername # BIN_PROGRAMS_LDADD (optional - list of libs to link to all BIN_PROGRAMS) # # For each FOO in BIN_PROGRAMS, define: # FOO_bin_OBJECTS = list of .o files for FOO # FOO_bin_LDADD = optional arguments to pass to linker, e.g. -lstdc++ # # Then include this file: # # include $(toc_makesdir)/cpp_bins.make # # and add 'bins' somewhere in your dependencies, e.g.: # # all: bins BIN_PROGRAMS_MAKEFILE = $(toc_makesdir)/BIN_PROGRAMS.make ifeq (1,$(configure_with_CYGWIN)) BIN_PROGRAMS_LDADD += -lcygwin endif # toc_link_binary call()able function: # $1 = binary file name # $2 = optional arguments to linker. # list of objects to link is derived from $($(1)_bin_OBJECTS) and $(BIN_PROGRAMS_OBJECTS) toc_link_binary = $(CXX) -o $(1) $($(1)_bin_OBJECTS) $(BIN_PROGRAMS_OBJECTS) $(LDFLAGS) $($(1)_bin_LDADD) $(BIN_PROGRAMS_LDADD) $(2) ifneq (,$(BIN_PROGRAMS)) ifeq (1,$(configure_with_CYGWIN)) CLEAN_FILES += $(addsuffix .exe,$(BIN_PROGRAMS)) CLEAN_FILES += $(wildcard *.exe.stackdump) else CLEAN_FILES += $(wildcard $(BIN_PROGRAMS)) endif BIN_PROGRAMS_DEPSFILE = .toc.BIN_PROGRAMS.make BIN_PROGRAMS_RULES_GENERATOR = $(dir $(BIN_PROGRAMS_MAKEFILE))makerules.BIN_PROGRAMS BIN_PROGRAMS_COMMON_DEPS += Makefile $(BIN_PROGRAMS_MAKEFILE) $(BIN_PROGRAMS_OBJECTS) $(BIN_PROGRAMS_DEPSFILE): Makefile $(BIN_PROGRAMS_RULES_GENERATOR) $(BIN_PROGRAMS_MAKEFILE) ifneq (,$(strip $(filter distclean clean,$(MAKECMDGOALS)))) @echo "$(MAKECMDGOALS): skipping BIN_PROGRAMS rules generation." else @echo "Generating BIN_PROGRAMS rules."; \ $(call toc_generate_rules,BIN_PROGRAMS,$(BIN_PROGRAMS)) > $@ -include $(BIN_PROGRAMS_DEPSFILE) endif deps: $(BIN_PROGRAMS_DEPSFILE) strip-bins: strip $(BIN_PROGRAMS) clean-bins: @test -n "$(BIN_PROGRAMS)" || exit 0; \ echo "Deleting: $(BIN_PROGRAMS)"; \ rm $(BIN_PROGRAMS) > /dev/null || true; run-bins: @LD_LIBRARY_PATH="$${LD_LIBRARY_PATH}:$${PWD}:$(top_src)/libdir"; \ for i in $(BIN_PROGRAMS); do \ echo "Running $$i"; ./$$i || exit $$?; done endif # ^^^ got $(BIN_PROGRAMS) ??? |