# <module>_JARFLAGS
# <module>_JMODFLAGS
-# <module>_JAVA Java sources. If not set it is found from src/<module>/classes/(*.java)
-# <module>_RESOURCES .jar resources. If not set it is found from src/<module>/classes/(not *.java)
+# <module>_JAVA Java sources. If not set it is found from src/<module>/classes/(*.java)
+# <module>_RESOURCES .jar resources. If not set it is found from src/<module>/classes/(not *.java)
# <module>_JAVA_GENERATED Java generated sources. These must be relative to the package name.
# Variables for use in fragments
# bin/gen/<module>/gen/ .c, exe files for generator free use
# bin/gen/<module>/classes/ .java files from generator <module>_JAVA_GENERATED
+# Working files
# bin/status/ marker files for makefile
-# bin/<module>/<module>.jar .jar modular
-
-# Native code
-
# bin/<module>/<target>/lib .so librareies for jmod <module>_LIBRARIES = libname
# bin/<module>/<target>/obj .o, .d files for library <libname>_SOURCES
# bin/<module>/<target>/include .h files for jmod <libname>_HEADERS
# bin/<module>/<target>/<module>.jmod .jmod module
+# Output files
+# bin/<target>/lib/ modular jar files and shared libraries for GNU/linux dev
+# bin/<target>/include/ header files for exported shared libraries
+# bin/<target>/bin/ shared libraries for microsoft dev
+# bin/<target>/jmods/ jmod files for 'jlink' use.
+
# ######################################################################
E:=
endif
endef
+java_libdir:=$(if $(filter windows-%,$(TARGET)),bin/$(TARGET)/bin,bin/$(TARGET)/lib)
+java_bindir:=bin/$(TARGET)/bin
+java_jardir:=bin/$(TARGET)/lib
+java_incdir:=bin/$(TARGET)/include
+java_jmoddir:=bin/$(TARGET)/jmods
+
$(foreach module,$(java_MODULES),$(eval $(call java_variables,$(module))))
# ######################################################################
bin/status/$(1).data: $$($(1)_RESOURCES)
bin/status/$(1).classes: $(patsubst %,bin/status/%.classes,$($(1)_JDEPMOD)) $$($(1)_JAVA) $$($(1)_JAVA_generated)
-jar $(1): bin/$(1)/$(1).jar $(if $(wildcard src/$(1)/jni/jni.make),bin/$(1)/$(TARGET)/$(1).jmod)
+jar $(1): $(java_jardir)/$(1).jar $(java_jmoddir)/$(1).jmod
bin: bin/status/$(1).classes bin/status/$(1).data
-sources: bin/$(1)/$(1)-sources.zip
+sources: $(java_jardir)/$(1)-sources.zip
gen: $$($(1)_JAVA_generated)
# Create modular jar
-bin/$(1)/$(1).jar: bin/status/$(1).classes bin/status/$(1).data
+$(java_jardir)/$(1).jar: bin/status/$(1).classes bin/status/$(1).data
@install -d $$(@D)
$(JAR) cf $$@ \
$(JARFLAGS) $$($(1)_JARFLAGS) \
-C bin/modules/$(1) .
# Create a jmod
-bin/$(1)/$(TARGET)/$(1).jmod: bin/status/$(1).classes bin/status/$(1).data
+$(java_jmoddir)/$(1).jmod: bin/status/$(1).classes bin/status/$(1).data
rm -f $$@
@install -d $$(@D)
$$(JMOD) create \
--class-path bin/modules/$(1) \
$$(if $$(wildcard bin/$(1)/$(TARGET)/include),--header-files bin/$(1)/$(TARGET)/include) \
$$(if $$(wildcard src/$(1)/legal),--legal-notices src/$(1)/legal) \
- $$(if $$(wildcard $$($(1)_bindir)),--cmds $$($(1)_bindir)) \
- $$(if $$(wildcard $$($(1)_libdir)),--libs $$($(1)_libdir)) \
+ $$(if $$(wildcard bin/$(1)/$(TARGET)/bin),--cmds bin/$(1)/$(TARGET)/bin) \
+ $$(if $$(wildcard bin/$(1)/$(TARGET)/lib),--libs bin/$(1)/$(TARGET)/lib) \
$$@
# Create an IDE source zip, paths have to match --module-source-path
-bin/$(1)/$(1)-sources.zip: bin/status/$(1).classes
+$(java_jardir)/$(1)-sources.zip: bin/status/$(1).classes
@install -d $$(@D)
jar -c -f $$@ -M \
$$(patsubst src/$(1)/classes/%,-C src/$(1)/classes %,$$(filter src/$(1)/classes/%,$$($(1)_JAVA))) \
@install -d $(@D)
$(JAVAC) \
--module-source-path "src/*/classes:bin/gen/*/classes" \
+ $(if $(JAVAMODPATH),--module-path $(subst $(S),:,$(JAVAMODPATH))) \
$(JAVACFLAGS) $($*_JAVACFLAGS) \
-h bin/inc \
-d bin/modules \
LIB=$($(TARGET)_LIB)
# functions to find cross-module stuff $(call library-path,modname,libname)
-library-path=bin/$(1)/$(TARGET)/lib/$(LIB)$(2)$(SO)
-library-dir=bin/$(1)/$(TARGET)/lib/
+library-path=$($(1)_libdir)/$(LIB)$(2)$(SO)
+library-dir=$($(1)_libdir)/
define jni_library=
# Rule for library $(2) in module $(1)
$(2)_OBJS = $(foreach sx,$(SUFFIXES),$(patsubst %$(sx), $($(1)_objdir)/%.o, $(filter %$(sx),$($(2)_SOURCES))))
$(2)_SRCS = $(addprefix src/$(1)/jni/,$($(2)_SOURCES))
+$(2)_SO = $($(1)_libdir)/$(LIB)$(2)$(SO)
$($(1)_libdir)/$(LIB)$(2)$(SO): $$($(2)_OBJS) $($(2)_LIBADD) $($(2)_DEPENDENCIES)
@install -d $$(@D)
$($(TARGET)_CC) -o $$@ -shared \
$($(TARGET)_LDFLAGS) $($(2)_LDFLAGS) $$($(2)_OBJS) $($(2)_LIBADD) $($(TARGET)_LDLIBS) $($(2)_LDLIBS)
+$(java_libdir)/%: $($(1)_libdir)/%
+ install -DC $$< $$@
+$(java_bindir)/%: $($(1)_bindir)/%
+ install -DC $$< $$@
+$(java_incdir)/%: $($(1)_incdir)/%
+ install -DC $$< $$@
+
$($(1)_objdir)/%.o: src/$(1)/jni/%.c bin/status/$(1).classes
@install -d $$(@D)
- $($(TARGET)_CC) -Isrc/$(1)/jni -Ibin/include/$(1) $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) \
+ $($(TARGET)_CC) -Isrc/$(1)/jni -Ibin/include/$(1) -I$($(1)_jnidir) \
+ $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) \
$($(TARGET)_CFLAGS) $($(2)_CFLAGS) -c -o $$@ $$<
$($(1)_incdir)/%.h: src/$(1)/jni/%.h
- install -D $$< $$@
+ install -DC $$< $$@
$($(1)_objdir)/%.d: src/$(1)/jni/%.c bin/status/$(1).classes
@install -d $$(@D)
$($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) $$< -o $$@.d 2>/dev/null
@sed 's,\($$*\.o\) *:,\1 $$@ : ,g' $$@.d > $$@ ; rm $$@.d
-bin jni $(1) bin/$(1)/$(TARGET)/$(1).jmod: $($(1)_libdir)/$(LIB)$(2)$(SO) \
+bin jni $(1) $(java_jmoddir)/$(1).jmod: \
+ $($(1)_libdir)/$(LIB)$(2)$(SO) \
+ $(java_libdir)/$(LIB)$(2)$(SO) \
$(addprefix $($(1)_incdir)/,$($(2)_HEADERS)) \
- $(addprefix $($(1)_bindir)/,$($(2)_COMMANDS))
+ $(addprefix $(java_incdir)/,$($(2)_HEADERS)) \
+ $(addprefix $($(1)_bindir)/,$($(2)_COMMANDS)) \
+ $(addprefix $(java_bindir)/,$($(2)_COMMANDS)) \
+ $$(addprefix $($(1)_libdir)/,$$($(2)_LIBRARIES))
$(if $(filter clean dist gen,$(MAKECMDGOALS)),,-include $$($(2)_OBJS:.o=.d))
endef