Skip to content

Commit 35fed06

Browse files
committed
Fancy up Makefile
1 parent a5e61e7 commit 35fed06

File tree

1 file changed

+69
-37
lines changed

1 file changed

+69
-37
lines changed

examples/src/linux/Makefile

Lines changed: 69 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
1-
CC = gcc
21

2+
# c compiler and flags
3+
CC = gcc
34
CFLAGS = -Wall -O2 -s
45

5-
#CFLAGS += -DDEBUG
6+
# cpp compiler and flags
7+
CXX = g++
8+
CXXFLAGS = -Wall -O2 -s
69

7-
OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
10+
# preprocessor flags, common to c and cpp
11+
CPPFLAGS = -MD
812

13+
OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
914
DEPS = $(patsubst %.o,%.d,$(OBJS))
10-
CFLAGS += -MD
1115
MISSING_DEPS = $(filter-out $(wildcard $(DEPS)),$(DEPS))
1216
MISSING_DEPS_SOURCES = $(wildcard $(patsubst %.d,%.c,$(MISSING_DEPS)))
1317

14-
LIBS=
15-
16-
TARGET = arm_hello arm_hello_static \
17-
arm64_hello arm64_hello_static \
18-
mips32el_hello mips32el_hello_static \
19-
x86_hello x86_hello_static \
20-
x8664_hello x8664_hello_static \
21-
patch_test.bin \
22-
arm_sleep_hello arm64_sleep_hello
23-
24-
all : $(TARGET)
18+
TARGETS = \
19+
arm_hello \
20+
arm_hello_static \
21+
arm_sleep_hello \
22+
arm64_hello \
23+
arm64_hello_static \
24+
arm64_sleep_hello \
25+
mips32el_hello \
26+
mips32el_hello_static \
27+
x86_hello \
28+
x86_hello_static \
29+
x86_hello_cpp \
30+
x86_hello_cpp_static \
31+
x8664_hello \
32+
x8664_hello_static \
33+
x8664_hello_cpp \
34+
x8664_hello_cpp_static \
35+
patch_test.bin
36+
37+
.PHONY: all clean
38+
39+
all : $(TARGETS)
40+
41+
ARM_TARGETS: $(filter arm_%,$(TARGETS))
42+
ARM64_TARGETS: $(filter arm64_%,$(TARGETS))
43+
MIPS32EL_TARGETS: $(filter mips32el_%,$(TARGETS))
44+
X86_TARGETS: $(filter x86_%,$(TARGETS))
45+
X8664_TARGETS: $(filter x8664_%,$(TARGETS))
2546

2647
ifneq ($(MISSING_DEPS),)
2748
$(MISSING_DEPS) :
@@ -31,67 +52,78 @@ endif
3152
-include $(DEPS)
3253

3354
arm_hello: hello.c
34-
arm-linux-gnueabihf-gcc -Wall -O2 -s $< -o $@
55+
arm-linux-gnueabihf-gcc $(CPPFLAGS) $(CFLAGS) -o $@ $<
3556

3657
arm_hello_static: hello.c
37-
arm-linux-gnueabihf-gcc -Wall -O2 -s -static $< -o $@
58+
arm-linux-gnueabihf-gcc $(CPPFLAGS) $(CFLAGS) -static -o $@ $<
3859

3960
arm_sleep_hello: sleep_hello.c
40-
arm-linux-gnueabihf-gcc -Wall -O2 -s $< -o $@
61+
arm-linux-gnueabihf-gcc $(CPPFLAGS) $(CFLAGS) -o $@ $<
4162

4263
arm64_hello: hello.c
43-
aarch64-linux-gnu-gcc -Wall -O2 -s $< -o $@
64+
aarch64-linux-gnu-gcc $(CPPFLAGS) $(CFLAGS) -o $@ $<
4465

4566
arm64_hello_static: hello.c
46-
aarch64-linux-gnu-gcc -Wall -O2 -s -static $< -o $@
67+
aarch64-linux-gnu-gcc $(CPPFLAGS) $(CFLAGS) -static -o $@ $<
4768

4869
arm64_sleep_hello: sleep_hello.c
49-
aarch64-linux-gnu-gcc -Wall -O2 -s $< -o $@
70+
aarch64-linux-gnu-gcc $(CPPFLAGS) $(CFLAGS) -o $@ $<
5071

5172
# not included in default targets because requires the Android NDK to be installed.
5273
# add <NDK>/toolchains/llvm/prebuilt/linux-x86_64/bin/ to your path
5374
arm64_android_hello: hello.c
54-
aarch64-linux-android29-clang -Wall -O2 -s $< -o $@
75+
aarch64-linux-android29-clang $(CPPFLAGS) $(CFLAGS) -o $@ $<
5576

5677
arm64_posix_syscall: posix_syscall.c
57-
aarch64-linux-gnu-gcc -Wall -O2 -s $< -o $@
78+
aarch64-linux-gnu-gcc $(CPPFLAGS) $(CFLAGS) -o $@ $<
5879

5980
mips32el_hello: hello.c
60-
mipsel-linux-gnu-gcc -Wall -O2 -s $< -o $@
81+
mipsel-linux-gnu-gcc $(CPPFLAGS) $(CFLAGS) -o $@ $<
6182

6283
mips32el_hello_static: hello.c
63-
mipsel-linux-gnu-gcc -Wall -O2 -s -static $< -o $@
84+
mipsel-linux-gnu-gcc $(CPPFLAGS) $(CFLAGS) -static -o $@ $<
6485

6586
mips32el_posix_syscall: posix_syscall.c
66-
mipsel-linux-gnu-gcc -Wall -O2 -s $< -o $@
87+
mipsel-linux-gnu-gcc $(CPPFLAGS) $(CFLAGS) -o $@ $<
6788

6889
x86_hello: hello.c
69-
gcc -Wall -O2 -s -m32 $< -o $@
90+
$(CC) $(CPPFLAGS) $(CFLAGS) -m32 -o $@ $<
7091

7192
x86_hello_static: hello.c
72-
gcc -Wall -O2 -s -m32 -static $< -o $@
93+
$(CC) $(CPPFLAGS) $(CFLAGS) -m32 -static -o $@ $<
94+
95+
x86_hello_cpp: hello.cpp
96+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -m32 -o $@ $<
97+
98+
x86_hello_cpp_static: hello.cpp
99+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -m32 -static -o $@ $<
73100

74101
x86_posix_syscall: posix_syscall.c
75-
gcc -Wall -O2 -s -m32 $< -o $@
102+
$(CC) $(CPPFLAGS) $(CFLAGS) -m32 -o $@ $<
76103

77104
x86_fetch_urandom: fetch_urandom.c
78-
gcc -Wall -O2 -s -m32 $< -o $@
105+
$(CC) $(CPPFLAGS) $(CFLAGS) -m32 -o $@ $<
79106

80107
x8664_hello: hello.c
81-
gcc -Wall -O2 -s $< -o $@
108+
$(CC) $(CFLAGS) -m64 -o $@ $<
82109

83110
x8664_hello_static: hello.c
84-
gcc -Wall -O2 -s -static $< -o $@
111+
$(CC) $(CPPFLAGS) $(CFLAGS) -m64 -static -o $@ $<
85112

86-
libpatch_test.so: patch_test.so.h patch_test.so.c
87-
gcc -shared -fpic -s patch_test.so.c -o $@
113+
x8664_hello_cpp: hello.cpp
114+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -m64 -o $@ $<
88115

89-
patch_test.bin: libpatch_test.so patch_test.bin.c
90-
gcc -s patch_test.bin.c libpatch_test.so -o $@
116+
x8664_hello_cpp_static: hello.cpp
117+
$(CXX) $(CXXFLAGS) -m64 -static -o $@ $<
118+
119+
libpatch_test.so: patch_test.so.h patch_test.so.c
120+
$(CC) $(CPPFLAGS) -Wall -s -O0 -shared -fpic -o $@ patch_test.so.c
91121

122+
patch_test.bin: patch_test.bin.c libpatch_test.so
123+
$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-nonnull -o $@ $^
92124

93125
$(OBJS):%.o:%.c
94126
$(CC) $(CFLAGS) -c $< -o $@
95127

96128
clean:
97-
rm -f *.d *.s *.o $(TARGET)
129+
$(RM) -f *.d *.s *.o *.so $(TARGETS)

0 commit comments

Comments
 (0)