From: Not Zed Date: Mon, 7 Feb 2022 01:01:26 +0000 (+1030) Subject: Add dependency generation for .api files X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=84e92cc84b54efa3ffd28eb4020b5aff3f046ecb;p=panamaz Add dependency generation for .api files Removed '.data' and '.script' status file rules and just use the files themselves as the targets. Cleaned up the make code a bit --- diff --git a/Makefile b/Makefile index 2a0ba4a..8d2d841 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,3 @@ notzed.vkregistry_JMAIN = vulkan.test.TestVulkan $(foreach module,$(java_MODULES),$(eval $(module)_JMAINFLAGS=--enable-native-access=notzed.nativez,$(module))) include java.make - -# makes notzed.nativez appear in the right place at the right time without altering java.make -$(java_bindir)/export-api: notzed.nativez diff --git a/README b/README index 135b477..2451943 100644 --- a/README +++ b/README @@ -32,17 +32,20 @@ vulkan-tools-1.2.x. Copy config.make.in to config.make and modify any variables required. -Parallel make should work. +First compile the native binding tools. This should only need to be +done once after which it auto-updates properly. -Build all: +$ make notzed.nativez + +Then make everything else, parallel make should work. $ make -j -Build one module: +Or build one module: $ make notzed.nativez -Run a demo (see next section): +Or run a demo (see next section): $ make run-notzed.vkregistry/vulkan.test.TestVulkan diff --git a/java.make b/java.make index 1986121..ff3491c 100644 --- a/java.make +++ b/java.make @@ -209,31 +209,53 @@ clean: 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 \ @@ -247,50 +269,31 @@ $(java_jmoddir)/$(1).jmod: bin/status/$(1).classes bin/status/$(1).data $$@ # 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= @@ -308,7 +311,7 @@ endef $(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 # ###################################################################### # _API List of api's to include @@ -316,12 +319,18 @@ $(foreach module,$(java_MODULES),$(foreach main,$($(module)_JMAIN),$(eval $(call # __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)))))) @@ -379,17 +388,15 @@ $($(1)_libdir)/%: src/$(1)/native/% $($(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) \ diff --git a/src/notzed.clstatic/gen/opencl.api b/src/notzed.clstatic/gen/opencl.api index 11126ea..3157e91 100644 --- a/src/notzed.clstatic/gen/opencl.api +++ b/src/notzed.clstatic/gen/opencl.api @@ -115,7 +115,7 @@ library CL success:errcode_ret=CL_SUCCESS { clCreateSampler; } -library enqueue ignore +library enqueue success:result$=CL_SUCCESS implied:num_events_in_wait_list=(int)event_wait_list.count() tonative:event=code:event=reserve diff --git a/src/notzed.nativez/bin/export-api b/src/notzed.nativez/bin/export-api index 5823932..6fcbf02 100755 --- a/src/notzed.nativez/bin/export-api +++ b/src/notzed.nativez/bin/export-api @@ -6,19 +6,21 @@ 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', @@ -30,55 +32,97 @@ my $var = { 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"; diff --git a/src/notzed.nativez/lib/config.pm b/src/notzed.nativez/lib/config.pm index 83f2aac..7dd8a91 100644 --- a/src/notzed.nativez/lib/config.pm +++ b/src/notzed.nativez/lib/config.pm @@ -28,6 +28,7 @@ sub new { my $self = { options => $options, objects => [], + includes => [], }; foreach my $path (@_) { @@ -65,8 +66,10 @@ sub loadControlFile { #print " $state $t\n"; if ($state == 0) { if ($t eq 'include') { - my $file = $tokeniser->next(); - $tokeniser->include(findInclude($self, $file)); + my $file = findInclude($self, $tokeniser->next()); + + push @{$self->{includes}}, $file; + $tokeniser->include($file); } elsif ($tokeniser->{type} eq 'token') { $target = { type => $t, options => [], items => [] }; push @$list, $target; diff --git a/src/notzed.nativez/lib/tokenise.pm b/src/notzed.nativez/lib/tokenise.pm index cddf789..478ed73 100644 --- a/src/notzed.nativez/lib/tokenise.pm +++ b/src/notzed.nativez/lib/tokenise.pm @@ -38,7 +38,7 @@ sub include { my $self = shift; my $path = shift; - print "include '$path'\n"; + #print "include '$path'\n"; push @{$self->{files}}, $self->{file};