SDK system based on Makefiles
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 27 Jan 2022 11:21:56 +0000 (12:21 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 27 Jan 2022 11:21:56 +0000 (12:21 +0100)
.gitignore
Makefile
branch.properties [new file with mode: 0644]
configure [new file with mode: 0644]
org.argeo.api.uuid/Makefile
org.argeo.api.uuid/jni/org_argeo_api_uuid/Makefile [new file with mode: 0644]
sdk.mk [deleted file]
sdk/includes.mk [new file with mode: 0644]
sdk/jni.mk [new file with mode: 0644]

index 492e809ea5293775af439187d46c91da46ee80da..fab481bb9c01ab487f850dc09c19c6905c4e9e10 100644 (file)
@@ -2,3 +2,5 @@
 **/target/
 **/generated/
 **/MANIFEST.MF
+/build/
+/sdk.mk
index d57f2a7e6d40f67137af708eb83a0ae61cc4f9e2..649560c5ae33bc0866a268daa55001483551b54d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
 MAKEDIRS = org.argeo.api.uuid
 
+BUILD_BASE=generated
+
 .PHONY: clean all
 all:
        $(foreach dir, $(MAKEDIRS), $(MAKE) -C $(dir);)
@@ -7,4 +9,3 @@ all:
 clean:
        $(foreach dir, $(MAKEDIRS), $(MAKE) -C $(dir) clean;)
 
-include sdk.mk 
\ No newline at end of file
diff --git a/branch.properties b/branch.properties
new file mode 100644 (file)
index 0000000..7a7e579
--- /dev/null
@@ -0,0 +1,2 @@
+MAJOR=2
+MINOR=3
diff --git a/configure b/configure
new file mode 100644 (file)
index 0000000..c92fa22
--- /dev/null
+++ b/configure
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+# We build where we are
+SDK_BUILD_BASE=$(pwd -P)/build
+
+# Source are located where this script is
+SDK_SRC_BASE="$(cd "$(dirname "$0")"; pwd -P)"
+
+SDK_MK=$SDK_SRC_BASE/sdk.mk
+
+#echo SDK_BUILD_BASE=$SDK_BUILD_BASE
+#echo SDK_SRC_BASE=$SDK_SRC_BASE
+#echo SDK_MK=$SDK_MK
+
+if [ -f "$SDK_MK" ]; 
+then
+
+echo "File $SDK_MK already exists. Remove it in order to configure a new build location:"
+echo "rm $SDK_MK"
+exit 1
+
+else
+
+# Create build directory, so that it can be used right away
+# and we check whether we have the rights
+mkdir -p $SDK_BUILD_BASE
+if [ -f "$SDK_MK" ];
+then
+echo "Cannot create $SDK_BUILD_BASE, SDK configuration has failed."
+exit 2
+fi
+
+# Generate sdk.mk
+cat > "$SDK_MK" <<EOF
+SDK_SRC_BASE := $SDK_SRC_BASE
+SDK_BUILD_BASE := $SDK_BUILD_BASE
+
+include \$(SDK_SRC_BASE)/branch.properties
+include \$(SDK_SRC_BASE)/sdk/includes.mk
+EOF
+
+
+echo SDK was configured.
+echo "Base for sources : $SDK_SRC_BASE"
+echo "Base for builds  : $SDK_BUILD_BASE"
+exit 0
+fi
+
index 093701fbd14fd5348e4e4ea35129c15003807ec0..3feb61027a6d45d5e55e3b3133ebf6c7d393fff8 100644 (file)
@@ -1,68 +1,23 @@
-include ../sdk.mk
+JNIDIRS = org_argeo_api_uuid
 
-NATIVE_PACKAGE=org_argeo_api_uuid
-TARGET_EXEC := libJava_$(NATIVE_PACKAGE).so
+.PHONY: clean all jni
 
-SRC_DIRS := ./jni/$(NATIVE_PACKAGE)
+all: jni
 
-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 $@
+jni:
+       $(foreach dir, jni/$(JNIDIRS), $(MAKE) -C $(dir);)
+       
+clean:
+       $(foreach dir, jni/$(JNIDIRS), $(MAKE) -C $(dir) clean;)
 
-# Build step for C++ source
-$(BUILD_DIR)/%.cpp.o: %.cpp
-       mkdir -p $(dir $@)
-       $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
+#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 $@)
 
-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
+%:
+       @echo Making '$@' $(if $^,from '$^')
+       @echo 'OBJ=$(OBJ)'
+       @echo 'DEP=$(DEP)'
diff --git a/org.argeo.api.uuid/jni/org_argeo_api_uuid/Makefile b/org.argeo.api.uuid/jni/org_argeo_api_uuid/Makefile
new file mode 100644 (file)
index 0000000..1c45b52
--- /dev/null
@@ -0,0 +1,5 @@
+NATIVE_PACKAGE := org_argeo_api_uuid
+
+#include ../../../branch.mk
+include ../../../sdk.mk
+
diff --git a/sdk.mk b/sdk.mk
deleted file mode 100644 (file)
index 7a7e579..0000000
--- a/sdk.mk
+++ /dev/null
@@ -1,2 +0,0 @@
-MAJOR=2
-MINOR=3
diff --git a/sdk/includes.mk b/sdk/includes.mk
new file mode 100644 (file)
index 0000000..8f1aeda
--- /dev/null
@@ -0,0 +1 @@
+include $(SDK_SRC_BASE)/sdk/jni.mk
diff --git a/sdk/jni.mk b/sdk/jni.mk
new file mode 100644 (file)
index 0000000..e22460d
--- /dev/null
@@ -0,0 +1,72 @@
+TARGET_EXEC := libJava_$(NATIVE_PACKAGE).so
+
+BASE_DIR := $(shell realpath .)
+SRC_DIRS := . 
+
+LDFLAGS=-shared -fPIC -Wl,-soname,$(TARGET_EXEC).$(MAJOR).$(MINOR)
+
+%:
+       @echo Making '$@' $(if $^,from '$^')
+       @echo 'MAJOR=$(MAJOR)'
+       @echo 'MINOR=$(MINOR)'
+       @echo 'BASE_DIR=$(BASE_DIR)'
+       @echo 'SRC_DIRS=$(BASE_DIR)'
+       @echo 'BUILD_DIR=$(BUILD_DIR)'
+       @echo 'MAKEFILE_DIR=$(MAKEFILE_DIR)'
+       
+
+#
+# Generic Argeo
+#
+BUILD_DIR := $(SDK_BUILD_BASE)/$(NATIVE_PACKAGE)
+#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)
+
+# 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)
+
+# MAKEFILE_DIR := $(dir $(firstword $(MAKEFILE_LIST)))