So I'm going to publish this small project on GitHub and I thought I'd better do a makefile for it. The source code consists of
- 1 Java Class
- 1 Native JNI module written in C
- 1 stdlib wrapper object written in C (for LD_PRELOAD)
The purpose of the Makefile is to compile the two shared objects from the C-Source.
Here it is
CC=gcc CFLAGS=-nostartfiles -fpic -shared -ldl -D_GNU_SOURCE -Wall -Werror OUT=bld OUTFILES = $(OUT)/bind.so $(OUT)/bindsetter.so JNI_AUTO_HEADER=$(OUT)/com_daftdroid_droidlib_bind_ClientBind.h #Two locations needed to get all the JNI header files JNI_INCLUDE=/usr/lib/jvm/java-8-oracle/include \ /usr/lib/jvm/java-8-oracle/include/linux #Add the includes to the compiler flags CFLAGS+=$(foreach d, $(JNI_INCLUDE), -I$d) all: $(OUTFILES) $(OUTFILES): $(OUT)/%.so: %.c $(JNI_AUTO_HEADER) $(CC) $(CFLAGS) -c $< -o $@ $(JNI_AUTO_HEADER): ClientBind.java javac ClientBind.java -d $(OUT) -h $(OUT) .PHONY: clean clean: rm bld/* -rf
So some questions:
CC=gcc is this a bit presumptuous?
CFLAGS - well these all assume GCC too. What about inflicting
-Werror on people - on my computer there are no warnings as it stands.
I hate this:
JNI_INCLUDE=/usr.... that is seriously installation dependent. What's a better way of doing this?
I have this header file
JNI_AUTO_HEADER that javac can generate from the .java source, so therefore I consider it a build artifact which the makefile is responsible for. Do you agree? Also I've made all of the .so files dependent on
JNI_AUTO_HEADER but hey, there's only two of them so I guess it's not worth worrying about.
Also I'm not sure if there's a better way of doing this in my source file:
// This include generated in the build directory at compile time #include "bld/com_daftdroid_droidlib_bind_ClientBind.h"
(without getting into a much more complex build process)
Any other comments welcome.