1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-11 05:46:58 +03:00
mold/Makefile

139 lines
3.2 KiB
Makefile
Raw Normal View History

ifeq ($(origin CC), default)
2021-08-25 06:48:41 +03:00
CC = clang
endif
ifeq ($(origin CXX), default)
2021-08-25 06:48:41 +03:00
CXX = clang++
endif
2021-05-18 07:20:57 +03:00
2021-09-01 09:34:12 +03:00
OS ?= $(shell uname -s)
2021-09-28 10:40:05 +03:00
CPPFLAGS = -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.6\" $(EXTRA_CPPFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
2021-09-01 09:34:12 +03:00
LIBS = -pthread -lz -lxxhash -ldl -lm
2021-09-02 17:16:47 +03:00
2021-09-08 13:02:38 +03:00
SRCS=$(wildcard *.cc elf/*.cc macho/*.cc)
HEADERS=$(wildcard *.h elf/*.h macho/*.h)
OBJS=$(SRCS:%.cc=out/%.o)
2020-10-02 07:28:26 +03:00
PREFIX ?= /usr
2021-08-25 06:50:27 +03:00
DEST = $(DESTDIR)$(PREFIX)
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-09-28 10:40:05 +03:00
GIT_HASH ?= $(shell [ -d .git ] && git rev-parse HEAD)
ifneq ($(GIT_HASH),)
CPPFLAGS += -DGIT_HASH=\"$(GIT_HASH)\"
endif
2021-03-30 17:52:02 +03:00
ifeq ($(DEBUG), 1)
CPPFLAGS += -O0 -g
2021-03-30 17:52:02 +03:00
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-08-19 05:50:44 +03:00
else ifeq ($(TSAN), 1)
CPPFLAGS += -fsanitize=thread
LDFLAGS += -fsanitize=thread
2021-09-01 09:34:12 +03:00
else ifneq ($(OS), Darwin)
2021-05-18 07:20:57 +03:00
# 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 += -Ithird-party/mimalloc/include
LIBS += -Wl,-whole-archive $(MIMALLOC_LIB) -Wl,-no-whole-archive
endif
2021-04-07 12:52:38 +03:00
endif
ifdef SYSTEM_TBB
LIBS += -ltbb
else
TBB_LIB = out/tbb/libs/libtbb.a
LIBS += $(TBB_LIB)
CPPFLAGS += -Ithird-party/tbb/include
endif
2021-09-01 09:34:12 +03:00
ifneq ($(OS), Darwin)
LIBS += -lcrypto
endif
2021-03-25 10:03:23 +03:00
all: mold mold-wrapper.so
mold: $(OBJS) $(MIMALLOC_LIB) $(TBB_LIB)
2021-09-07 14:35:26 +03:00
$(CXX) $(CPPFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS)
2021-07-03 14:48:38 +03:00
ln -sf mold ld
2021-09-08 13:15:12 +03:00
ln -sf mold ld64.mold
2021-03-25 10:03:23 +03:00
2021-09-02 17:16:47 +03:00
mold-wrapper.so: elf/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-09-08 13:02:38 +03:00
out/%.o: %.cc $(HEADERS) Makefile out/elf/.keep out/macho/.keep
2021-09-07 14:17:31 +03:00
$(CXX) $(CPPFLAGS) -c -o $@ $<
2021-09-07 14:35:26 +03:00
out/elf/.keep:
mkdir -p out/elf
touch $@
2020-10-08 11:01:54 +03:00
2021-09-08 13:02:38 +03:00
out/macho/.keep:
mkdir -p out/macho
touch $@
$(MIMALLOC_LIB):
mkdir -p out/mimalloc
(cd out/mimalloc; CFLAGS=-DMI_USE_ENVIRON=0 cmake -G'Unix Makefiles' ../../third-party/mimalloc)
$(MAKE) -C out/mimalloc mimalloc-static
2020-09-29 09:05:29 +03:00
$(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 ../../third-party/tbb)
$(MAKE) -C out/tbb tbb
(cd out/tbb; ln -sf *_relwithdebinfo libs)
ifeq ($(OS), Darwin)
test tests check: all
$(MAKE) -C test -f Makefile.darwin --no-print-directory
else
test tests check: all
$(MAKE) -C test -f Makefile.linux --no-print-directory --output-sync
endif
2020-09-29 09:05:29 +03:00
2021-05-14 14:41:21 +03:00
install: all
2021-08-25 06:50:27 +03:00
install -m 755 -d $(DEST)/bin
install -m 755 mold $(DEST)/bin
strip $(DEST)/bin/mold
2021-08-25 06:50:27 +03:00
install -m 755 -d $(DEST)/lib/mold
install -m 644 mold-wrapper.so $(DEST)/lib/mold
strip $(DEST)/lib/mold/mold-wrapper.so
2021-08-25 06:50:27 +03:00
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
2021-05-14 14:41:21 +03:00
2021-09-08 13:15:12 +03:00
ln -sf mold $(DEST)/bin/ld.mold
ln -sf mold $(DEST)/bin/ld64.mold
2021-05-17 16:56:58 +03:00
uninstall:
2021-09-08 14:22:51 +03:00
rm -f $(DEST)/bin/mold $(DEST)/bin/ld.mold $(DEST)/bin/ld64.mold
2021-08-25 06:50:27 +03:00
rm -f $(DEST)/share/man/man1/mold.1.gz
rm -rf $(DEST)/lib/mold
2021-05-17 16:56:58 +03:00
2020-09-29 09:05:29 +03:00
clean:
2021-09-08 13:15:12 +03:00
rm -rf *~ mold mold-wrapper.so out ld ld64.mold
2020-09-29 09:05:29 +03:00
2021-09-08 09:56:45 +03:00
.PHONY: all test tests check clean