Skip to content

Commit

Permalink
Improved build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlauer committed Oct 30, 2023
1 parent 9d6d143 commit 98705ce
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
17 changes: 13 additions & 4 deletions .blaze/blaze.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void build_natives() throws Exception {
final String targetStr = Contexts.config().value("target").orNull();
final NativeTarget nativeTarget = targetStr != null ? NativeTarget.fromJneTarget(targetStr) : NativeTarget.detect();

log.info("Building natives for target {}", nativeTarget.toJneTarget());
log.info("Copying native code to (cleaned) {} directory...", targetDir);
rm(targetDir).recursive().force().run();
mkdir(targetDir).parents().run();
Expand All @@ -46,11 +47,17 @@ public void build_natives() throws Exception {
.verbose()
.run();
} else {
String cmd = "make";
// freebsd and openbsd, we need to use gmake
if (nativeTarget.getOperatingSystem() == OperatingSystem.FREEBSD || nativeTarget.getOperatingSystem() == OperatingSystem.OPENBSD) {
cmd = "gmake";
}

log.info("Building jcat executable...");
exec("make").workingDir(targetJcatDir).debug().run();
exec(cmd).workingDir(targetJcatDir).debug().run();

log.info("Building helloj library...");
exec("make").workingDir(targetLibHelloJDir).debug().run();
exec(cmd).workingDir(targetLibHelloJDir).debug().run();
}

cp(targetJcatDir.resolve(exename)).target(javaOutputDir).force().verbose().run();
Expand Down Expand Up @@ -258,14 +265,16 @@ public void cross_build_natives() throws Exception {
new Buildx(crossTargets)
.tags("build")
.execute((target, project) -> {
String buildScript = "setup/build-native-lib-linux-action.sh";
/*String buildScript = "setup/build-native-lib-linux-action.sh";
if (target.getOs().equals("macos")) {
buildScript = "setup/build-native-lib-macos-action.sh";
} else if (target.getOs().equals("windows")) {
buildScript = "setup/build-native-lib-windows-action.bat";
}
project.action(buildScript, target.getOs(), target.getArch()).run();
project.action(buildScript, target.getOs(), target.getArch()).run();*/

project.action("java", "-jar", "blaze.jar", "build_natives", "--target", target.getOsArch()).run();

// we know that the only modified file will be in the artifact dir
final String artifactRelPath = "src/test/resources/jne/" + target.getOs() + "/" + target.getArch() + "/";
Expand Down
8 changes: 0 additions & 8 deletions native/jcat/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#
# To run this in your own shell
# CC=gcc make
#

#CC = gcc
#CPP = g++

all:
$(CC) -Wall -pedantic -O2 -o jcat jcat.c

Expand Down
18 changes: 17 additions & 1 deletion native/libhelloj/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,29 @@ JAVA ?= java
SHAREDFILEEXT ?= so
UNAME_S := $(shell uname -s)
EXTRA_CXXFLAGS := -z noexecstack
CXXFLAGS :=
CFLAGS :=
JAVA_INCLUDE := -I${JAVA_HOME}/include
ifeq ($(UNAME_S),Darwin)
JAVA_INCLUDE := ${JAVA_INCLUDE} -I${JAVA_HOME}/include/darwin
SHAREDFILEEXT = dylib
EXTRA_CXXFLAGS =
endif
ifeq ($(UNAME_S),Linux)
JAVA_INCLUDE := ${JAVA_INCLUDE} -I${JAVA_HOME}/include/linux
endif
ifeq ($(UNAME_S),FreeBSD)
JAVA_INCLUDE := ${JAVA_INCLUDE} -I${JAVA_HOME}/include/freebsd
CXX = clang++
endif
ifeq ($(UNAME_S),OpenBSD)
JAVA_INCLUDE := ${JAVA_INCLUDE} -I${JAVA_HOME}/include/openbsd
EXTRA_CXXFLAGS =
CXX = clang++
endif

all:
$(CXX) -shared -fPIC -Wall -pedantic -O3 $(CXXFLAGS) $(EXTRA_CXXFLAGS) -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -I${JAVA_HOME}/include/darwin -I${JAVA_HOME}/include/freebsd -I${JAVA_HOME}/include/openbsd -o libhelloj.$(SHAREDFILEEXT) -lc helloj_HelloLib.cpp
$(CXX) -shared -fPIC -Wall -pedantic -O3 $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(JAVA_INCLUDE) -o libhelloj.$(SHAREDFILEEXT) -lc helloj_HelloLib.cpp

jniheaders:
$(JAVAC) -h . helloj/HelloLib.java
Expand Down
Binary file modified src/test/resources/jne/linux/x64/jcat
Binary file not shown.
Binary file modified src/test/resources/jne/linux/x64/libhelloj.so
Binary file not shown.

0 comments on commit 98705ce

Please sign in to comment.