summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/Makefile.common100
1 files changed, 80 insertions, 20 deletions
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