From e80536ca309c45ffeba49c8c3e3e698ba6910203 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Thu, 27 Jan 2022 09:37:58 +0100 Subject: [PATCH] Introduce Makefile and JNI support --- Makefile | 10 ++ org.argeo.api.uuid/.cproject | 170 ++++++++++++++++++ org.argeo.api.uuid/.project | 16 ++ .../.settings/language.settings.xml | 28 +++ .../.settings/org.eclipse.cdt.core.prefs | 6 + org.argeo.api.uuid/META-INF/.gitignore | 1 + org.argeo.api.uuid/Makefile | 68 +++++++ .../libuuid_NativeUuidFactory.cpp | 1 + .../org_argeo_api_uuid_NativeUuidFactory.h | 45 +++++ .../org/argeo/api/uuid/NativeUuidFactory.java | 30 ++++ sdk.mk | 2 + 11 files changed, 377 insertions(+) create mode 100644 Makefile create mode 100644 org.argeo.api.uuid/.cproject create mode 100644 org.argeo.api.uuid/.settings/language.settings.xml create mode 100644 org.argeo.api.uuid/.settings/org.eclipse.cdt.core.prefs create mode 100644 org.argeo.api.uuid/META-INF/.gitignore create mode 100644 org.argeo.api.uuid/Makefile create mode 100644 org.argeo.api.uuid/jni/org_argeo_api_uuid/libuuid_NativeUuidFactory.cpp create mode 100644 org.argeo.api.uuid/jni/org_argeo_api_uuid/org_argeo_api_uuid_NativeUuidFactory.h create mode 100644 org.argeo.api.uuid/src/org/argeo/api/uuid/NativeUuidFactory.java create mode 100644 sdk.mk diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..d57f2a7e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +MAKEDIRS = org.argeo.api.uuid + +.PHONY: clean all +all: + $(foreach dir, $(MAKEDIRS), $(MAKE) -C $(dir);) + +clean: + $(foreach dir, $(MAKEDIRS), $(MAKE) -C $(dir) clean;) + +include sdk.mk \ No newline at end of file diff --git a/org.argeo.api.uuid/.cproject b/org.argeo.api.uuid/.cproject new file mode 100644 index 000000000..7acdcf500 --- /dev/null +++ b/org.argeo.api.uuid/.cproject @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + + + + ide + + true + + true + + true + + + + + + + + diff --git a/org.argeo.api.uuid/.project b/org.argeo.api.uuid/.project index be973cdee..764e6d106 100644 --- a/org.argeo.api.uuid/.project +++ b/org.argeo.api.uuid/.project @@ -5,6 +5,12 @@ + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + org.eclipse.jdt.core.javabuilder @@ -20,9 +26,19 @@ + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature diff --git a/org.argeo.api.uuid/.settings/language.settings.xml b/org.argeo.api.uuid/.settings/language.settings.xml new file mode 100644 index 000000000..8c583566d --- /dev/null +++ b/org.argeo.api.uuid/.settings/language.settings.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.argeo.api.uuid/.settings/org.eclipse.cdt.core.prefs b/org.argeo.api.uuid/.settings/org.eclipse.cdt.core.prefs new file mode 100644 index 000000000..c8ec5df2d --- /dev/null +++ b/org.argeo.api.uuid/.settings/org.eclipse.cdt.core.prefs @@ -0,0 +1,6 @@ +doxygen/doxygen_new_line_after_brief=true +doxygen/doxygen_use_brief_tag=false +doxygen/doxygen_use_javadoc_tags=true +doxygen/doxygen_use_pre_tag=false +doxygen/doxygen_use_structural_commands=false +eclipse.preferences.version=1 diff --git a/org.argeo.api.uuid/META-INF/.gitignore b/org.argeo.api.uuid/META-INF/.gitignore new file mode 100644 index 000000000..4c36ca982 --- /dev/null +++ b/org.argeo.api.uuid/META-INF/.gitignore @@ -0,0 +1 @@ +x86_64/ \ No newline at end of file diff --git a/org.argeo.api.uuid/Makefile b/org.argeo.api.uuid/Makefile new file mode 100644 index 000000000..093701fbd --- /dev/null +++ b/org.argeo.api.uuid/Makefile @@ -0,0 +1,68 @@ +include ../sdk.mk + +NATIVE_PACKAGE=org_argeo_api_uuid +TARGET_EXEC := libJava_$(NATIVE_PACKAGE).so + +SRC_DIRS := ./jni/$(NATIVE_PACKAGE) + +LDFLAGS=-shared -fPIC -Wl,-soname,$(TARGET_EXEC).$(MAJOR).$(MINOR) + +# +# Generic Argeo +# +BUILD_DIR := ./generated +META_INF_DIR := ./META-INF +ARCH := $(shell uname -p) + +# Every folder in ./src will need to be passed to GCC so that it can find header files +INC_DIRS := $(shell find $(SRC_DIRS) -type d) /usr/lib/jvm/java/include /usr/lib/jvm/java/include/linux + +.PHONY: clean all ide +all: $(BUILD_DIR)/$(TARGET_EXEC) + +ide: $(META_INF_DIR)/$(ARCH)/$(TARGET_EXEC) + +$(META_INF_DIR)/$(ARCH)/$(TARGET_EXEC): $(BUILD_DIR)/$(TARGET_EXEC) + mkdir -p $(dir $@) + cp $(BUILD_DIR)/$(TARGET_EXEC) $(dir $@) + +# Find all the C and C++ files we want to compile +# Note the single quotes around the * expressions. Make will incorrectly expand these otherwise. +SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s') + +# String substitution for every C/C++ file. +# As an example, hello.cpp turns into ./build/hello.cpp.o +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) + +# String substitution (suffix version without %). +# As an example, ./build/hello.cpp.o turns into ./build/hello.cpp.d +DEPS := $(OBJS:.o=.d) + +# Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) + +# The -MMD and -MP flags together generate Makefiles for us! +# These files will have .d instead of .o as the output. +CPPFLAGS := $(INC_FLAGS) -MMD -MP + +# The final build step. +$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) + $(CC) $(OBJS) -o $@ $(LDFLAGS) + +# Build step for C source +$(BUILD_DIR)/%.c.o: %.c + mkdir -p $(dir $@) + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +# Build step for C++ source +$(BUILD_DIR)/%.cpp.o: %.cpp + mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -r $(BUILD_DIR) + +# Include the .d makefiles. The - at the front suppresses the errors of missing +# Makefiles. Initially, all the .d files will be missing, and we don't want those +# errors to show up. +-include $(DEPS) \ No newline at end of file diff --git a/org.argeo.api.uuid/jni/org_argeo_api_uuid/libuuid_NativeUuidFactory.cpp b/org.argeo.api.uuid/jni/org_argeo_api_uuid/libuuid_NativeUuidFactory.cpp new file mode 100644 index 000000000..2930397c2 --- /dev/null +++ b/org.argeo.api.uuid/jni/org_argeo_api_uuid/libuuid_NativeUuidFactory.cpp @@ -0,0 +1 @@ +#include "../../jni/org_argeo_api_uuid/org_argeo_api_uuid_NativeUuidFactory.h" diff --git a/org.argeo.api.uuid/jni/org_argeo_api_uuid/org_argeo_api_uuid_NativeUuidFactory.h b/org.argeo.api.uuid/jni/org_argeo_api_uuid/org_argeo_api_uuid_NativeUuidFactory.h new file mode 100644 index 000000000..bdf334ab5 --- /dev/null +++ b/org.argeo.api.uuid/jni/org_argeo_api_uuid/org_argeo_api_uuid_NativeUuidFactory.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_argeo_api_uuid_NativeUuidFactory */ + +#ifndef _Included_org_argeo_api_uuid_NativeUuidFactory +#define _Included_org_argeo_api_uuid_NativeUuidFactory +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_argeo_api_uuid_NativeUuidFactory + * Method: timeUUID + * Signature: ()Ljava/util/UUID; + */ +JNIEXPORT jobject JNICALL Java_org_argeo_api_uuid_NativeUuidFactory_timeUUID + (JNIEnv *, jobject); + +/* + * Class: org_argeo_api_uuid_NativeUuidFactory + * Method: nameUUIDv5 + * Signature: (Ljava/util/UUID;[B)Ljava/util/UUID; + */ +JNIEXPORT jobject JNICALL Java_org_argeo_api_uuid_NativeUuidFactory_nameUUIDv5 + (JNIEnv *, jobject, jobject, jbyteArray); + +/* + * Class: org_argeo_api_uuid_NativeUuidFactory + * Method: nameUUIDv3 + * Signature: (Ljava/util/UUID;[B)Ljava/util/UUID; + */ +JNIEXPORT jobject JNICALL Java_org_argeo_api_uuid_NativeUuidFactory_nameUUIDv3 + (JNIEnv *, jobject, jobject, jbyteArray); + +/* + * Class: org_argeo_api_uuid_NativeUuidFactory + * Method: randomUUIDStrong + * Signature: ()Ljava/util/UUID; + */ +JNIEXPORT jobject JNICALL Java_org_argeo_api_uuid_NativeUuidFactory_randomUUIDStrong + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/org.argeo.api.uuid/src/org/argeo/api/uuid/NativeUuidFactory.java b/org.argeo.api.uuid/src/org/argeo/api/uuid/NativeUuidFactory.java new file mode 100644 index 000000000..21e0eb184 --- /dev/null +++ b/org.argeo.api.uuid/src/org/argeo/api/uuid/NativeUuidFactory.java @@ -0,0 +1,30 @@ +package org.argeo.api.uuid; + +import java.util.UUID; + +/** An {@link UuidFactory} based on a native library. */ +public class NativeUuidFactory implements UuidFactory, TypedUuidFactory { + + @Override + public UUID get() { + return timeUUID(); + } + + @Override + public native UUID timeUUID(); + + @Override + public native UUID nameUUIDv5(UUID namespace, byte[] data); + + @Override + public native UUID nameUUIDv3(UUID namespace, byte[] data); + + @Override + public native UUID randomUUIDStrong(); + + @Override + public UUID randomUUIDWeak() { + throw new UnsupportedOperationException(); + } + +} diff --git a/sdk.mk b/sdk.mk new file mode 100644 index 000000000..7a7e579b7 --- /dev/null +++ b/sdk.mk @@ -0,0 +1,2 @@ +MAJOR=2 +MINOR=3 -- 2.30.2