include $(foreach module,$(java_MODULES),$(wildcard src/$(module)/gen/gen.make))
include $(foreach module,$(java_MODULES) $(native_MODULES),$(wildcard src/$(module)/native/native.make))
+# staging only, not for modules, not sure here?
+define bin_files_targets=
+bin $1: $(patsubst src/$1/bin/%,bin/$(TARGET)/bin/%,$($1_SCRIPTS))
+bin/$(TARGET)/bin/%: src/$1/bin/%
+ install -vD -m 0755 $$< $$@
+endef
+define lib_files_targets=
+bin $1: $(patsubst src/$1/lib/%,bin/$(TARGET)/lib/%,$($1_DATA))
+bin/$(TARGET)/lib/%: src/$1/lib/%
+ install -vD -m 0644 $$< $$@
+endef
+
+#$(foreach module,$(java_MODULES),$(if $($(module)_SCRIPTS),$(info $(call bin_files_targets,$(module)))))
+#$(foreach module,$(java_MODULES),$(if $($(module)_DATA),$(info $(call lib_files_targets,$(module)))))
+
+$(foreach module,$(java_MODULES),$(if $($(module)_SCRIPTS),$(eval $(call bin_files_targets,$(module)))))
+$(foreach module,$(java_MODULES),$(if $($(module)_DATA),$(eval $(call lib_files_targets,$(module)))))
+
+$(error)
+
# ######################################################################
# Java
# ######################################################################
define java_targets=
# Rules for module $(1)
-$(1)_JAVA_generated = $$(addprefix $$($(1)_genjavadir)/,$$($(1)_JAVA_GENERATED))
+$(1)_JAVA_generated = $$(addprefix $$($1_genjavadir)/,$$($1_JAVA_GENERATED))
-bin/status/$(1).data: $$($(1)_RESOURCES)
-bin/status/$(1).classes: $(patsubst %,bin/status/%.classes,$(filter $($(1)_JDEPMOD), $(java_MODULES))) $$($(1)_JAVA) $$($(1)_JAVA_generated)
-bin/status/$(1).scripts: $$($(1)_DATA) $$($(1)_SCRIPTS)
-jar $(1): $(java_jardir)/$(1).jar $(java_jmoddir)/$(1).jmod bin/status/$(1).scripts $($(1)_JDEPMOD)
-bin: bin/status/$(1).classes bin/status/$(1).data bin/status/$(1).scripts
+bin/status/$1.classes: $(patsubst %,bin/status/%.classes,$(filter $($1_JDEPMOD), $(java_MODULES))) $$($1_JAVA) $$($1_JAVA_generated)
+
+jar $1: $(java_jardir)/$1.jar $(java_jmoddir)/$1.jmod
+$1: $(filter $($1_JDEPMOD), $(native_MODULES))
+bin: bin/status/$(1).classes $$($1_resources_files)
sources: $(java_jardir)/$(1)-sources.zip
gen: $$($(1)_JAVA_generated)
+$(java_jardir)/$1.jar $(java_jmoddir)/$1.jmod: bin/status/$1.classes $(patsubst src/$1/classes/%,%,$($1_RESOURCES))
+
# Create modular jar
-$(java_jardir)/$(1).jar: bin/status/$(1).classes bin/status/$(1).data
+$(java_jardir)/$1.jar:
@install -d $$(@D)
$(JAR) cf $$@ \
$(JARFLAGS) $$($(1)_JARFLAGS) \
-C bin/modules/$(1) .
# Create a jmod
-$(java_jmoddir)/$(1).jmod: bin/status/$(1).classes bin/status/$(1).data
+$(java_jmoddir)/$1.jmod:
rm -f $$@
@install -d $$(@D)
$$(JMOD) create \
$$@
# Create an IDE source zip, paths have to match --module-source-path
-$(java_jardir)/$(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))) \
- $$(patsubst bin/gen/$(1)/classes/%,-C bin/gen/$(1)/classes %,$$(filter bin/gen/$(1)/classes/%,$$($(1)_JAVA)))
+ $$(patsubst src/$1/classes/%,-C src/$1/classes %,$$(filter src/$1/classes/%,$$($1_JAVA))) \
+ $$(patsubst bin/gen/$1/classes/%,-C bin/gen/$1/classes %,$$(filter bin/gen/$1/classes/%,$$($1_JAVA)))
-endef
+# resources
+bin/modules/$1/%: src/$1/classes/%
+ install -vDC $$< $$@
-#$(foreach module,$(java_MODULES),$(info $(call java_targets,$(module))))
-$(foreach module,$(java_MODULES),$(eval $(call java_targets,$(module))))
-
-# ######################################################################
-# Global pattern rules
-
-# Stage resources
-bin/status/%.data:
- @install -d $(@D)
- for data in $(patsubst src/$*/classes/%,"%",$($*_RESOURCES)) ; do \
- install -vDC "src/$*/classes/$$data" "bin/modules/$*/$$data" || exit 1 ; \
- done
- touch $@
-
-# Stage scripts and data
-bin/status/%.scripts:
- @install -d $(@D)
- for data in $(patsubst src/$*/lib/%,"%",$($*_DATA)) ; do \
- install -vDC -m 0644 "src/$*/lib/$$data" "bin/$(TARGET)/lib/$$data" || exit 1 ; \
- done
- for data in $(patsubst src/$*/bin/%,"%",$($*_SCRIPTS)) ; do \
- install -vDC -m 0755 "src/$*/bin/$$data" "bin/$(TARGET)/bin/$$data" || exit 1 ; \
- done
- touch $@
-
-# Compile one module.
-bin/status/%.classes:
- @install -d $(@D)
+# Compile module.
+bin/status/$1.classes:
+ @install -d $$(@D)
$(JAVAC) \
--module-source-path "src/*/classes:bin/gen/*/classes" \
$(if $(JAVAMODPATH),--module-path $(subst $(S),:,$(JAVAMODPATH))) \
- $(JAVACFLAGS) $($*_JAVACFLAGS) \
+ $(JAVACFLAGS) $($1_JAVACFLAGS) \
-d bin/modules \
- -m $* \
- $($*_JAVA) $($*_JAVA_generated)
- touch $@
+ -m $1 \
+ $($1_JAVA) $($1_JAVA_generated)
+ touch $$@
+endef
+
+#$(foreach module,$(java_MODULES),$(info $(call java_targets,$(module))))
+$(foreach module,$(java_MODULES),$(eval $(call java_targets,$(module))))
# setup run-* targets
define run_targets=
$(foreach module,$(java_MODULES),$(foreach main,$($(module)_JMAIN),$(eval $(call run_targets,$(module),$(main)))))
# ######################################################################
-# nativez jdk.foreign export tool via _API variables
+# notzed.nativez jdk.foreign export tool via _API variables
# ######################################################################
# <module>_API List of api's to include
# <module>_<api>_APIFLAGS Extra flags to pass to export-api for each api
define export_targets=
-gen: bin/status/$2.export
bin/status/$1.classes: bin/status/$2.export
-bin/status/$2.export: src/$1/gen/$2.api src/$1/gen/$2.h $(NATIVEZ_HOME)/bin/export-api
+bin/status/$2.export:
mkdir -p bin/gen/$1/gen bin/status
- $(NATIVEZ_HOME)/bin/export-api -w bin/gen/$1/gen -d bin/gen/$1/classes $($1_APIFLAGS) $($1_$2_APIFLAGS) $$<
+ $(NATIVEZ_HOME)/bin/export-api \
+ -w bin/gen/$1/gen -d bin/gen/$1/classes $($1_APIFLAGS) $($1_$2_APIFLAGS) src/$1/gen/$2.api
touch $$@
+
+bin/status/$2.export.d:
+ @$(NATIVEZ_HOME)/bin/export-api -M -MT "$$(@:.d=) $$@" -MF $$@ \
+ -w bin/gen/$1/gen -d bin/gen/$1/classes $($1_APIFLAGS) $($1_$2_APIFLAGS) src/$1/gen/$2.api 2>/dev/null
+
+$(if $(filter clean dist gen,$(MAKECMDGOALS)),,-include bin/status/$2.export.d)
endef
#$(foreach module,$(java_MODULES),$(if $($(module)_API),$(foreach api,$($(module)_API),$(info $(call export_targets,$(module),$(api))))))
$($(1)_objdir)/%.d: src/$(1)/native/%.c
@install -d $$(@D)
@rm -f $$@
- @$($(TARGET)_CC) -MM -MT "bin/$(1)/$(TARGET)/obj/$$*.o" -Isrc/$(1)/jni -Ibin/include/$(1) \
- $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) $$< -o $$@.d 2>/dev/null
- @sed 's,\($$*\.o\) *:,\1 $$@ : ,g' $$@.d > $$@ ; rm $$@.d
+ @$($(TARGET)_CC) -MM -MT "$$(@:.d=.o) $$@" -Isrc/$(1)/jni -Ibin/include/$(1) \
+ $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) $$< -o $$@ 2>/dev/null
# auto-dependencies for c++ files
$($(1)_objdir)/%.d: src/$(1)/native/%.cc
@install -d $$(@D)
@rm -f $$@
- @$($(TARGET)_CXX) -MM -MT "bin/$(1)/$(TARGET)/obj/$$*.o" -Isrc/$(1)/jni -Ibin/include/$(1) \
- $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) $$< -o $$@.d
- @sed 's,\($$*\.o\) *:,\1 $$@ : ,g' $$@.d > $$@ ; rm $$@.d
+ @$($(TARGET)_CXX) -MM -MT "$$(@:.d=.o) $$@" -Isrc/$(1)/jni -Ibin/include/$(1) \
+ $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) $$< -o $$@ 2>/dev/null
bin native $(1) $(java_jmoddir)/$(1).jmod: \
$($(1)_libdir)/$(LIB)$(2)$(SO) \
use strict;
use File::Basename;
-#use autodie qw(system); # super-ugly and unecessary output though
+use File::Spec::Functions qw(abs2rel);
use FindBin;
use lib "$FindBin::Bin/../lib";
use Data::Dumper;
use File::Path qw(make_path);
+use File::Basename;
use config;
my $apidef;
my $apibase;
my $apih;
+my $mode = 'generate';
my $var = {
package => 'api',
output => 'bin',
while (@ARGV) {
my $cmd = shift(@ARGV);
- if ($cmd =~ m/^(-[^-])(.+)/) {
- $cmd = $1;
- unshift @ARGV, $2;
- }
-
- if ($cmd eq "-t") {
- $var->{package} = shift;
- } elsif ($cmd eq "-d") {
- $var->{output} = shift;
- } elsif ($cmd eq "-w") {
- $var->{workdir} = shift;
- } elsif ($cmd eq "-I") {
- push @{$var->{include}}, shift;
- } elsif ($cmd eq "-v") {
- $var->{verbose}++;
+ if ($cmd eq '-MT') {
+ $var->{'make-target'} = shift;
+ } elsif ($cmd eq '-MF') {
+ $var->{'make-file'} = shift;
} else {
- $apidef = $cmd;
- $apih = "$1.h" if ($apidef =~ m/^(.*).api$/);
- $apibase = basename($apidef, '.api');
-
- # if ($apidef =~ m/^(.*).api$/) {
- # $apih = $1;
- # } else {
- # die ("api definition must end in '.api'");
- # }
+ if ($cmd =~ m/^(-[^-])(.+)/) {
+ $cmd = $1;
+ unshift @ARGV, $2;
+ }
+
+ if ($cmd eq "-t") {
+ $var->{package} = shift;
+ } elsif ($cmd eq "-d") {
+ $var->{output} = shift;
+ } elsif ($cmd eq "-w") {
+ $var->{workdir} = shift;
+ } elsif ($cmd eq "-I") {
+ push @{$var->{include}}, shift;
+ } elsif ($cmd eq "-v") {
+ $var->{verbose}++;
+ } elsif ($cmd eq '-M') {
+ $mode = 'make-rule';
+ } else {
+ $apidef = $cmd;
+ $apih = "$1.h" if ($apidef =~ m/^(.*).api$/);
+ $apibase = basename($apidef, '.api');
+ }
}
}
push @{$var->{include}}, "$FindBin::Bin/../lib";
-print Dumper($var);
+#print Dumper($var);
die ("Missing config argument") if !defined($apidef);
die ("Unable to find config: $apidef") if !-f $apidef;
die ("Unable to find matching header for: $apidef") if !-f $apih;
my $api = new config($var, $apidef);
-
my @includes = map { ('-I', $_ ) } @{$var->{include}};
+
+if ($mode eq 'make-rule') {
+ my @list = ();
+
+ $var->{'make-target'} = "$apibase.d" if !defined $var->{'make-target'};
+
+ my @args = (
+ '-M',
+ '-MT', $var->{'make-target'},
+ @includes,
+ $apih);
+
+ open (my $gcc, '-|', 'gcc', @args) // die("command failed $!");
+ while (<$gcc>) {
+ chop;
+ s/ *\\$//;
+ s/^ +//;
+ push @list, $_;
+ }
+ close($gcc);
+
+ foreach my $m (qw(export-api export-defines generate-api)) {
+ push @list, abs2rel("$FindBin::Bin/$m");
+ }
+ foreach my $m (qw(api.pm code.pm config.pm method.pm tokenise.pm)) {
+ push @list, abs2rel("$FindBin::Bin/../lib/$m");
+ }
+
+ push @list, $apidef;
+ push @list, map { abs2rel($_) } @{$api->{includes}};
+
+ if (defined $var->{'make-file'}) {
+ open (my $f, ">", $var->{'make-file'}.'~') || die "writing $var->{'make-file'}";
+ print $f join(" \\\n ", @list)."\n";
+ close ($f) || die "writing $var->{'make-file'}";
+ rename($var->{'make-file'}.'~', $var->{'make-file'}) || die "writing $var->{'make-file'}";
+ } else {
+ print join(" \\\n ", @list)."\n";
+ }
+ exit 0;
+}
+
my @cmd = (
- "gcc",
+ 'gcc',
"-fplugin=$FindBin::Bin/../lib/libexport.so",
"-fplugin-arg-libexport-output=$var->{workdir}/$apibase.pm",
# "-fplugin-arg-libexport-verbose=$var->{verbose}",
- "-O0",
- "-o",
- "/dev/null",
+ '-O0',
+ '-o', '/dev/null',
@includes,
- "$apih"
+ $apih
);
print join " ", @cmd, "\n";