|
Message-ID: <20151107130537.GC8500@port70.net> Date: Sat, 7 Nov 2015 14:05:37 +0100 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com Subject: Re: Support for out-of-tree build * Petr Hosek <phosek@...omium.org> [2015-11-06 23:40:48 +0000]: > I'm porting musl to (Portable) Native Client. One of the requirements we > have is out-tree-build; I've found an older patch from Szabolcs Nagy so yes, this is on the roadmap for a while now there were various iterations of this one limitation of the VPATH approach is that mixing in-tree and out-tree builds breaks: if build targets are found in the source dir after a previous in-tree build then those are not rebuilt out-tree. so at least there should be some check in the Makefile (e.g. if config.mak exists in-tree during an out-tree build) the other approach is to change the problematic %.o: $(ARCH)/%.s rules, because <dir>/%.o: $(srcdir)/<dir>/$(ARCH)/%.s cannot be expressed in make. (e.g. the dirs under src/ could be explicitly listed and then just adding $(srcdir)/ to all rules would make it work and in-/out-tree could be mixed.) > I've decided to rebase it on top of master, clean and finish it. It seems > to be working fine with the current master with all different > configurations. I'd be happy to make any changes necessary to have it > landed, please let me know if you have any comments. > From 916b69c7757ae23f37e1112ad00cb50573c0244e Mon Sep 17 00:00:00 2001 > From: Petr Hosek <phosek@...omium.org> > Date: Thu, 5 Nov 2015 14:51:50 -0800 > Subject: [PATCH] suport out-of-tree build > > this change add support for building musl outside of the source > tree. the implementation is similar to autotools where running > configure in a different folder creates config.mak in the current > working directory and symlinks the makefile, which contains the > logic for creating all necessary directories and resolving paths > relative to the source directory. based on patch by Szabolcs Nagy. > --- > Makefile | 56 ++++++++++++++++++++++++++++++++++++-------------------- > configure | 25 ++++++++++++++++++++++--- > 2 files changed, 58 insertions(+), 23 deletions(-) > > diff --git a/Makefile b/Makefile > index 2b21015..c63d588 100644 > --- a/Makefile > +++ b/Makefile > @@ -8,6 +8,7 @@ > # Do not make changes here. > # > > +srcdir = . > exec_prefix = /usr/local > bindir = $(exec_prefix)/bin > > @@ -16,8 +17,8 @@ includedir = $(prefix)/include > libdir = $(prefix)/lib > syslibdir = /lib > > -SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c)) > -OBJS = $(SRCS:.c=.o) > +SRCS = $(sort $(wildcard $(srcdir)/src/*/*.c $(srcdir)/arch/$(ARCH)/src/*.c)) > +OBJS = $(SRCS:$(srcdir)/%.c=%.o) > LOBJS = $(OBJS:.o=.lo) > GENH = include/bits/alltypes.h > GENH_INT = src/internal/version.h > @@ -32,7 +33,7 @@ CFLAGS_AUTO = -Os -pipe > CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc > > CFLAGS_ALL = $(CFLAGS_C99FSE) > -CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include > +CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/arch/$(ARCH) -I./src/internal -I$(srcdir)/src/internal -I./include -I$(srcdir)/include > CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS) > CFLAGS_ALL_STATIC = $(CFLAGS_ALL) > CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED > @@ -41,10 +42,11 @@ LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS) > > AR = $(CROSS_COMPILE)ar > RANLIB = $(CROSS_COMPILE)ranlib > -INSTALL = ./tools/install.sh > +INSTALL = $(srcdir)/tools/install.sh > > -ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h) > -ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%)) > +ARCH_INCLUDES = $(wildcard $(srcdir)/arch/$(ARCH)/bits/*.h) > +INCLUDES = $(wildcard $(srcdir)/include/*.h $(srcdir)/include/*/*.h) > +ALL_INCLUDES = $(sort $(INCLUDES:$(srcdir)/%=%) $(GENH) $(ARCH_INCLUDES:$(srcdir)/arch/$(ARCH)/%=include/%)) > > EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl > EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) > @@ -64,6 +66,20 @@ LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1 > > all: $(ALL_LIBS) $(ALL_TOOLS) > > +ifneq ($(srcdir),.) > +VPATH = $(srcdir) > +$(ALL_TOOLS): tools/.dirstamp > +$(ALL_LIBS): lib/.dirstamp > +$(CRT_LIBS:lib/%=crt/%): crt/.dirstamp > +$(OBJS) $(LOBJS): $(patsubst %/,%/.dirstamp,$(sort $(dir $(OBJS)))) > +$(GENH): arch/$(ARCH)/bits/.dirstamp > +include/bits: include/.dirstamp > +src/internal/version.h: src/internal/.dirstamp > +%/.dirstamp: > + mkdir -p $* > + touch $@ > +endif > + i guess this works without the ifneq, just litters the source dir with .dirstamps in case of an in-tree build. > install: install-libs install-headers install-tools > > clean: > @@ -82,26 +98,24 @@ include/bits: > @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; } > ln -sf ../arch/$(ARCH)/bits $@ > > -include/bits/alltypes.h.in: include/bits > +include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in $(srcdir)/tools/mkalltypes.sed include/bits > + sed -f $(srcdir)/tools/mkalltypes.sed $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in > $@ > > -include/bits/alltypes.h: include/bits/alltypes.h.in include/alltypes.h.in tools/mkalltypes.sed > - sed -f tools/mkalltypes.sed include/bits/alltypes.h.in include/alltypes.h.in > $@ > - > -src/internal/version.h: $(wildcard VERSION .git) > - printf '#define VERSION "%s"\n' "$$(sh tools/version.sh)" > $@ > +src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git) > + printf '#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@ > > src/internal/version.lo: src/internal/version.h > > crt/rcrt1.o src/ldso/dlstart.lo src/ldso/dynlink.lo: src/internal/dynlink.h arch/$(ARCH)/reloc.h > > -crt/crt1.o crt/Scrt1.o crt/rcrt1.o src/ldso/dlstart.lo: $(wildcard arch/$(ARCH)/crt_arch.h) > +crt/crt1.o crt/scrt1.o crt/rcrt1.o src/ldso/dlstart.lo: $(wildcard $(srcdir)/arch/$(ARCH)/crt_arch.h) > > crt/rcrt1.o: src/ldso/dlstart.c > > crt/Scrt1.o crt/rcrt1.o: CFLAGS_ALL += -fPIC > > -OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%)) > -$(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3 > +OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%)) > +$(OPTIMIZE_SRCS:$(srcdir)/%.c=%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=%.lo): CFLAGS += -O3 > > MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c > $(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS) > @@ -119,14 +133,14 @@ $(CRT_LIBS:lib/%=crt/%): CFLAGS_ALL += -DCRT > # force the corresponding object file to be rebuilt, even if the implicit > # rule below goes indirectly through a .sub file. > define mkasmdep > -$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1) > +$(dir $(patsubst $(srcdir)/%/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1) > endef > -$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s)))) > +$(foreach s,$(wildcard $(srcdir)/src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s)))) > > # Choose invocation of assembler to be used > # $(1) is input file, $(2) is output file, $(3) is assembler flags > ifeq ($(ADD_CFI),yes) > - AS_CMD = LC_ALL=C awk -f tools/add-cfi.common.awk -f tools/add-cfi.$(ARCH).awk $< | $(CC) -x assembler -c -o $@ - > + AS_CMD = LC_ALL=C awk -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) -x assembler -c -o $@ - > else > AS_CMD = $(CC) -c -o $@ $< > endif > @@ -202,9 +216,11 @@ install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) > install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) > > musl-git-%.tar.gz: .git > - git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@) > + git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@) > > musl-%.tar.gz: .git > - git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@) > + git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@) > + > +.SECONDARY: > what does .SECONDARY do? > .PHONY: all clean install install-libs install-headers install-tools > diff --git a/configure b/configure > index dece1d0..b2d0c8d 100755 > --- a/configure > +++ b/configure > @@ -9,6 +9,9 @@ VAR=VALUE. See below for descriptions of some of the useful variables. > > Defaults for the options are specified in brackets. > > +Configuration: > + --srcdir=DIR source directory [detected] > + > Installation directories: > --prefix=PREFIX main installation prefix [/usr/local/musl] > --exec-prefix=EPREFIX installation prefix for executable files [PREFIX] > @@ -117,6 +120,7 @@ CFLAGS_TRY= > LDFLAGS_AUTO= > LDFLAGS_TRY= > OPTIMIZE_GLOBS= > +srcdir= > prefix=/usr/local/musl > exec_prefix='$(prefix)' > bindir='$(exec_prefix)/bin' > @@ -139,6 +143,7 @@ clang_wrapper=no > for arg ; do > case "$arg" in > --help) usage ;; > +--srcdir=*) srcdir=${arg#*=} ;; > --prefix=*) prefix=${arg#*=} ;; > --exec-prefix=*) exec_prefix=${arg#*=} ;; > --bindir=*) bindir=${arg#*=} ;; > @@ -179,11 +184,23 @@ LIBCC=*) LIBCC=${arg#*=} ;; > esac > done > > -for i in prefix exec_prefix bindir libdir includedir syslibdir ; do > +for i in srcdir prefix exec_prefix bindir libdir includedir syslibdir ; do > stripdir $i > done > > # > +# Get the musl source dir for out-of-tree builds > +# > +if test -z "$srcdir" ; then > +srcdir="${0%/configure}" > +stripdir srcdir > +fi > +abs_builddir="$(pwd)" || fail "$0: cannot determine working directory" > +abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir" > +test "$abs_srcdir" = "$abs_builddir" && srcdir=. > +ln -sf $srcdir/Makefile . > + > +# > # Get a temp filename we can use > # > i=0 > @@ -293,6 +310,7 @@ microblaze*) ARCH=microblaze ;; > or1k*) ARCH=or1k ;; > powerpc*) ARCH=powerpc ;; > sh[1-9bel-]*|sh|superh*) ARCH=sh ;; > +le32*) ARCH=le32 ;; is le32 something native client related? > unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;; > *) fail "$0: unknown or unsupported target \"$target\"" ;; > esac > @@ -321,7 +339,7 @@ __attribute__((__may_alias__)) > #endif > x; > EOF > -if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \ > +if $CC $CFLAGS_C99FSE -I$srcdir/arch/$ARCH -I$srcdir/include $CPPFLAGS $CFLAGS \ > -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then > printf "no\n" > else > @@ -620,7 +638,7 @@ echo '#include <float.h>' > "$tmpc" > echo '#if LDBL_MANT_DIG == 53' >> "$tmpc" > echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc" > echo '#endif' >> "$tmpc" > -if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \ > +if $CC $CFLAGS_C99FSE -I$srcdir/arch/$ARCH -I$srcdir/include $CPPFLAGS $CFLAGS \ > -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then > printf "yes\n" > else > @@ -643,6 +661,7 @@ cat << EOF > ARCH = $ARCH > SUBARCH = $SUBARCH > ASMSUBARCH = $ASMSUBARCH > +srcdir = $srcdir > prefix = $prefix > exec_prefix = $exec_prefix > bindir = $bindir > -- > 2.6.0.rc2.230.g3dd15c0 >
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.