]> git.argeo.org Git - cc0/argeo-build.git/blob - osgi.mk
3f17e6dd01d0576a196f172678375bbf85df7793
[cc0/argeo-build.git] / osgi.mk
1 ARGEO_BUILD_BASE := $(dir $(lastword $(MAKEFILE_LIST)))
2 include $(ARGEO_BUILD_BASE)common.mk
3 #
4 # Common build routines to be included in Makefiles
5 #
6 # The following variables are found in the sdk.mk file which is generated by the configure script:
7 # SDK_SRC_BASE the base of the source code, typically the root of the cloned git repository
8 # SDK_BUILD_BASE the base of the output
9 # JAVA_HOME the base of the JDK used to build
10 A2_OUTPUT = $(SDK_BUILD_BASE)/a2
11 JVM ?= $(JAVA_HOME)/bin/java
12 JAVADOC ?= $(JAVA_HOME)/bin/javadoc
13
14 # The following variables should be declared in the including Makefile:
15 # BUNDLES the space-separated list of bundles to build
16 # A2_CATEGORY the (single) a2 category the bundles will belong to
17
18 # The following environment variables can change the behaviour of the build
19 # SOURCE_BUNDLES sources will be packaged separately in Eclipse-compatible source bundles
20 # NO_MANIFEST_COPY generated MANIFESTs won't be copied to the source tree
21
22 # The following variables have default values which can be overriden
23 # DEP_CATEGORIES the a2 categories the compilation depends on
24 # JAVADOC_PACKAGES the space-separated list of packages for which javadoc will be generated
25 # A2_BASE the space-separated directories where already built a2 categories can be found
26 DEP_CATEGORIES ?=
27 JAVADOC_PACKAGES ?=
28 A2_BASE ?=/usr/share/a2 /usr/local/share/a2 $(A2_OUTPUT)
29
30 # We always use the latest version of the ECJ compiler
31 ECJ_JAR ?= $(lastword $(foreach base, $(A2_BASE), $(sort $(wildcard $(base)/org.argeo.tp.build/org.eclipse.jdt.core.compiler.batch.$(ECJ_MAJOR).*.jar))))
32 # Third-party libraries
33 LOGGER_JAR ?= $(lastword $(foreach base, $(A2_BASE), $(wildcard $(base)/log/syslogger/org.argeo.tp/org.argeo.tp.syslogger.$(SYSLOGGER_BRANCH).jar)))
34 BNDLIB_JAR ?= $(lastword $(foreach base, $(A2_BASE), $(wildcard $(base)/org.argeo.tp.build/biz.aQute.bndlib.$(BNDLIB_BRANCH).jar)))
35
36 # Internal variables
37 ARGEO_MAKE = $(JVM) -cp $(LOGGER_JAR):$(ECJ_JAR):$(BNDLIB_JAR) $(ARGEO_BUILD_BASE)src/org/argeo/build/Make.java
38 JAVADOC_SRCS = $(foreach bundle, $(BUNDLES), $(bundle)/src)
39 ifneq ($(NO_MANIFEST_COPY),true)
40 MANIFESTS = $(foreach bundle, $(BUNDLES), $(bundle)/META-INF/MANIFEST.MF)
41 endif
42 BUILD_BASE = $(SDK_BUILD_BASE)/$(shell basename $(SDK_SRC_BASE))
43 TARGET_BUNDLES = $(abspath $(foreach bundle, $(BUNDLES),$(A2_OUTPUT)/$(shell dirname $(bundle))/$(A2_CATEGORY)/$(shell basename $(bundle)).$(major).$(minor).jar))
44 TODOS = $(foreach bundle, $(BUNDLES),$(BUILD_BASE)/$(bundle)/to-build)
45
46 # Needed in order to be able to expand $$ variables
47 .SECONDEXPANSION:
48 .PHONY: osgi manifests javadoc
49
50 osgi: $(BUILD_BASE)/built $(MANIFESTS)
51
52 # Actual build (compilation + bundle packaging)
53 $(BUILD_BASE)/built : BUNDLES_TO_BUILD = $(subst $(abspath $(BUILD_BASE))/,, $(subst to-build,, $?))
54 $(BUILD_BASE)/built : $(TODOS)
55 $(ARGEO_MAKE) \
56 all --a2-bases $(A2_BASE) --dep-categories $(DEP_CATEGORIES) \
57 --category $(A2_CATEGORY) --bundles $(BUNDLES_TO_BUILD)
58 @touch $(BUILD_BASE)/built
59
60 $(A2_OUTPUT)/%.$(major).$(minor).jar : $(BUILD_BASE)/$$(subst $(A2_CATEGORY)/,,$$*)/to-build
61 $(ARGEO_MAKE) \
62 all --a2-bases $(A2_BASE) --dep-categories $(DEP_CATEGORIES) \
63 --category $(A2_CATEGORY) --bundles $(subst $(A2_CATEGORY)/,,$*)
64
65 $(BUILD_BASE)/%/to-build : $$(shell find % -type f -not -path 'bin/*' -not -path '*/MANIFEST.MF' | sed 's/ /\\ /g')
66 @rm -rf $(dir $@)
67 @mkdir -p $(dir $@)
68 @touch $@
69
70 # Local manifests
71 %/META-INF/MANIFEST.MF : $(BUILD_BASE)/%/META-INF/MANIFEST.MF
72 ifneq ($(NO_MANIFEST_COPY),true)
73 @mkdir -p $*/META-INF
74 @cp $< $@
75 endif
76
77 clean-manifests :
78 @rm -rf $(foreach bundle, $(BUNDLES), $(bundle)/META-INF/MANIFEST.MF);
79
80 osgi-install:
81 $(ARGEO_MAKE) \
82 install --category $(A2_CATEGORY) --bundles $(BUNDLES) \
83 --target $(A2_INSTALL_TARGET)
84
85 osgi-uninstall:
86 $(ARGEO_MAKE) \
87 uninstall --category $(A2_CATEGORY) --bundles $(BUNDLES) \
88 --target $(A2_INSTALL_TARGET)
89
90 # Javadoc generation
91 javadoc: $(BUILD_BASE)/built
92 $(JAVADOC) -noindex -quiet -Xmaxwarns 1 -d $(BUILD_BASE)/api --source-path $(subst $(space),$(pathsep),$(strip $(JAVADOC_SRCS))) -subpackages $(JAVADOC_PACKAGES)
93
94 # Make variables used to replace spaces by a separator, typically in order to generate classpaths
95 # for example: CLASSPATH = $(subst $(space),$(pathsep),$(strip $(JARS)))
96 null :=
97 space := $(null) #
98 pathsep := :