]> git.argeo.org Git - cc0/argeo-build.git/blob - osgi.mk
2d06f566f7f03c258e3bf9a5bd7f3b41a96c0c99
[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 # Third-party libraries
31 LOGGER_JAR ?= $(lastword $(foreach base, $(A2_BASE), $(wildcard $(base)/org.argeo.tp/org.argeo.tp.syslogger.$(SYSLOGGER_BRANCH).jar)))
32 ECJ_JAR ?= $(lastword $(foreach base, $(A2_BASE), $(wildcard $(base)/org.argeo.tp.sdk/org.eclipse.jdt.core.compiler.batch.$(ECJ_BRANCH).jar)))
33 BNDLIB_JAR ?= $(lastword $(foreach base, $(A2_BASE), $(wildcard $(base)/org.argeo.tp.sdk/biz.aQute.bndlib.$(BNDLIB_BRANCH).jar)))
34
35 # Internal variables
36 ARGEO_MAKE = $(JVM) -cp $(LOGGER_JAR):$(ECJ_JAR):$(BNDLIB_JAR) $(ARGEO_BUILD_BASE)src/org/argeo/build/Make.java
37 JAVADOC_SRCS = $(foreach bundle, $(BUNDLES), $(bundle)/src)
38 ifneq ($(NO_MANIFEST_COPY),true)
39 MANIFESTS = $(foreach bundle, $(BUNDLES), $(bundle)/META-INF/MANIFEST.MF)
40 endif
41 BUILD_BASE = $(SDK_BUILD_BASE)/$(shell basename $(SDK_SRC_BASE))
42 TARGET_BUNDLES = $(abspath $(foreach bundle, $(BUNDLES),$(A2_OUTPUT)/$(shell dirname $(bundle))/$(A2_CATEGORY)/$(shell basename $(bundle)).$(major).$(minor).jar))
43 TODOS = $(foreach bundle, $(BUNDLES),$(BUILD_BASE)/$(bundle)/to-build)
44
45 # Needed in order to be able to expand $$ variables
46 .SECONDEXPANSION:
47 .PHONY: osgi manifests javadoc
48
49 osgi: $(BUILD_BASE)/built $(MANIFESTS)
50
51 # Actual build (compilation + bundle packaging)
52 $(BUILD_BASE)/built : BUNDLES_TO_BUILD = $(subst $(abspath $(BUILD_BASE))/,, $(subst to-build,, $?))
53 $(BUILD_BASE)/built : $(TODOS)
54 $(ARGEO_MAKE) \
55 all --a2-bases $(A2_BASE) --dep-categories $(DEP_CATEGORIES) \
56 --category $(A2_CATEGORY) --bundles $(BUNDLES_TO_BUILD)
57 @touch $(BUILD_BASE)/built
58
59 $(A2_OUTPUT)/%.$(major).$(minor).jar : $(BUILD_BASE)/$$(subst $(A2_CATEGORY)/,,$$*)/to-build
60 $(ARGEO_MAKE) \
61 all --a2-bases $(A2_BASE) --dep-categories $(DEP_CATEGORIES) \
62 --category $(A2_CATEGORY) --bundles $(subst $(A2_CATEGORY)/,,$*)
63
64 $(BUILD_BASE)/%/to-build : $$(shell find % -type f -not -path 'bin/*' -not -path '*/MANIFEST.MF' | sed 's/ /\\ /g')
65 @rm -rf $(dir $@)
66 @mkdir -p $(dir $@)
67 @touch $@
68
69 # Local manifests
70 %/META-INF/MANIFEST.MF : $(BUILD_BASE)/%/META-INF/MANIFEST.MF
71 ifneq ($(NO_MANIFEST_COPY),true)
72 @mkdir -p $*/META-INF
73 @cp $< $@
74 endif
75
76 clean-manifests :
77 @rm -rf $(foreach bundle, $(BUNDLES), $(bundle)/META-INF/MANIFEST.MF);
78
79 # Javadoc generation
80 javadoc: $(BUILD_BASE)/built
81 $(JAVADOC) -quiet -Xmaxwarns 1 -d $(BUILD_BASE)/api --source-path $(subst $(space),$(pathsep),$(strip $(JAVADOC_SRCS))) -subpackages $(JAVADOC_PACKAGES)
82
83 # Make variables used to replace spaces by a separator, typically in order to generate classpaths
84 # for example: CLASSPATH = $(subst $(space),$(pathsep),$(strip $(JARS)))
85 null :=
86 space := $(null) #
87 pathsep := :