]> git.argeo.org Git - cc0/argeo-build.git/blob - jni.mk
Close directory stream
[cc0/argeo-build.git] / jni.mk
1 ARGEO_BUILD_BASE := $(dir $(lastword $(MAKEFILE_LIST)))
2 include $(ARGEO_BUILD_BASE)common.mk
3
4 # The following variables should be declared in the including Makefile:
5 # NATIVE_PACKAGE this native package name
6 # A2_CATEGORY the (single) a2 category the bundles will belong to
7
8 # The following variables have default values which can be overriden
9 # DEP_NATIVE space-separated logical names of named depdencies
10 # DEP_INCLUDES additional includes
11 # DEP_LIBS additional native libraries
12 DEP_NATIVE ?=
13 DEP_INCLUDES ?= $(foreach dep, $(DEP_NATIVE), /usr/include/$(dep))
14 DEP_LIBS ?= $(foreach dep, $(DEP_NATIVE), -l$(dep))
15
16 A2_NATIVE_CATEGORY=$(A2_OUTPUT)/lib/linux/$(shell uname -m)/$(A2_CATEGORY)
17 TARGET_EXEC := libJava_$(NATIVE_PACKAGE).$(major).$(minor).so
18
19 LDFLAGS ?= -shared -fPIC -Wl,-soname,$(TARGET_EXEC).$(major).$(minor).$(micro) $(DEP_LIBS)
20 CFLAGS ?= -O3 -fPIC
21
22 SRC_DIRS := .
23
24 #
25 # Generic Argeo
26 #
27 BUILD_DIR := $(SDK_BUILD_BASE)/jni/$(NATIVE_PACKAGE)
28
29 # Include directories
30 INC_DIRS := $(shell find $(SRC_DIRS) -type d) $(JAVA_HOME)/include $(JAVA_HOME)/include/linux $(DEP_INCLUDES)
31
32 all: $(A2_NATIVE_CATEGORY)/$(TARGET_EXEC)
33
34 clean:
35 $(RM) $(BUILD_DIR)/*.o
36 $(RM) $(A2_NATIVE_CATEGORY)/$(TARGET_EXEC)
37
38 install:
39 $(INSTALL) $(A2_NATIVE_INSTALL_TARGET)/$(A2_CATEGORY) $(A2_NATIVE_CATEGORY)/$(TARGET_EXEC)
40
41 uninstall:
42 $(RM) $(A2_NATIVE_INSTALL_TARGET)/$(A2_CATEGORY)/$(TARGET_EXEC)
43 @if [ -d $(A2_NATIVE_INSTALL_TARGET) ]; then find $(A2_NATIVE_INSTALL_TARGET) -empty -type d -delete; fi
44
45 # Sources
46 SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s')
47 # Objects (example.cpp to ./org_example_core/example.cpp.o)
48 OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
49 # Dependencies (example.cpp.o to ./org_example_core/example.cpp.d)
50 DEPS := $(OBJS:.o=.d)
51 # Add -I prefix to include directories
52 INC_FLAGS := $(addprefix -I,$(INC_DIRS))
53 # Generate dependencies makefiles
54 CPPFLAGS := $(INC_FLAGS) -MMD -MP
55
56 # Final build step
57 $(A2_NATIVE_CATEGORY)/$(TARGET_EXEC): $(OBJS)
58 mkdir -p $(A2_NATIVE_CATEGORY)
59 $(CC) $(OBJS) -o $@ $(LDFLAGS)
60
61 # Build step for C source
62 $(BUILD_DIR)/%.c.o: %.c
63 mkdir -p $(dir $@)
64 $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
65
66 # Build step for C++ source
67 $(BUILD_DIR)/%.cpp.o: %.cpp
68 mkdir -p $(dir $@)
69 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
70
71 # Include the .d makefiles. (- pefix suppress errors if not found)
72 -include $(DEPS)
73
74 .PHONY: clean all install uninstall