adapt build/install/gcc-wrapper systems for dynamic linking support

This commit is contained in:
Rich Felker 2011-06-23 22:13:47 -04:00
parent b7f6e0c6f8
commit ec05a0b08f
3 changed files with 20 additions and 9 deletions

View File

@ -35,14 +35,15 @@ EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
LIBC_LIBS = lib/libc.a LIBC_LIBS = lib/libc.a
ALL_LIBS = $(LIBC_LIBS) $(CRT_LIBS) $(EMPTY_LIBS) ALL_LIBS = $(LIBC_LIBS) $(CRT_LIBS) $(EMPTY_LIBS)
ALL_LDSO = lib/ld-musl-$(ARCH).so.1
ALL_TOOLS = tools/musl-gcc ALL_TOOLS = tools/musl-gcc
-include config.mak -include config.mak
all: $(ALL_LIBS) $(ALL_TOOLS) all: $(ALL_LIBS) $(ALL_TOOLS) $(ALL_LDSO)
install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(ALL_LDSO:%=$(DESTDIR)/%) $(ALL_LDSO:%/ld-musl-$(ARCH).so.1=$(DESTDIR)$(libdir)/libc.so)
clean: clean:
rm -f crt/*.o rm -f crt/*.o
@ -74,7 +75,7 @@ include/bits/alltypes.h: include/bits/alltypes.h.sh
%.lo: %.c $(GENH) %.lo: %.c $(GENH)
$(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $< $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
lib/libc.so: $(LOBJS) lib/ld-musl-$(ARCH).so.1: $(LOBJS)
$(CC) $(LDFLAGS) -o $@ $(LOBJS) -lgcc $(CC) $(LDFLAGS) -o $@ $(LOBJS) -lgcc
$(OBJCOPY) --weaken $@ $(OBJCOPY) --weaken $@
@ -91,15 +92,24 @@ lib/%.o: crt/%.o
cp $< $@ cp $< $@
tools/musl-gcc: tools/gen-musl-gcc.sh config.mak tools/musl-gcc: tools/gen-musl-gcc.sh config.mak
sh $< "$(prefix)" > $@ || { rm -f $@ ; exit 1 ; } sh $< "$(prefix)" "$(ARCH)" > $@ || { rm -f $@ ; exit 1 ; }
chmod +x $@ chmod +x $@
$(DESTDIR)$(bindir)/%: tools/% $(DESTDIR)$(bindir)/%: tools/%
install -D $< $@ install -D $< $@
$(DESTDIR)$(prefix)/%: % $(DESTDIR)$(libdir)/%: lib/%
install -D -m 644 $< $@ install -D -m 644 $< $@
$(DESTDIR)$(includedir)/%: include/%
install -D -m 644 $< $@
$(DESTDIR)/lib/ld-musl-$(ARCH).so.1: lib/ld-musl-$(ARCH).so.1
install -D -m 755 $< $@
$(DESTDIR)$(libdir)/libc.so: $(DESTDIR)/lib/ld-musl-$(ARCH).so.1
echo 'GROUP ( /lib/ld-musl-$(ARCH).so.1 )' > $@
.PRECIOUS: $(CRT_LIBS:lib/%=crt/%) .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
.PHONY: all clean install .PHONY: all clean install

4
dist/config.mak vendored
View File

@ -20,5 +20,5 @@ exec_prefix = /usr/local
# Uncomment for warnings (as errors). Might need tuning to your gcc version. # Uncomment for warnings (as errors). Might need tuning to your gcc version.
#CFLAGS += -Werror -Wall -Wpointer-arith -Wcast-align -Wno-parentheses -Wno-char-subscripts -Wno-uninitialized -Wno-sequence-point -Wno-missing-braces -Wno-unused-value -Wno-overflow -Wno-int-to-pointer-cast #CFLAGS += -Werror -Wall -Wpointer-arith -Wcast-align -Wno-parentheses -Wno-char-subscripts -Wno-uninitialized -Wno-sequence-point -Wno-missing-braces -Wno-unused-value -Wno-overflow -Wno-int-to-pointer-cast
# Uncomment if you want to build a shared library (experimental). # Uncomment if you want to disable building the shared library.
#LIBC_LIBS += lib/libc.so #ALL_LDSO =

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
printf '#!/bin/sh\n\nlibc_prefix="%s"\n' "$1" printf '#!/bin/sh\n\nlibc_prefix="%s"\narch="%s"\n' "$1" "$2"
cat <<"EOF" cat <<"EOF"
libc_lib=$libc_prefix/lib libc_lib=$libc_prefix/lib
@ -27,5 +27,6 @@ done
exec "$0" "$@" exec "$0" "$@"
' -std=gnu99 -nostdinc -nostdlib \ ' -std=gnu99 -nostdinc -nostdlib \
-isystem "$libc_inc" -isystem "$gcc_inc" \ -isystem "$libc_inc" -isystem "$gcc_inc" \
-Wl,-xxxxxx "$@" -L"$libc_lib" -lc -L"$libgcc" -lgcc -Lxxxxxx -Wl,-nostdlib -Wl,-xxxxxx "$@" -L"$libc_lib" -lc -L"$libgcc" -lgcc -Lxxxxxx \
-Wl,-dynamic-linker /lib/ld-musl-"$arch".so.1 -Wl,-nostdlib
EOF EOF