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
|
https://github.com/rui314/mold/pull/135
From: Sam James <sam@gentoo.org>
Date: Tue, 14 Dec 2021 10:53:44 +0000
Subject: [PATCH 1/2] build: respect user *FLAGS
- Respect user CXXFLAGS
- Rename CPPFLAGS (previously used in the sense of "flags for the C++ compiler") -> CXXFLAGS
- CPPFLAGS is generally used for "flags for the C(++) preprocessor.", so let's
use it for that
- Respect user LDFLAGS
(In one instance, we were respecting LDFLAGS, but doing it too late.
We need to pass LDFLAGS _before_ any objects in order for -Wl,--as-needed
to work correctly.)
Signed-off-by: Sam James <sam@gentoo.org>
--- a/Makefile
+++ b/Makefile
@@ -17,10 +17,15 @@ STRIP ?= strip
OS ?= $(shell uname -s)
-CPPFLAGS = -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.6\" \
- -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables \
- -DLIBDIR="\"$(LIBDIR)\"" $(EXTRA_CPPFLAGS)
-LDFLAGS += $(EXTRA_LDFLAGS)
+# Used for both C and C++
+COMMON_FLAGS = -pthread -fPIE -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables
+
+CFLAGS ?= -O2
+CFLAGS += $(COMMON_FLAGS)
+
+CXXFLAGS ?= -O2
+CXXFLAGS += $(COMMON_FLAGS) -std=c++20
+CPPFLAGS += -DMOLD_VERSION=\"0.9.6\" -DLIBDIR="\"$(LIBDIR)\""
LIBS = -pthread -lz -lxxhash -ldl -lm
SRCS=$(wildcard *.cc elf/*.cc macho/*.cc)
@@ -38,21 +43,19 @@ ifneq ($(GIT_HASH),)
endif
ifeq ($(DEBUG), 1)
- CPPFLAGS += -O0 -g
-else
- CPPFLAGS += -O2
+ CXXFLAGS += -O0 -g
endif
ifeq ($(LTO), 1)
- CPPFLAGS += -flto -O3
+ CXXFLAGS += -flto -O3
LDFLAGS += -flto
endif
ifeq ($(ASAN), 1)
- CPPFLAGS += -fsanitize=address
+ CXXFLAGS += -fsanitize=address
LDFLAGS += -fsanitize=address
else ifeq ($(TSAN), 1)
- CPPFLAGS += -fsanitize=thread
+ CXXFLAGS += -fsanitize=thread
LDFLAGS += -fsanitize=thread
else ifneq ($(OS), Darwin)
# By default, we want to use mimalloc as a memory allocator.
@@ -89,15 +92,15 @@ endif
all: mold mold-wrapper.so
mold: $(OBJS) $(MIMALLOC_LIB) $(TBB_LIB)
- $(CXX) $(CPPFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS)
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)
ln -sf mold ld
ln -sf mold ld64.mold
mold-wrapper.so: elf/mold-wrapper.c Makefile
- $(CC) -fPIC -shared -o $@ $< -ldl
+ $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -shared -o $@ $(LDFLAGS) $< -ldl
out/%.o: %.cc $(HEADERS) Makefile out/elf/.keep out/macho/.keep
- $(CXX) $(CPPFLAGS) -c -o $@ $<
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
out/elf/.keep:
mkdir -p out/elf
|