-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
133 lines (115 loc) · 3.45 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
JAVA := /opt/java
ifeq ($(strip $(JAVA_HOME)),)
else
JAVA := $(JAVA_HOME)
endif
ifeq ($(shell uname), Linux)
INCLUDE_FLAGS=-I$(JAVA)/include -I$(JAVA)/include/linux
OS := linux
CC = gcc
CFLAGS = -D_GNU_SOURCE $(INCLUDE_FLAGS)
else ifeq ($(shell uname), Darwin)
TARGET=macosx
INCLUDE_FLAGS=-I$(JAVA)/include -I$(JAVA)/include/darwin
OS := macosx
CC = gcc
CFLAGS = -DDARWIN $(INCLUDE_FLAGS)
else ifeq ($(shell uname), MINGW32_NT)
OS := windows
CC = gcc
CFLAGS = -DWIN32 -I$(JAVA)/include -I$(JAVA)/include/win32
endif
ifeq ($(TARGET), ios)
OS := ios
CC = clang
CFLAGS = -arch arm64 \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk \
-miphoneos-version-min=12.0 \
-fobjc-arc \
-O2 \
-Wall -Wextra \
-g \
-framework Foundation \
$(INCLUDE_FLAGS)
else ifeq ($(TARGET), android)
OS := android
CC = $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
CFLAGS = -target aarch64-linux-android \
-DANDROID
else
endif
SRCDIR = src
DARWIN_SRCDIR = src/darwin
OBJDIR = build
LIBDIR = lib
SRCS = $(wildcard $(SRCDIR)/*.c)
ifeq ($(TARGET), macosx)
SRCS = $(wildcard $(SRCDIR)/*.c) $(wildcard $(DARWIN_SRCDIR)/*.m)
# SRCS += $(wildcard $(SRCDIR)/darwin/*.m)
echo "SRCS = $(SRCS)"
endif
ifeq ($(TARGET), ios)
SRCS = $(wildcard $(SRCDIR)/*.c) $(wildcard $(DARWIN_SRCDIR)/*.m)
# SRCS += $(wildcard $(SRCDIR)/darwin/*.m)
echo "SRCS = $(SRCS)"
endif
#OBJS = $(patsubst %.c,$(OBJDIR)/$(OS)/%.o,$(notdir $(SRCS)))
#OBJS += $(patsubst $(DARWIN_SRCDIR)/%.m,$(OBJDIR)/$(OS)/%.o,$(wildcard $(DARWIN_SRCDIR)/*.m))
OBJS_C = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/$(OS)/%.o,$(filter %.c,$(SRCS)))
OBJS_M = $(patsubst $(DARWIN_SRCDIR)/%.m,$(OBJDIR)/$(OS)/%.o,$(filter %.m,$(SRCS)))
OBJS = $(OBJS_C) $(OBJS_M)
JDKLIB = /tmp/libjdk.a
TEMP_DIR = /tmp/extractdir
ifeq ($(OS), windows)
JDKLIB := C:/path/to/libjdk.lib
LIB = $(LIBDIR)/windows/staticjdk/lib/libvmone.lib
AR = lib
ARFLAGS = /OUT:
else
LIB = $(LIBDIR)/$(OS)/staticjdk/lib/libvmone.a
AR = ar
ARFLAGS = rcs
endif
all: $(LIB)
$(LIB): $(OBJS)
@mkdir -p $(LIBDIR)/$(OS)/staticjdk/lib
ifeq ($(OS), windows)
if [ -s $(JDKLIB) ]; then \
echo "Including $(JDKLIB) in lib"; \
TMPDIR=$(LIBDIR)/$(OS)/temp_objs; \
mkdir -p $$TMPDIR; \
(cd $$TMPDIR && $(AR) x $(JDKLIB)); \
$(AR) $(ARFLAGS) $@ $$TMPDIR/*.o $^; \
else \
echo "Existing library not found. Creating static library with object files only."; \
$(AR) $(ARFLAGS) $@ $^; \
fi
else
if [ -s $(JDKLIB) ]; then \
echo "Including $(JDKLIB) in lib"; \
TMPDIR=$(LIBDIR)/$(OS)/temp_objs; \
mkdir -p $$TMPDIR; \
(cd $$TMPDIR && ar x $(JDKLIB)); \
ar $(ARFLAGS) $@ $$TMPDIR/*.o $^; \
else \
echo "Existing library not found. Creating static library with object files only."; \
ar $(ARFLAGS) $@ $^; \
fi
endif
debug:
@echo "OS: $(OS)"
@echo "SRCS: $(SRCS)"
@echo "OBJS: $(OBJS)"
@echo "OBJDIR: $(OBJDIR)"
$(OBJDIR)/$(OS)/%.o: $(SRCDIR)/%.c
echo "Using Java from $(JAVA) and OS = $(OS) and OBJS = $(OBJS)"
@mkdir -p $(OBJDIR)/$(OS)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/$(OS)/%.o: $(SRCDIR)/darwin/%.m
@mkdir -p $(OBJDIR)/$(OS)
$(CC) $(CFLAGS) -c $< -o $@
#$(OBJDIR)/$(OS)/%.o: $(SRCDIR)/darwin/%.m
#@mkdir -p $(OBJDIR)/$(OS)
#$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -rf $(OBJDIR) $(LIBDIR)