fix: 'make dist' without javah
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 7 Jul 2022 21:01:54 +0000 (17:01 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 23 Aug 2022 20:36:12 +0000 (16:36 -0400)
Don't use 'BUILT_SOURCES' for the header file generated by javah /
javac, files added to this target will be generated on 'make dist'
regardless of the configuration or presence of the required tools.

Add proper make dependencies between the different targets instead of
using 'all-local'.

Set JAVAROOT to a temporary directory to properly clean class files and
avoid confusing javah when it's used to generate the JNI header.

Change-Id: I8544d0418039ba667d062cb01c924368ab702ab7
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-java/Makefile.am

index 260774f972c81540854b9d20828be9651341f7d2..3fd7c39d9d8165ad8fb9032fcb9f44d264649495 100644 (file)
@@ -1,36 +1,47 @@
-JAVAROOT = .
+JAVAROOT = .build
 jarfile = liblttng-ust-java.jar
 jardir = $(datadir)/java
 pkgpath = org/lttng/ust
 
 dist_noinst_JAVA = $(pkgpath)/LTTngUst.java
 jar_DATA = $(jarfile)
-BUILT_SOURCES = org_lttng_ust_LTTngUst.h
 
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include $(JNI_CPPFLAGS)
+
 lib_LTLIBRARIES = liblttng-ust-java.la
 liblttng_ust_java_la_SOURCES = LTTngUst.c lttng_ust_java.h
+
+# Generated by javac / javah
 nodist_liblttng_ust_java_la_SOURCES = org_lttng_ust_LTTngUst.h
 
 liblttng_ust_java_la_LIBADD = -lc -L$(top_builddir)/liblttng-ust/.libs -llttng-ust
 
+# Explicit dependency to ensure the header is generated before the
+# C file is built.
+LTTngUst.lo: org_lttng_ust_LTTngUst.h
+
 $(jarfile): classnoinst.stamp
-       $(JAR) cf $(JARFLAGS) $@ $(pkgpath)/*.class
+       $(JAR) cf $(JARFLAGS) $@ -C $(JAVAROOT) $(pkgpath)/LTTngUst.class
+
+# Ensure the javaroot directory is created before the Java class files are built.
+$(pkgpath)/LTTngUst.java: $(JAVAROOT)
+$(JAVAROOT):
+       -test -d $(JAVAROOT) || mkdir $(JAVAROOT)
 
 if !HAVE_JAVAH
 # If we don't have javah, assume we are running openjdk >= 10 and use javac
 # to generate the jni header file.
 AM_JAVACFLAGS = -h .
 
-org_lttng_ust_LTTngUst.h: $(jarfile)
+# The header file will be generated by javac when building the Java class
+# files, add a dependency on the stamp file to ensure proper ordering.
+org_lttng_ust_LTTngUst.h: classnoinst.stamp
 else
-org_lttng_ust_LTTngUst.h: jni-header.stamp
-
-jni-header.stamp: $(dist_noinst_JAVA)
-       $(JAVAH) -classpath $(srcdir) $(JAVAHFLAGS) org.lttng.ust.LTTngUst && \
-       echo "JNI header generated" > jni-header.stamp
+org_lttng_ust_LTTngUst.h:
+       $(JAVAH) -classpath $(srcdir) $(JAVAHFLAGS) org.lttng.ust.LTTngUst
 endif
 
-all-local: org_lttng_ust_LTTngUst.h
+CLEANFILES = $(jarfile) org_lttng_ust_LTTngUst.h
 
-CLEANFILES = $(jarfile) $(pkgpath)/*.class jni-header.stamp org_lttng_ust_LTTngUst.h
+clean-local:
+       -rm -rf $(JAVAROOT)
This page took 0.027843 seconds and 4 git commands to generate.