-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
112 lines (88 loc) · 3.61 KB
/
Copy pathMakefile
File metadata and controls
112 lines (88 loc) · 3.61 KB
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
# mp3CC - MIDletPascal 3.5 compiler, linux/arm build
#
# make native build -> Release/mp3CC
# make arm64 static aarch64 build -> Release-arm64/mp3CC
# make android static bionic builds -> Release-android-*/mp3CC
# make ISDEBUG=1 unoptimised + symbols -> Debug/mp3CC
#
# the arm64 target is built static on purpose: the same binary then runs both
# on arm linux and on android (arm64-v8a), where there is no glibc to link to.
CROSS ?=
CC = $(CROSS)gcc
# this is 2006-era c written for 32-bit msvc. modern gcc rejects by default
# what it relies on, so the legacy dialect is pinned explicitly:
# -std=gnu89 k&r-style definitions, no c99+ scoping changes
# -fcommon tentative definitions merged across units (pre-gcc10 default)
# -fpermissive downgrade c23 hard errors back to warnings
LEGACY = -std=gnu89 -fcommon -fpermissive -w
DEFS = -DLINUX -DUNIX
ifeq ($(ISDEBUG),1)
CFLAGS += -g -O0
DESTDIR ?= Debug
else
CFLAGS += -O2
LDFLAGS += -s
DESTDIR ?= Release
endif
ifeq ($(STATIC),1)
LDFLAGS += -static
endif
CPPC = $(CC) $(DEFS) $(LEGACY) $(CFLAGS)
MAINS=main
CLASSGENS=constant_pool classgen bytecode preverify
LEXS=lex.yy
UTILS=error memory strings
ifeq ($(ANDROID),1)
UTILS += android_tls
endif
PARSERS=parser stdpas
STRUCTURES=block identifier type type_list name_table string_list unit
PREVERS=file convert_md classresolver stubs classloader util \
check_class sys_support jar_support check_code jar \
inlinejsr main
DIRS=$(DESTDIR) $(DESTDIR)/classgen $(DESTDIR)/lex $(DESTDIR)/main \
$(DESTDIR)/parser $(DESTDIR)/preverifier $(DESTDIR)/structures \
$(DESTDIR)/util
ITEMS=$(CLASSGENS:%=classgen/%) $(LEXS:%=lex/%) $(MAINS:%=main/%) \
$(PARSERS:%=parser/%) $(PREVERS:%=preverifier/%) \
$(STRUCTURES:%=structures/%) $(UTILS:%=util/%)
all: release
re: clean all
clean:
rm -rf Release Debug Release-arm64 Release-android-*
debug:
$(MAKE) ISDEBUG=1
arm64:
$(MAKE) CROSS=aarch64-linux-gnu- STATIC=1 DESTDIR=Release-arm64
# android builds link static against bionic via the ndk. a glibc-static binary
# starts from adb shell but is killed by the app seccomp filter when spawned
# from an application process, so the ndk toolchain is required here.
# ndk r29 gives the 64-bit binaries 16 kb load-segment alignment by default.
# clang has no -fpermissive for c, the -Wno-* set below is its equivalent.
NDK ?= $(HOME)/Android/android-ndk-r29
NDK_BIN = $(NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin
CLANG_LEGACY = -std=gnu89 -fcommon -w -Wno-int-conversion \
-Wno-implicit-function-declaration -Wno-implicit-int \
-Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types \
-Wno-return-type
android: android-arm64 android-armv7 android-x86_64
android-arm64:
$(MAKE) CC=$(NDK_BIN)/aarch64-linux-android21-clang STATIC=1 ANDROID=1 \
DESTDIR=Release-android-arm64 LEGACY="$(CLANG_LEGACY)"
android-armv7:
$(MAKE) CC=$(NDK_BIN)/armv7a-linux-androideabi21-clang STATIC=1 ANDROID=1 \
DESTDIR=Release-android-armv7 LEGACY="$(CLANG_LEGACY)"
android-x86_64:
$(MAKE) CC=$(NDK_BIN)/x86_64-linux-android21-clang STATIC=1 ANDROID=1 \
DESTDIR=Release-android-x86_64 LEGACY="$(CLANG_LEGACY)"
release: $(DIRS) $(DESTDIR)/mp3CC
$(DIRS):
mkdir -p $@
# Clang otherwise emits emulated TLS, which cannot raise PT_TLS alignment
$(DESTDIR)/util/android_tls.o: util/android_tls.c | $(DIRS)
$(CPPC) -fno-emulated-tls -c -o $@ $<
$(DESTDIR)/%.o : %.c | $(DIRS)
$(CPPC) -c -o $@ $<
$(DESTDIR)/mp3CC: $(ITEMS:%=$(DESTDIR)/%.o)
$(CPPC) $(LDFLAGS) -o $@ $^ -lm
.PHONY: all re clean debug release arm64 android android-arm64 android-armv7 android-x86_64