diff --git a/Makefile b/Makefile index 04a9134b..5c8144f0 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,10 @@ +PREFIX ?= /usr/local +BINDIR ?= $(PREFIX)/bin +LIBDIR ?= $(PREFIX)/lib +MANDIR ?= $(PREFIX)/share/man + +D = $(DESTDIR) + ifeq ($(origin CC), default) CC = clang endif @@ -10,7 +17,7 @@ OS ?= $(shell uname -s) CPPFLAGS = -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.6\" \ -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables \ - $(EXTRA_CPPFLAGS) + -DLIBDIR="\"$(LIBDIR)\"" $(EXTRA_CPPFLAGS) LDFLAGS += $(EXTRA_LDFLAGS) LIBS = -pthread -lz -lxxhash -ldl -lm @@ -18,8 +25,6 @@ SRCS=$(wildcard *.cc elf/*.cc macho/*.cc) HEADERS=$(wildcard *.h elf/*.h macho/*.h) OBJS=$(SRCS:%.cc=out/%.o) -PREFIX ?= /usr/local -DEST = $(DESTDIR)$(PREFIX) DEBUG ?= 0 LTO ?= 0 ASAN ?= 0 @@ -113,26 +118,26 @@ test tests check: all endif install: all - install -m 755 -d $(DEST)/bin - install -m 755 mold $(DEST)/bin - strip $(DEST)/bin/mold + install -m 755 -d $D$(BINDIR) + install -m 755 mold $D$(BINDIR) + strip $D$(BINDIR)/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 $D$(LIBDIR)/mold + install -m 644 mold-wrapper.so $D$(LIBDIR)/mold + strip $D$(LIBDIR)/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 + install -m 755 -d $D$(MANDIR)/man1 + install -m 644 docs/mold.1 $D$(MANDIR)/man1 + rm -f $D$(MANDIR)/man1/mold.1.gz + gzip -9 $D$(MANDIR)/man1/mold.1 - ln -sf mold $(DEST)/bin/ld.mold - ln -sf mold $(DEST)/bin/ld64.mold + ln -sf mold $D$(BINDIR)/ld.mold + ln -sf mold $D$(BINDIR)/ld64.mold uninstall: - rm -f $(DEST)/bin/mold $(DEST)/bin/ld.mold $(DEST)/bin/ld64.mold - rm -f $(DEST)/share/man/man1/mold.1.gz - rm -rf $(DEST)/lib/mold + rm -f $D$(BINDIR)/mold $D$(BINDIR)/ld.mold $D$(BINDIR)/ld64.mold + rm -f $D$(MANDIR)/man1/mold.1.gz + rm -rf $D$(LIBDIR)/mold clean: rm -rf *~ mold mold-wrapper.so out ld ld64.mold diff --git a/elf/subprocess.cc b/elf/subprocess.cc index f0962f36..3502a3ee 100644 --- a/elf/subprocess.cc +++ b/elf/subprocess.cc @@ -272,11 +272,13 @@ std::string find_dso(Context &ctx, const std::string &self) { if (is_regular_file(path)) return path; - // If not exist, mold might be installed as $PREFIX/bin/mold and the - // DSO as $PREFIX/lib/mold/mold-wrapper.so. - path = path_clean(self + "/../../lib/mold/mold-wrapper.so"); +#ifdef LIBDIR + // If not found, search $(LIBDIR)/mold, which is /usr/local/lib/mold + // by default. + path = path_clean(LIBDIR "/mold/mold-wrapper.so"); if (is_regular_file(path)) return path; +#endif Fatal(ctx) << "mold-wrapper.so is missing"; } diff --git a/test/elf/mold-wrapper2.sh b/test/elf/mold-wrapper2.sh index b7677160..79e55ea3 100755 --- a/test/elf/mold-wrapper2.sh +++ b/test/elf/mold-wrapper2.sh @@ -21,19 +21,4 @@ cp $mold-wrapper.so $t/bin $t/bin/mold -run bash -c 'echo $LD_PRELOAD' | grep -q '/bin/mold-wrapper.so' -rm -rf $t -mkdir -p $t/bin $t/lib/mold -cp $mold $t/bin -cp $mold-wrapper.so $t/lib/mold - -$t/bin/mold -run bash -c 'echo $LD_PRELOAD' | grep -q '/lib/mold/mold-wrapper.so' - -rm -rf $t -mkdir -p $t/bin $t/lib/mold -cp $mold $t/bin -cp $mold-wrapper.so $t/bin -cp $mold-wrapper.so $t/lib/mold - -$t/bin/mold -run bash -c 'echo $LD_PRELOAD' | grep -q '/bin/mold-wrapper.so' - echo OK