forked from eclipse-openj9/openj9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildj9tools.mk
127 lines (105 loc) · 3.97 KB
/
buildj9tools.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
################################################################################
# Copyright IBM Corp. and others 2017
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
# or the Apache License, Version 2.0 which accompanies this distribution and
# is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# This Source Code may also be made available under the following
# Secondary Licenses when the conditions for such availability set
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
# General Public License, version 2 with the GNU Classpath
# Exception [1] and GNU General Public License, version 2 with the
# OpenJDK Assembly Exception [2].
#
# [1] https://www.gnu.org/software/classpath/license.html
# [2] https://openjdk.org/legal/assembly-exception.html
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
#
################################################################################
# Makefile to compile and archive the J9 Java tools.
#
# Usage:
# make -f buildj9tools.mk FREEMARKER_JAR=/path/to/freemarker.jar
#
# Optional parameters:
# BOOT_JDK: path to Java 8 or 9 installation directory
# DEST_DIR: the location to copy the J9 Java tools generated binaries
################################################################################
DEST_DIR := lib
EMPTY :=
LIB_DIR := lib
OS := $(shell uname)
PATH_SEP := $(if $(or $(findstring Windows,$(OS)),$(findstring CYGWIN,$(OS))),;,:)
SPACE := $(EMPTY) $(EMPTY)
WORK_PFX := build-
# compiler settings
ifdef BOOT_JDK
JAVA_BIN ?= $(BOOT_JDK)/bin
else
ifdef DEV_TOOLS
JAVA_BIN ?= $(DEV_TOOLS)/ibm-jdk-1.8.0/bin
else
# requires Java 8 or 9
JAVA := java8
JAVA_BIN ?= $(dir $(realpath $(shell which $(JAVA))))
endif
endif
ifneq (,$(JAVA_BIN))
JAVA_BIN := $(subst //,/,$(subst \,/,$(JAVA_BIN)/))
endif
JAVAC := $(JAVA_BIN)javac
JAR := $(JAVA_BIN)jar
JAVAC_FLAGS := -nowarn
JAR_TARGETS :=
.PHONY : all clean default distclean preprocessor
default : all
all : # prerequisites are contributed via macros below
clean :
rm -rf $(WORK_PFX)*
distclean : clean
rm -f $(JAR_TARGETS)
preprocessor : $(DEST_DIR)/jpp.jar
# FindAllFiles
# ------------
# param 1 = the directory to search (recursively)
# param 2 = the pattern to match
#
FindAllFiles = $(strip $(call FindAllFiles_impl,$1,$2))
FindAllFiles_impl = $(wildcard $1/$2) $(foreach i,$(wildcard $1/*),$(call FindAllFiles_impl,$i,$2))
# BuildJar_template
# -----------------
# param 1 = the base name of the jar to create
# param 2 = the source directory
# parma 3 = classpath elements (optional)
#
define BuildJar_template
$1_OTHER_FILES := $(call FindAllFiles,$2,*.properties)
ifeq ($1,uma)
$1_OTHER_FILES += $(call FindAllFiles,$2,*.xsd)
endif
$1_SOURCES := $(call FindAllFiles,$2,*.java)
$1_TARGET := $(DEST_DIR)/$1.jar
$1_WORK_DIR := $(WORK_PFX)$1
JAR_TARGETS += $$($1_TARGET)
all : $$($1_TARGET)
$$($1_TARGET) : $$($1_SOURCES) $$($1_OTHER_FILES)
@echo Building $$@
@rm -rf $$($1_WORK_DIR)
@mkdir -p $$($1_WORK_DIR)
@$(JAVAC) -d $$($1_WORK_DIR) $(JAVAC_FLAGS) $(if $3,-classpath "$(subst $(SPACE),$(PATH_SEP),$(strip $3))") $$($1_SOURCES)
@$(JAR) cf $$@ -C $$($1_WORK_DIR) . \
$$(patsubst $2/%,-C $2 %,$$($1_OTHER_FILES)) \
$$(if $$(wildcard $2/schema),-C $2/schema .)
@rm -rf $$($1_WORK_DIR)
endef # BuildJar_template
$(eval $(call BuildJar_template,j9nls,j9nls))
$(eval $(call BuildJar_template,j9vmcp,j9constantpool,$(DEST_DIR)/om.jar))
$(eval $(call BuildJar_template,om,objectmodel))
$(eval $(call BuildJar_template,jpp,com.ibm.jpp.preprocessor))
$(eval $(call BuildJar_template,uma,com.ibm.uma,$(DEST_DIR)/om.jar $(FREEMARKER_JAR)))
$(DEST_DIR)/j9vmcp.jar : $(DEST_DIR)/om.jar
$(DEST_DIR)/uma.jar : $(DEST_DIR)/om.jar