javac -h turns out to be much more complicated than javah :-(

This commit is contained in:
rfm 2024-02-14 11:50:21 +00:00
parent 76a1df3b61
commit 9de817126c
3 changed files with 32 additions and 12 deletions

View file

@ -1,3 +1,13 @@
2024-02-14 Richard Frith-Macdonald <rfm@gnu.org>
* common.make:
* rules.make:
Rewrite 'javac -h' code because its usage turns out to be quite
different from that of the javah command it is supposed to replace.
Possibly the header generation and class file generation could/should
be combined in a single pass, but we can't readily do that without
breakign compatibility with older versions of java.
2024-02-11 Richard Frith-Macdonald <rfm@gnu.org>
* Documentation/gnustep-make.texi:

View file

@ -854,16 +854,10 @@ ifeq ($(JAVAC),)
endif
#
# The java header compiler.
# After Java 8, javah is replaced by javac with the -h flag, so if we don't
# find the javah executable we assume we are using javac.
# The java header compiler (if any). We need to check later.
#
ifeq ($(JAVAH),)
ifeq (, $(shell $(JAVA_HOME)/bin/javah -version 2>/dev/null))
JAVAH = $(JAVA_HOME)/bin/javac -h
else
JAVAH = $(JAVA_HOME)/bin/javah
endif
endif
#

View file

@ -672,12 +672,28 @@ endif
# Example of how this rule will be applied:
# gnu/gnustep/base/NSObject.h : gnu/gnustep/base/NSObject.java
# javah -o gnu/gnustep/base/NSObject.h gnu.gnustep.base.NSObject
# or
# javac -h -o gnu/gnustep/base/NSObject.h gnu.gnustep.base.NSObject
# or, on more recent releases than 8, we have to use javac and move the
# resulting header file around t the correct location as javac does not
# provide command line options to control the output file name.
# NB. javac also fails to produce a header file when a java file does
# not produce class information, so we catch that and generate an empty
# header where necessary.
%.h : %.java
$(ECHO_JAVAHING)$(JAVAH) \
$(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVAHFLAGS)) \
$($<_FILE_FLAGS) -o $@ $(subst /,.,$*)$(END_ECHO)
$(ECHO_NOTHING)if [ -x $(JAVAH) ]; then \
$(JAVAH) \
$(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVAHFLAGS)) \
$($<_FILE_FLAGS) -o $@ $(subst /,.,$*); \
else \
JAVA_DST_DIR=`dirname $@`; \
$(JAVAC) -h $$JAVA_DST_DIR -sourcepath `dirname $*` \
$(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVAHFLAGS)) \
$($<_FILE_FLAGS) $*.java; \
if [ -e $$JAVA_DST_DIR/$(subst /,_,$@) ]; then \
mv $$JAVA_DST_DIR/$(subst /,_,$@) $$JAVA_DST_DIR/`basename $@`; \
else \
touch $$JAVA_DST_DIR/`basename $@`; \
fi \
fi$(END_ECHO)
%.c : %.psw
pswrap -h $*.h -o $@ $<