]> git.argeo.org Git - cc0/argeo-build.git/blob - osgi.mk
Preserve spaces in output
[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 @echo "\| Compiler : $(ECJ_JAR)"
56 @echo "\| A2 category : $(A2_CATEGORY)"
57 @echo "\| Bundles : $(BUNDLES_TO_BUILD)"
58 @echo "\| Dependencies : $(DEP_CATEGORIES)"
59 @$(ARGEO_MAKE) \
60 all --a2-bases $(A2_BASE) --dep-categories $(DEP_CATEGORIES) \
61 --category $(A2_CATEGORY) --bundles $(BUNDLES_TO_BUILD)
62 @touch $(BUILD_BASE)/built
63
64 $(A2_OUTPUT)/%.$(major).$(minor).jar : $(BUILD_BASE)/$$(subst $(A2_CATEGORY)/,,$$*)/to-build
65 $(ARGEO_MAKE) \
66 all --a2-bases $(A2_BASE) --dep-categories $(DEP_CATEGORIES) \
67 --category $(A2_CATEGORY) --bundles $(subst $(A2_CATEGORY)/,,$*)
68
69 $(BUILD_BASE)/%/to-build : $$(shell find % -type f -not -path 'bin/*' -not -path '*/MANIFEST.MF' | sed 's/ /\\ /g')
70 @rm -rf $(dir $@)
71 @mkdir -p $(dir $@)
72 @touch $@
73
74 # Local manifests
75 %/META-INF/MANIFEST.MF : $(BUILD_BASE)/%/META-INF/MANIFEST.MF
76 ifneq ($(NO_MANIFEST_COPY),true)
77 @mkdir -p $*/META-INF
78 @cp $< $@
79 endif
80
81 clean-manifests :
82 @rm -rf $(foreach bundle, $(BUNDLES), $(bundle)/META-INF/MANIFEST.MF);
83
84 osgi-install:
85 $(ARGEO_MAKE) \
86 install --category $(A2_CATEGORY) --bundles $(BUNDLES) \
87 --target $(A2_INSTALL_TARGET)
88
89 osgi-uninstall:
90 $(ARGEO_MAKE) \
91 uninstall --category $(A2_CATEGORY) --bundles $(BUNDLES) \
92 --target $(A2_INSTALL_TARGET)
93
94 # Javadoc generation
95 javadoc: $(BUILD_BASE)/built
96 $(JAVADOC) -noindex -quiet -Xmaxwarns 1 -d $(BUILD_BASE)/api --source-path $(subst $(space),$(pathsep),$(strip $(JAVADOC_SRCS))) -subpackages $(JAVADOC_PACKAGES)
97
98 # Make variables used to replace spaces by a separator, typically in order to generate classpaths
99 # for example: CLASSPATH = $(subst $(space),$(pathsep),$(strip $(JARS)))
100 null :=
101 space := $(null) #
102 pathsep := :