Skip to content

Commit 020a51d

Browse files
committed
Make build cross-platform
1 parent 364ebdb commit 020a51d

17 files changed

Lines changed: 410 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Maven
22
target/
3+
effective-settings.xml
34

45
# Eclipse
56
.classpath

Makefile

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,73 @@
1+
include utils/java-shell-for-make/enable-java-shell.mk
2+
3+
ifeq ($(OS), WINDOWS)
4+
MVN := mvn.cmd
5+
else
16
MVN := mvn
2-
M2_HOME := $(shell $(MVN) org.apache.maven.plugins:maven-help-plugin:3.4.0:effective-settings \
3-
| grep localRepository \
4-
| sed 's| *<localRepository>\(.*\)</localRepository> *|\1|g' )
7+
endif
8+
9+
mvn := try { \
10+
System.setProperty("jdk.lang.Process.allowAmbiguousCommands", "true"); \
11+
List<String> cmd = new ArrayList<>(); \
12+
for (String x : "$(MVN)".split("\\s+")) cmd.add(x); \
13+
for (String x : commandLineArgs) cmd.add(x); \
14+
exec(cmd); } \
15+
finally { \
16+
System.setProperty("jdk.lang.Process.allowAmbiguousCommands", "false"); }
17+
18+
M2_HOME := $(shell \
19+
exitOnError( \
20+
/* cd into random directory without pom.xml in order to force Maven "stub" project */ \
21+
captureOutput(err::println, \
22+
Files.createTempDirectory("mvn-stub-").toFile(), \
23+
"$(CURDIR)/$(SHELL)", $(call quote-for-java,$(mvn)), "--", \
24+
"org.apache.maven.plugins:maven-help-plugin:3.4.0:effective-settings", \
25+
"-Doutput=$(CURDIR)/effective-settings.xml")); \
26+
println( \
27+
xpath(new File("effective-settings.xml"), \
28+
"/*/*[local-name()='localRepository']/text()") \
29+
.replace('\\', '/')); \
30+
)
531

632
LOUISUTDML_VERSION := 2.11.0-p1
733
LOUIS_VERSION := 3.21.0-p2
834

9-
rwildcard = $(shell [ -d $1 ] && find $1 -type f -name '$2' | sed 's/ /\\ /g')
35+
rwildcard = $(shell if (new File("$1").isDirectory()) glob("$1**/$2").forEach(x -> println(x.getPath().replace('\\', '/').replace(" ", "\\ ")));)
1036

1137
install : \
1238
$(M2_HOME)/be/docarch/oxt-maven-plugin/1.0-SNAPSHOT/oxt-maven-plugin-1.0-SNAPSHOT.jar \
1339
$(M2_HOME)/be/docarch/l10n-maven-plugin/1.0-SNAPSHOT/l10n-maven-plugin-1.0-SNAPSHOT.jar \
1440
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-aarch64-MacOSX-gpp-shared.nar \
1541
$(M2_HOME)/org/liblouis/louisutdml/$(LOUISUTDML_VERSION)/louisutdml-$(LOUISUTDML_VERSION)-aarch64-MacOSX-gpp-shared.nar \
1642
$(M2_HOME)/org/liblouis/louisutdml/$(LOUISUTDML_VERSION)/louisutdml-$(LOUISUTDML_VERSION)-aarch64-MacOSX-gpp-executable.nar
17-
$(MVN) clean install -Pmacosx_aarch64
43+
exec("$(SHELL)", $(call quote-for-java,$(mvn)), "--", "clean", "install", "-Pmacosx_aarch64");
1844

1945
# Maven can not automatically resolve these dependencies
2046
$(M2_HOME)/be/docarch/oxt-maven-plugin/1.0-SNAPSHOT/oxt-maven-plugin-1.0-SNAPSHOT.jar : \
2147
utils/oxt-maven-plugin/pom.xml \
2248
$(call rwildcard,utils/oxt-maven-plugin/src/main/,*)
23-
cd $(dir $<) && $(MVN) clean install
49+
exec(new File("$(dir $<)"), "$(CURDIR)/$(SHELL)", $(call quote-for-java,$(mvn)), "--", "clean", "install");
2450

2551
$(M2_HOME)/be/docarch/l10n-maven-plugin/1.0-SNAPSHOT/l10n-maven-plugin-1.0-SNAPSHOT.jar : \
2652
utils/l10n-maven-plugin/pom.xml \
2753
$(call rwildcard,utils/l10n-maven-plugin/src/main/,*)
28-
cd $(dir $<) && $(MVN) clean install
54+
exec(new File("$(dir $<)"), "$(CURDIR)/$(SHELL)", $(call quote-for-java,$(mvn)), "--", "clean", "install");
2955

3056
$(M2_HOME)/com/github/maven-nar/nar-maven-plugin/3.5.3-SNAPSHOT/nar-maven-plugin-3.5.3-SNAPSHOT.jar : \
3157
utils/nar-maven-plugin/pom.xml \
3258
$(call rwildcard,utils/nar-maven-plugin/src/main/,*)
33-
cd $(dir $<) && $(MVN) clean install
59+
exec(new File("$(dir $<)"), "$(CURDIR)/$(SHELL)", $(call quote-for-java,$(mvn)), "--", "clean", "install");
3460

3561
ifneq (,$(findstring -SNAPSHOT,$(LOUIS_VERSION)))
3662
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-aarch64-MacOSX-gpp-shared.nar : \
3763
libs/liblouis/pom.xml \
3864
$(call rwildcard,libs/liblouis/src/,*)
39-
$(MAKE) -C $(dir $<) clean compile-macosx install
65+
exec("$(MAKE)", "-C", "$(dir $<)", "clean", "compile-macosx", "install");
4066
else
4167
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-aarch64-MacOSX-gpp-shared.nar :
42-
$(MVN) org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get \
43-
-Dartifact=org.liblouis:louis:$(LOUIS_VERSION):nar:aarch64-MacOSX-gpp-shared
68+
exec("$(SHELL)", $(call quote-for-java,$(mvn)), "--", \
69+
"org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get", \
70+
"-Dartifact=org.liblouis:louis:$(LOUIS_VERSION):nar:aarch64-MacOSX-gpp-shared");
4471
endif
4572

4673
ifneq (,$(findstring -SNAPSHOT,$(LOUISUTDML_VERSION)))
@@ -49,7 +76,7 @@ $(M2_HOME)/org/liblouis/louisutdml/$(LOUISUTDML_VERSION)/louisutdml-$(LOUISUTDML
4976
libs/liblouisutdml/pom.xml \
5077
$(call rwildcard,libs/liblouisutdml/src/,*) \
5178
$(M2_HOME)/com/github/maven-nar/nar-maven-plugin/3.5.3-SNAPSHOT/nar-maven-plugin-3.5.3-SNAPSHOT.jar
52-
$(MAKE) -C $(dir $<) clean compile-macosx install
79+
exec("$(MAKE)", "-C", "$(dir $<)", "clean", "compile-macosx", "install");
5380
endif
5481

5582
install-windows : \
@@ -58,27 +85,29 @@ install-windows : \
5885
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-i686-w64-mingw32-gpp-executable.nar \
5986
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-x86_64-w64-mingw32-gpp-executable.nar \
6087
$(M2_HOME)/org/liblouis/louisutdml/$(LOUISUTDML_VERSION)/louisutdml-$(LOUISUTDML_VERSION)-i686-w64-mingw32-gpp-executable.nar
61-
$(MVN) clean install -Pwindows_x86
88+
exec("$(SHELL)", $(call quote-for-java,$(mvn)), "--", "clean", "install", "-Pwindows_x86");
6289

6390
ifneq (,$(findstring -SNAPSHOT,$(LOUIS_VERSION)))
6491
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-i686-w64-mingw32-gpp-executable.nar \
6592
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-x86_64-w64-mingw32-gpp-executable.nar : \
6693
libs/liblouis/pom.xml \
6794
$(call rwildcard,libs/liblouis/src/,*)
68-
$(MAKE) -C $(dir $<) clean compile-windows install
95+
exec("$(MAKE)", "-C", "$(dir $<)", "clean", "compile-windows", "install");
6996
else
7097
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-i686-w64-mingw32-gpp-executable.nar :
71-
$(MVN) org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get \
72-
-Dartifact=org.liblouis:louis:$(LOUIS_VERSION):nar:i686-w64-mingw32-gpp-executable
98+
exec("$(SHELL)", $(call quote-for-java,$(mvn)), "--", \
99+
"org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get", \
100+
"-Dartifact=org.liblouis:louis:$(LOUIS_VERSION):nar:i686-w64-mingw32-gpp-executable");
73101
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-x86_64-w64-mingw32-gpp-executable.nar :
74-
$(MVN) org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get \
75-
-Dartifact=org.liblouis:louis:$(LOUIS_VERSION):nar:x86_64-w64-mingw32-gpp-executable
102+
exec("$(SHELL)", $(call quote-for-java,$(mvn)), "--", \
103+
"org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get", \
104+
"-Dartifact=org.liblouis:louis:$(LOUIS_VERSION):nar:x86_64-w64-mingw32-gpp-executable");
76105
endif
77106

78107
ifneq (,$(findstring -SNAPSHOT,$(LOUISUTDML_VERSION)))
79108
$(M2_HOME)/org/liblouis/louisutdml/$(LOUISUTDML_VERSION)/louisutdml-$(LOUISUTDML_VERSION)-i686-w64-mingw32-gpp-executable.nar : \
80109
libs/liblouisutdml/pom.xml \
81110
$(call rwildcard,libs/liblouisutdml/src/,*) \
82111
$(M2_HOME)/org/liblouis/louis/$(LOUIS_VERSION)/louis-$(LOUIS_VERSION)-i686-w64-mingw32-gpp-executable.nar
83-
$(MAKE) -C $(dir $<) clean compile-windows install
112+
exec("$(MAKE)", "-C", "$(dir $<)", "clean", "compile-windows", "install");
84113
endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/recipes/
2+
.DS_Store
14.1 KB
Binary file not shown.
82.5 KB
Binary file not shown.
17.3 KB
Binary file not shown.
70.5 KB
Binary file not shown.
228 KB
Binary file not shown.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
ifneq ($(firstword $(sort $(MAKE_VERSION) 3.82)), 3.82)
2+
$(error "GNU Make 3.82 is required to run this script")
3+
endif
4+
5+
ifneq (,$(findstring Windows,$(OS))$(findstring WINDOWS,$(OS)))
6+
EVAL_JAVA := $(dir $(lastword $(MAKEFILE_LIST)))bin/windows_amd64/eval-java.exe
7+
SHELL := $(EVAL_JAVA)
8+
else
9+
ifneq ($(patsubst %.exe,%,$(notdir $(SHELL))),eval-java)
10+
UNAME_S := $(shell uname -s)
11+
UNAME_P := $(shell uname -m)
12+
ifeq ($(UNAME_S),Darwin)
13+
ifneq ($(filter arm%,$(UNAME_P))$(filter aarch%,$(UNAME_P)),)
14+
EVAL_JAVA := $(dir $(lastword $(MAKEFILE_LIST)))bin/darwin_arm64/eval-java
15+
else
16+
EVAL_JAVA := $(dir $(lastword $(MAKEFILE_LIST)))bin/darwin_amd64/eval-java
17+
endif
18+
else
19+
ifneq ($(filter arm%,$(UNAME_P))$(filter aarch%,$(UNAME_P)),)
20+
EVAL_JAVA := $(dir $(lastword $(MAKEFILE_LIST)))bin/linux_arm64/eval-java
21+
else
22+
EVAL_JAVA := $(dir $(lastword $(MAKEFILE_LIST)))bin/linux_amd64/eval-java
23+
endif
24+
endif
25+
ifneq ($(shell \
26+
if ! $(EVAL_JAVA) --verify 2>/dev/null; then \
27+
echo "$(EVAL_JAVA) can not be executed on this platform. Compiling it from source" >&2; \
28+
echo "cc $(dir $(lastword $(MAKEFILE_LIST)))eval-java.c -o $(EVAL_JAVA)" >&2; \
29+
cc $(dir $(lastword $(MAKEFILE_LIST)))eval-java.c -o $(EVAL_JAVA); \
30+
fi; \
31+
echo $$? ),0)
32+
$(error Failed to compile eval-java.c)
33+
else
34+
SHELL := $(EVAL_JAVA)
35+
endif
36+
endif
37+
endif
38+
39+
.SHELLFLAGS :=
40+
41+
# Reset environment variables to avoid pass-through, when one Makefile
42+
# invokes make in another directory.
43+
CLASSPATH :=
44+
IMPORTS :=
45+
STATIC_IMPORTS :=
46+
JAVA_REPL_PORT :=
47+
unexport CLASSPATH IMPORTS STATIC_IMPORTS JAVA_REPL_PORT
48+
49+
JAVA_VERSION := $(shell println(getJavaVersion());)
50+
51+
ifeq ($(JAVA_VERSION),)
52+
# probably because java not found or exited with a UnsupportedClassVersionError
53+
$(error Java 8 is required to run this script)
54+
else ifeq ($(shell println($(JAVA_VERSION) >= 8);), false)
55+
$(error Java 8 is required to run this script)
56+
endif
57+
58+
OS := $(shell println(getOS());)
59+
60+
ifneq ($(OS), WINDOWS)
61+
export JAVA_REPL_KILL_AFTER_IDLE := 10
62+
# The following is not enabled by default, because starting the server
63+
# now means that any changes to environment variables after the
64+
# include of enable-java-shell.mk will not be noticed by
65+
# java-eval. This includes the environment variables JAVA_HOME, IMPORTS
66+
# and STATIC_IMPORTS, and any other environment variables used by a
67+
# recipe. Users may optionally include this line in their Makefile, at
68+
# a position of their liking.
69+
#export JAVA_REPL_PORT := $(shell --spawn-repl-server)
70+
endif
71+
72+
# utility function for helping with the migration from bash to java shell
73+
define \n
74+
75+
76+
endef
77+
quote-for-java = "$(subst ${\n},\n,$(subst ",\",$(subst \,\\,$(1))))"
78+
bash = exec("bash", "-c", $(call quote-for-java,$1));

0 commit comments

Comments
 (0)