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