mirror of
https://github.com/rui314/mold.git
synced 2024-11-14 07:18:42 +03:00
117 lines
3.0 KiB
Makefile
117 lines
3.0 KiB
Makefile
ifeq ($(origin CC), default)
|
|
CC = clang
|
|
endif
|
|
|
|
ifeq ($(origin CXX), default)
|
|
CXX = clang++
|
|
endif
|
|
|
|
GIT_HASH ?= $(shell [ -d .git ] && git rev-parse HEAD)
|
|
|
|
CPPFLAGS = -g -pthread -std=c++20 -fPIE \
|
|
-DMOLD_VERSION=\"0.9.4\" \
|
|
-DGIT_HASH=\"$(GIT_HASH)\" \
|
|
$(EXTRA_CPPFLAGS)
|
|
LDFLAGS += $(EXTRA_LDFLAGS)
|
|
LIBS = -Wl,-as-needed -lcrypto -pthread -lz -lxxhash -ldl -lm
|
|
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
|
|
|
|
PREFIX ?= /usr
|
|
DEST = $(DESTDIR)$(PREFIX)
|
|
DEBUG ?= 0
|
|
LTO ?= 0
|
|
ASAN ?= 0
|
|
TSAN ?= 0
|
|
|
|
ifeq ($(DEBUG), 1)
|
|
CPPFLAGS += -O0
|
|
else
|
|
CPPFLAGS += -O2
|
|
endif
|
|
|
|
ifeq ($(LTO), 1)
|
|
CPPFLAGS += -flto -O3
|
|
LDFLAGS += -flto
|
|
endif
|
|
|
|
ifeq ($(ASAN), 1)
|
|
CPPFLAGS += -fsanitize=address
|
|
LDFLAGS += -fsanitize=address
|
|
else ifeq ($(TSAN), 1)
|
|
CPPFLAGS += -fsanitize=thread
|
|
LDFLAGS += -fsanitize=thread
|
|
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.
|
|
ifdef SYSTEM_MIMALLOC
|
|
LIBS += -lmimalloc
|
|
else
|
|
MIMALLOC_LIB = out/mimalloc/libmimalloc.a
|
|
CPPFLAGS += -Imimalloc/include
|
|
LIBS += -Wl,-whole-archive $(MIMALLOC_LIB) -Wl,-no-whole-archive
|
|
endif
|
|
endif
|
|
|
|
ifdef SYSTEM_TBB
|
|
LIBS += -ltbb
|
|
else
|
|
TBB_LIB = out/tbb/libs/libtbb.a
|
|
LIBS += $(TBB_LIB)
|
|
CPPFLAGS += -Itbb/include
|
|
endif
|
|
|
|
all: mold mold-wrapper.so
|
|
|
|
mold: $(OBJS) $(MIMALLOC_LIB) $(TBB_LIB)
|
|
$(CXX) $(CXXFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS)
|
|
ln -sf mold ld
|
|
|
|
mold-wrapper.so: mold-wrapper.c Makefile
|
|
$(CC) -fPIC -shared -o $@ $< -ldl
|
|
|
|
$(OBJS): mold.h elf.h Makefile
|
|
|
|
$(MIMALLOC_LIB):
|
|
mkdir -p out/mimalloc
|
|
(cd out/mimalloc; CFLAGS=-DMI_USE_ENVIRON=0 cmake -G'Unix Makefiles' ../../mimalloc)
|
|
$(MAKE) -C out/mimalloc mimalloc-static
|
|
|
|
$(TBB_LIB):
|
|
mkdir -p out/tbb
|
|
(cd out/tbb; cmake -G'Unix Makefiles' -DBUILD_SHARED_LIBS=OFF -DTBB_TEST=OFF -DCMAKE_CXX_FLAGS=-D__TBB_DYNAMIC_LOAD_ENABLED=0 -DTBB_STRICT=OFF ../../tbb)
|
|
$(MAKE) -C out/tbb tbb
|
|
(cd out/tbb; ln -sf *_relwithdebinfo libs)
|
|
|
|
test tests check: all
|
|
$(MAKE) -C test --output-sync --no-print-directory
|
|
|
|
install: all
|
|
install -m 755 -d $(DEST)/bin
|
|
install -m 755 mold $(DEST)/bin
|
|
strip $(DEST)/bin/mold
|
|
|
|
install -m 755 -d $(DEST)/lib/mold
|
|
install -m 644 mold-wrapper.so $(DEST)/lib/mold
|
|
strip $(DEST)/lib/mold/mold-wrapper.so
|
|
|
|
install -m 755 -d $(DEST)/share/man/man1
|
|
install -m 644 docs/mold.1 $(DEST)/share/man/man1
|
|
rm -f $(DEST)/share/man/man1/mold.1.gz
|
|
gzip -9 $(DEST)/share/man/man1/mold.1
|
|
|
|
uninstall:
|
|
rm -f $(DEST)/bin/mold
|
|
rm -f $(DEST)/share/man/man1/mold.1.gz
|
|
rm -rf $(DEST)/lib/mold
|
|
|
|
clean:
|
|
rm -rf *.o *~ mold mold-wrapper.so test/tmp out ld
|
|
|
|
.PHONY: all test tests check clean $(TESTS)
|