1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 02:20:51 +03:00
mold/Makefile

93 lines
2.4 KiB
Makefile
Raw Normal View History

2021-05-18 07:20:57 +03:00
CC = clang
CXX = clang++
MIMALLOC_LIB = mimalloc/out/release/libmimalloc.a
GIT_HASH = $(shell [ -d .git ] && git rev-parse HEAD)
2021-05-18 07:20:57 +03:00
CPPFLAGS = -g -Imimalloc/include -pthread -std=c++20 \
2021-05-21 09:21:14 +03:00
-Wno-deprecated-volatile \
2021-05-21 07:38:17 +03:00
-DMOLD_VERSION=\"0.1.1\" \
-DGIT_HASH=\"$(GIT_HASH)\" \
2021-05-18 07:20:57 +03:00
$(EXTRA_CPPFLAGS)
LDFLAGS = $(EXTRA_LDFLAGS)
LIBS = -Wl,-as-needed -lcrypto -pthread -ltbb -lz -lxxhash -ldl
2021-05-18 07:20:57 +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 \
2021-06-19 18:49:41 +03:00
passes.o tar.o compress.o memory_mapped_file.o relocatable.o \
2021-06-10 15:47:38 +03:00
arch_x86_64.o arch_i386.o
2020-10-02 07:28:26 +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.
LDFLAGS += -Wl,-whole-archive $(MIMALLOC_LIB) -Wl,-no-whole-archive
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-03-25 10:03:23 +03:00
all: mold mold-wrapper.so
2021-05-18 07:20:57 +03:00
mold: $(OBJS) $(MIMALLOC_LIB)
2020-11-30 11:06:52 +03:00
$(CXX) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS)
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
$(MIMALLOC_LIB): mimalloc/CMakeLists.txt
2021-01-18 06:54:28 +03:00
mkdir -p mimalloc/out/release
(cd mimalloc/out/release; CFLAGS=-DMI_USE_ENVIRON=0 cmake ../..)
2021-01-18 06:54:28 +03:00
$(MAKE) -C mimalloc/out/release
2020-09-29 09:05:29 +03:00
mimalloc/CMakeLists.txt:
git submodule update --init --recursive
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
install -m 755 mold $(PREFIX)/bin
strip $(PREFIX)/bin/mold
install -m 755 -d $(PREFIX)/lib/mold
install -m 644 mold-wrapper.so $(PREFIX)/lib/mold
strip $(PREFIX)/lib/mold/mold-wrapper.so
install -m 644 docs/mold.1 $(PREFIX)/share/man/man1
rm -f $(PREFIX)/share/man/man1/mold.1.gz
gzip -9 $(PREFIX)/share/man/man1/mold.1
2021-05-14 14:41:21 +03:00
2021-05-17 16:56:58 +03:00
uninstall:
rm -rf $(PREFIX)/bin/mold $(PREFIX)/share/man/man1/mold.1.gz \
$(PREFIX)/lib/mold
2020-09-29 09:05:29 +03:00
clean:
rm -rf *.o *~ mold mold-wrapper.so test/tmp
2020-09-29 09:05:29 +03:00
2021-05-29 09:00:18 +03:00
.PHONY: all test tests check clean $(TESTS)