2021-05-18 07:20:57 +03:00
|
|
|
CC = clang
|
|
|
|
CXX = clang++
|
|
|
|
|
2021-06-30 17:41:46 +03:00
|
|
|
GIT_HASH ?= $(shell [ -d .git ] && git rev-parse HEAD)
|
2021-05-18 07:20:57 +03:00
|
|
|
|
2021-07-26 10:20:15 +03:00
|
|
|
CPPFLAGS = -g -pthread -std=c++20 -fPIE \
|
2021-07-21 13:44:21 +03:00
|
|
|
-DMOLD_VERSION=\"0.9.3\" \
|
2021-05-21 07:31:31 +03:00
|
|
|
-DGIT_HASH=\"$(GIT_HASH)\" \
|
2021-05-18 07:20:57 +03:00
|
|
|
$(EXTRA_CPPFLAGS)
|
2021-07-15 18:44:40 +03:00
|
|
|
LDFLAGS += $(EXTRA_LDFLAGS)
|
2021-07-12 05:00:10 +03:00
|
|
|
LIBS = -Wl,-as-needed -lcrypto -pthread -lz -lxxhash -ldl -lm
|
2021-07-26 15:30:51 +03:00
|
|
|
OBJS = main.o object-file.o input-sections.o output-chunks.o \
|
|
|
|
mapfile.o perf.o linker-script.o archive-file.o output-file.o \
|
|
|
|
subprocess.o gc-sections.o icf.o symbols.o cmdline.o filepath.o \
|
|
|
|
passes.o tar.o compress.o memory-mapped-file.o relocatable.o \
|
|
|
|
concurrent-map.o hyperloglog.o \
|
|
|
|
arch-x86-64.o arch-i386.o arch-aarch64.o
|
2020-10-02 07:28:26 +03:00
|
|
|
|
2021-05-17 15:47:11 +03:00
|
|
|
PREFIX ?= /usr
|
2021-03-30 17:52:02 +03:00
|
|
|
DEBUG ?= 0
|
2021-05-17 17:33:30 +03:00
|
|
|
LTO ?= 0
|
|
|
|
ASAN ?= 0
|
|
|
|
TSAN ?= 0
|
|
|
|
|
2021-03-30 17:52:02 +03:00
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
CPPFLAGS += -O0
|
|
|
|
else
|
|
|
|
CPPFLAGS += -O2
|
|
|
|
endif
|
|
|
|
|
2021-04-05 16:51:15 +03:00
|
|
|
ifeq ($(LTO), 1)
|
2021-04-07 12:52:38 +03:00
|
|
|
CPPFLAGS += -flto -O3
|
|
|
|
LDFLAGS += -flto
|
2021-04-05 16:51:15 +03:00
|
|
|
endif
|
|
|
|
|
2021-04-07 12:52:38 +03:00
|
|
|
ifeq ($(ASAN), 1)
|
2021-04-07 09:38:31 +03:00
|
|
|
CPPFLAGS += -fsanitize=address
|
2021-04-07 12:52:38 +03:00
|
|
|
LDFLAGS += -fsanitize=address
|
2021-05-18 07:20:57 +03:00
|
|
|
else
|
|
|
|
# By default, we want to use mimalloc as a memory allocator.
|
|
|
|
# Since replacing the standard malloc is not compatible with ASAN,
|
|
|
|
# we do that only when ASAN is not enabled.
|
2021-07-01 04:38:30 +03:00
|
|
|
ifdef SYSTEM_MIMALLOC
|
2021-06-30 17:41:46 +03:00
|
|
|
LIBS += -lmimalloc
|
2021-07-01 04:38:30 +03:00
|
|
|
else
|
2021-07-15 18:22:39 +03:00
|
|
|
MIMALLOC_LIB = out/mimalloc/libmimalloc.a
|
2021-07-26 10:18:24 +03:00
|
|
|
CPPFLAGS += -Imimalloc/include
|
2021-07-01 04:38:30 +03:00
|
|
|
LIBS += -Wl,-whole-archive $(MIMALLOC_LIB) -Wl,-no-whole-archive
|
2021-06-30 17:41:46 +03:00
|
|
|
endif
|
2021-04-07 12:52:38 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(TSAN), 1)
|
|
|
|
CPPFLAGS += -fsanitize=thread
|
|
|
|
LDFLAGS += -fsanitize=thread
|
2021-04-07 09:38:31 +03:00
|
|
|
endif
|
|
|
|
|
2021-07-02 17:11:48 +03:00
|
|
|
ifdef SYSTEM_TBB
|
|
|
|
LIBS += -ltbb
|
|
|
|
else
|
2021-07-15 18:22:39 +03:00
|
|
|
TBB_LIB = out/tbb/libs/libtbb.a
|
2021-07-02 17:11:48 +03:00
|
|
|
LIBS += $(TBB_LIB)
|
2021-07-15 18:18:36 +03:00
|
|
|
CPPFLAGS += -Itbb/include
|
2021-07-02 17:11:48 +03:00
|
|
|
endif
|
|
|
|
|
2021-03-25 10:03:23 +03:00
|
|
|
all: mold mold-wrapper.so
|
|
|
|
|
2021-07-02 17:11:48 +03:00
|
|
|
mold: $(OBJS) $(MIMALLOC_LIB) $(TBB_LIB)
|
2021-06-30 17:41:46 +03:00
|
|
|
$(CXX) $(CXXFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS)
|
2021-07-03 14:48:38 +03:00
|
|
|
ln -sf mold ld
|
2021-03-25 10:03:23 +03:00
|
|
|
|
|
|
|
mold-wrapper.so: mold-wrapper.c Makefile
|
2021-05-18 14:12:28 +03:00
|
|
|
$(CC) -fPIC -shared -o $@ $< -ldl
|
2020-10-02 07:28:26 +03:00
|
|
|
|
2021-01-09 08:53:26 +03:00
|
|
|
$(OBJS): mold.h elf.h Makefile
|
2020-10-08 11:01:54 +03:00
|
|
|
|
2021-06-27 10:59:31 +03:00
|
|
|
$(MIMALLOC_LIB):
|
2021-07-15 18:22:39 +03:00
|
|
|
mkdir -p out/mimalloc
|
|
|
|
(cd out/mimalloc; CFLAGS=-DMI_USE_ENVIRON=0 cmake ../../mimalloc)
|
|
|
|
$(MAKE) -C out/mimalloc mimalloc-static
|
2020-09-29 09:05:29 +03:00
|
|
|
|
2021-07-02 17:11:48 +03:00
|
|
|
$(TBB_LIB):
|
2021-07-15 18:22:39 +03:00
|
|
|
mkdir -p out/tbb
|
2021-08-12 02:39:52 +03:00
|
|
|
(cd out/tbb; cmake -DBUILD_SHARED_LIBS=OFF -DTBB_TEST=OFF -DCMAKE_CXX_FLAGS=-D__TBB_DYNAMIC_LOAD_ENABLED=0 -DTBB_STRICT=OFF ../../tbb)
|
2021-07-15 18:22:39 +03:00
|
|
|
$(MAKE) -C out/tbb tbb
|
|
|
|
(cd out/tbb; ln -sf *_relwithdebinfo libs)
|
2021-07-02 17:11:48 +03:00
|
|
|
|
2021-05-21 06:48:52 +03:00
|
|
|
test tests check: all
|
2021-05-29 09:00:18 +03:00
|
|
|
$(MAKE) -C test --output-sync --no-print-directory
|
2020-09-29 09:05:29 +03:00
|
|
|
|
2021-05-14 14:41:21 +03:00
|
|
|
install: all
|
2021-07-03 09:06:06 +03:00
|
|
|
install -m 755 -d $(DESTDIR)$(PREFIX)/bin
|
2021-06-30 17:41:46 +03:00
|
|
|
install -m 755 mold $(DESTDIR)$(PREFIX)/bin
|
2021-07-01 13:05:43 +03:00
|
|
|
strip $(DESTDIR)$(PREFIX)/bin/mold
|
2021-05-18 14:10:45 +03:00
|
|
|
|
2021-06-30 17:41:46 +03:00
|
|
|
install -m 755 -d $(DESTDIR)$(PREFIX)/lib/mold
|
|
|
|
install -m 644 mold-wrapper.so $(DESTDIR)$(PREFIX)/lib/mold
|
|
|
|
strip $(DESTDIR)$(PREFIX)/lib/mold/mold-wrapper.so
|
2021-05-18 14:10:45 +03:00
|
|
|
|
2021-06-30 17:41:46 +03:00
|
|
|
install -m 755 -d $(DESTDIR)$(PREFIX)/share/man/man1
|
|
|
|
install -m 644 docs/mold.1 $(DESTDIR)$(PREFIX)/share/man/man1
|
|
|
|
rm -f $(DESTDIR)$(PREFIX)/share/man/man1/mold.1.gz
|
|
|
|
gzip -9 $(DESTDIR)$(PREFIX)/share/man/man1/mold.1
|
2021-05-14 14:41:21 +03:00
|
|
|
|
2021-05-17 16:56:58 +03:00
|
|
|
uninstall:
|
2021-07-03 09:06:06 +03:00
|
|
|
rm -f $(DESTDIR)$(PREFIX)/bin/mold
|
|
|
|
rm -f $(DESTDIR)$(PREFIX)/share/man/man1/mold.1.gz
|
|
|
|
rm -rf $(DESTDIR)$(PREFIX)/lib/mold
|
2021-05-17 16:56:58 +03:00
|
|
|
|
2020-09-29 09:05:29 +03:00
|
|
|
clean:
|
2021-07-15 18:22:39 +03:00
|
|
|
rm -rf *.o *~ mold mold-wrapper.so test/tmp out ld
|
2020-09-29 09:05:29 +03:00
|
|
|
|
2021-05-29 09:00:18 +03:00
|
|
|
.PHONY: all test tests check clean $(TESTS)
|