+SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
+include $(SELF_DIR)common.mk
+#
+# Common repackage routines to be included in Makefiles
+#
+# The following variables are found in the sdk.mk file which is generated by the configure script:
+# SDK_SRC_BASE the base of the source code, typically the root of the cloned git repository
+# SDK_BUILD_BASE the base of the output
+# JAVA_HOME the base of the JDK used to build
A2_OUTPUT = $(SDK_BUILD_BASE)/a2
-A2_BASE ?= $(A2_OUTPUT)
JVM ?= $(JAVA_HOME)/bin/java
-TODOS_REPACKAGE = $(foreach category, $(CATEGORIES),$(BUILD_BASE)/$(category)/to-repackage)
+# The following variables should be declared in the including Makefile:
+# CATEGORIES the space-separated list of categories to repackage
+
+# The following variables have default values which can be overriden
+# A2_BASE the space-separated directories where already built a2 categories can be found
+A2_BASE ?=/usr/share/a2 /usr/local/share/a2 $(A2_OUTPUT)
+# Third-party libraries
+LOGGER_JAR ?= $(lastword $(foreach base, $(A2_BASE), $(wildcard $(base)/org.argeo.tp/org.argeo.tp.syslogger.$(SYSLOGGER_BRANCH).jar)))
+BNDLIB_JAR ?= $(lastword $(foreach base, $(A2_BASE), $(wildcard $(base)/org.argeo.tp.sdk/biz.aQute.bndlib.$(BNDLIB_BRANCH).jar)))
+
+# Internal variables
+TODOS_REPACKAGE = $(foreach category, $(CATEGORIES),$(BUILD_BASE)/$(category)/to-repackage)
BUILD_BASE = $(SDK_BUILD_BASE)/$(shell basename $(SDK_SRC_BASE))
all: $(BUILD_BASE)/repackaged
$(BUILD_BASE)/repackaged : CATEGORIES_TO_REPACKAGE = $(subst $(abspath $(BUILD_BASE))/,, $(subst to-repackage,, $?))
$(BUILD_BASE)/repackaged : $(TODOS_REPACKAGE)
$(JVM) \
- -cp $(A2_BASE)/org.argeo.tp/org.argeo.tp.syslogger.2.3.jar:$(A2_BASE)/org.argeo.tp.sdk/biz.aQute.bndlib.5.3.jar \
+ -cp $(LOGGER_JAR):$(BNDLIB_JAR) \
$(SDK_SRC_BASE)/sdk/argeo-build/src/org/argeo/build/Repackage.java \
$(A2_OUTPUT) $(CATEGORIES_TO_REPACKAGE)
touch $(BUILD_BASE)/repackaged