]> git.argeo.org Git - lgpl/argeo-commons.git/blob - sdk/jni.mk
8483bd7041ddca5096a7cb63872af055e8a7366f
[lgpl/argeo-commons.git] / sdk / jni.mk
1 TARGET_EXEC := libJava_$(NATIVE_PACKAGE).so
2
3 LDFLAGS = -shared -fPIC -Wl,-soname,$(TARGET_EXEC).$(MAJOR).$(MINOR) -luuid
4 CFLAGS = -fPIC
5
6 SRC_DIRS := .
7 %:
8 @echo Making '$@' $(if $^,from '$^')
9 # @echo 'MAJOR=$(MAJOR)'
10 # @echo 'MINOR=$(MINOR)'
11 @echo 'SRC_DIRS=$(SRC_DIRS)'
12 @echo 'BUILD_DIR=$(BUILD_DIR)'
13
14
15 #
16 # Generic Argeo
17 #
18 BUILD_DIR := $(SDK_BUILD_BASE)/$(NATIVE_PACKAGE)
19 #BUILD_DIR := ./build
20 #META_INF_DIR := ./../META-INF
21 #ARCH := $(shell uname -p)
22
23 # Every folder in ./src will need to be passed to GCC so that it can find header files
24 INC_DIRS := $(shell find $(SRC_DIRS) -type d) /usr/lib/jvm/java/include /usr/lib/jvm/java/include/linux /usr/include/uuid
25
26
27 .PHONY: clean all ide
28 all: $(SDK_BUILD_BASE)/$(TARGET_EXEC)
29
30 # Find all the C and C++ files we want to compile
31 # Note the single quotes around the * expressions. Make will incorrectly expand these otherwise.
32 SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s')
33
34 # String substitution for every C/C++ file.
35 # As an example, hello.cpp turns into ./build/hello.cpp.o
36 OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
37
38 # String substitution (suffix version without %).
39 # As an example, ./build/hello.cpp.o turns into ./build/hello.cpp.d
40 DEPS := $(OBJS:.o=.d)
41
42 # Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag
43 INC_FLAGS := $(addprefix -I,$(INC_DIRS))
44
45 # The -MMD and -MP flags together generate Makefiles for us!
46 # These files will have .d instead of .o as the output.
47 CPPFLAGS := $(INC_FLAGS) -MMD -MP
48
49 # The final build step.
50 $(SDK_BUILD_BASE)/$(TARGET_EXEC): $(OBJS)
51 $(CC) $(OBJS) -o $@ $(LDFLAGS)
52
53 # Build step for C source
54 $(BUILD_DIR)/%.c.o: %.c
55 mkdir -p $(dir $@)
56 $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
57
58 # Build step for C++ source
59 $(BUILD_DIR)/%.cpp.o: %.cpp
60 mkdir -p $(dir $@)
61 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
62
63 clean:
64 rm -r $(BUILD_DIR) $(SDK_BUILD_BASE)/$(TARGET_EXEC)
65
66 # Include the .d makefiles. The - at the front suppresses the errors of missing
67 # Makefiles. Initially, all the .d files will be missing, and we don't want those
68 # errors to show up.
69 -include $(DEPS)
70
71 # MAKEFILE_DIR := $(dir $(firstword $(MAKEFILE_LIST)))