From 90b089d7fd6454771b23fdcebb78d3b1a469c3f5 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 7 Apr 2008 02:11:49 +0000 Subject: Rework buildsystem so that it no longer calls make recursively and rebuilds the testcases when the library changes. svn path=/trunk/hubbub/; revision=4077 --- build/Makefile.common | 100 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 20 deletions(-) (limited to 'build/Makefile.common') diff --git a/build/Makefile.common b/build/Makefile.common index 21c319a..bc79ff5 100644 --- a/build/Makefile.common +++ b/build/Makefile.common @@ -1,39 +1,99 @@ # Top-level Makefile fragment for Hubbub +# Default target +all: release + # Name of component -export COMPONENT = libhubbub +COMPONENT := libhubbub # Environment -export EXPORT = $(CURDIR)/dist -export TOP = $(CURDIR) +EXPORT := $(CURDIR)/dist +TOP := $(CURDIR) +RELEASEDIR := build/Release +DEBUGDIR := build/Debug + +# List of items to delete on clean +ITEMS_CLEAN := +# List of items to delete on distclean +ITEMS_DISTCLEAN := + +# List of targets to run for testing +TARGET_TESTS := + +# Source files +SOURCES := + +# Include Makefile fragments in subdirectories -.PHONY: release debug test clean setup export distclean +define do_include +DIR := $$(dir $(1)) +include $(1) + +endef + +MAKE_INCLUDES := $(wildcard */Makefile) +$(eval $(foreach INC, $(MAKE_INCLUDES), $(call do_include,$(INC)))) + +# Calculate objects to build +OBJECTS := $(subst /,_,$(subst .c,.o,$(SOURCES))) + +.PHONY: release debug test clean distclean setup export install uninstall # Rules -release: setup - @$(MAKE) $(MAKEFLAGS) -C src release +release: setup $(addprefix $(RELEASEDIR)/,$(OBJECTS)) + @$(AR) $(ARFLAGS) $(COMPONENT).a $(RELEASEDIR)/* -debug: setup - @$(MAKE) $(MAKEFLAGS) -C src debug +debug: setup $(addprefix $(DEBUGDIR)/,$(OBJECTS)) + @$(AR) $(ARFLAGS) $(COMPONENT)-debug.a $(DEBUGDIR)/* -test: debug - @$(MAKE) $(MAKEFLAGS) -C test test +test: debug $(TARGET_TESTS) clean: - @$(MAKE) $(MAKEFLAGS) -C src clean - @$(MAKE) $(MAKEFLAGS) -C test clean + -@$(RM) $(RMFLAGS) $(ITEMS_CLEAN) + -@$(RM) $(RMFLAGS) -r $(RELEASEDIR) + -@$(RM) $(RMFLAGS) -r $(DEBUGDIR) + -@$(RM) $(RMFLAGS) $(COMPONENT).a + -@$(RM) $(RMFLAGS) $(COMPONENT)-debug.a + -@$(RM) $(RMFLAGS) $(COMPONENT).pc + +distclean: clean + -@$(RM) $(RMFLAGS) $(ITEMS_DISTCLEAN) + -@$(RM) $(RMFLAGS) -r $(TOP)/dist setup: - @$(MAKE) $(MAKEFLAGS) -C src setup - @$(MAKE) $(MAKEFLAGS) -C test setup + @$(MKDIR) $(MKDIRFLAGS) $(RELEASEDIR) + @$(MKDIR) $(MKDIRFLAGS) $(DEBUGDIR) export: release @$(MKDIR) $(MKDIRFLAGS) $(TOP)/dist/lib @$(CP) $(CPFLAGS) -r include $(EXPORT)/ - @$(MAKE) $(MAKEFLAGS) -C src export - @$(MAKE) $(MAKEFLAGS) -C test export + @${CP} ${CPFLAGS} $(COMPONENT).a ${EXPORT}/lib/ + +install: release + @$(MKDIR) $(MKDIRFLAGS) -p $(PREFIX)/lib/pkgconfig + @$(MKDIR) $(MKDIRFLAGS) -p $(PREFIX)/include/hubbub + @$(SED) -e 's#PREFIX#$(PREFIX)#' $(COMPONENT).pc.in >$(COMPONENT).pc + @$(INSTALL) --mode=644 -t $(PREFIX)/lib $(COMPONENT).a + @$(INSTALL) --mode=644 -t $(PREFIX)/lib/pkgconfig $(COMPONENT).pc + @$(INSTALL) --mode=644 -t $(PREFIX)/include/hubbub $(filter %.h, $(wildcard include/hubbub/*)) + +uninstall: + @$(RM) $(RMFLAGS) $(PREFIX)/lib/$(COMPONENT).a + @$(RM) $(RMFLAGS) $(PREFIX)/lib/pkgconfig/$(COMPONENT).pc + @$(RM) $(RMFLAGS) -r $(PREFIX)/include/hubbub + +# Finally, build rules for compilation +define do_compile +$$(RELEASEDIR)/$(2): $(1) + @$$(ECHO) $$(ECHOFLAGS) "==> $(1)" + @$$(CC) -c $$(RELEASECFLAGS) -o $$@ $(1) + +$$(DEBUGDIR)/$(2): $(1) + @$$(ECHO) $$(ECHOFLAGS) "==> $(1)" + @$$(CC) -c $$(DEBUGCFLAGS) -o $$@ $(1) + +endef + +$(eval $(foreach SOURCE,$(filter %.c,$(SOURCES)), \ + $(call do_compile,$(SOURCE),$(subst /,_,$(SOURCE:.c=.o))))) -distclean: clean - -@$(RM) $(RMFLAGS) -r $(TOP)/dist - @$(MAKE) $(MAKEFLAGS) -C src distclean - @$(MAKE) $(MAKEFLAGS) -C test distclean -- cgit v1.2.3