From: Petr Hosek <phosek@chromium.org>
To: musl@lists.openwall.com
Subject: Re: Support for out-of-tree build
Date: Thu, 19 Nov 2015 00:22:09 +0000 [thread overview]
Message-ID: <CABBv4TYv2z3+=dESvMiMnZr43UXGskr8SZjXw+R=8epD0FRToA@mail.gmail.com> (raw)
In-Reply-To: <20151118214452.GQ3818@brightrain.aerifal.cx>
[-- Attachment #1.1: Type: text/plain, Size: 9945 bytes --]
On Wed, Nov 18, 2015 at 1:45 PM Rich Felker <dalias@libc.org> wrote:
> > -SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
> > -OBJS = $(SRCS:.c=.o)
> > +BASE_SRCS = $(sort $(wildcard $(srcdir)/src/*/*.c
> $(srcdir)/arch/$(ARCH)/src/*.c))
> > +BASE_OBJS = $(BASE_SRCS:$(srcdir)/%.c=%.o)
> > +ARCH_SRCS = $(wildcard $(srcdir)/src/*/$(ARCH)/*.s)
> > +ARCH_OBJS = $(ARCH_SRCS:$(srcdir)/%.s=%.o)
> > +SUB_SRCS = $(wildcard $(srcdir)/src/*/$(ARCH)$(ASMSUBARCH)/*.sub)
> > +SUB_OBJS = $(SUB_SRCS:$(srcdir)/%.sub=%.o)
> > +EXCLUDE_ARCH_OBJS = $(patsubst $(srcdir)/%,%,$(subst
> /$(ARCH)/,/,$(patsubst $(srcdir)/%,%,$(ARCH_OBJS))))
> > +EXCLUDE_SUB_OBJS = $(patsubst $(srcdir)/%,%,$(subst
> /$(ARCH)$(ASMSUBARCH)/,/,$(patsubst $(srcdir)/%,%,$(SUB_OBJS))))
> > +OBJS = $(addprefix $(objdir)/, $(filter-out $(EXCLUDE_SUB_OBJS)
> $(EXCLUDE_ARCH_OBJS), $(BASE_OBJS)) $(ARCH_OBJS) $(SUB_OBJS))
>
> Why not just put all the arch files (whether they come from .s or
> .sub, or in the future .c or .S) together in ARCH_OBJS? I think this
> can all be done with no intermediate *_SRCS vars (and probably even
> without SRCS) with some explicit $(patsubst...) etc. Actually I'm a
> bit surprised if things like this work:
>
> $(BASE_SRCS:$(srcdir)/%.c=%.o)
>
> I had trouble with % in the middle of the pattern not doing what I
> expected it to.
>
I have merged ARCH_* and SUB_* into ARCH_*.
> > 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) $(sort
> -I$(objdir)/src/internal -I$(srcdir)/src/internal) $(sort
> -I$(objdir)/include -I$(srcdir)/include)
>
> What is the $(sort...) for now? Before I thought it was to remove
> duplicates, but now they will not be duplicates unless you're trying
> to support objdir=. -- is that your intent? I don't think it will
> work based on our discussions yesterday.
>
Correct, this would only make sense if objdir=. but then the implicit rules
wouldn't work so we don't need to support that scenario.
> > clean:
> > - rm -f crt/*.o
> > + rm -f $(objdir)/crt/*.o
> > rm -f $(OBJS)
> > rm -f $(LOBJS)
> > rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
>
> This can probably just be rm -rf obj, but perhaps we should wait to
> make that change. And seeing this, I'm mildly in favor of hard-coding
> obj/ (everywhere) rather than using $(objdir)/ simply because the
> latter is really dangerous if you override it on the command line with
> an unwanted setting (like make clean objdir=/).
>
That's why I avoided using rm -rf $(objdir). I can imagine the use case for
setting $(objdir) to a different location, changing this to make it
hard-coded wouldn't be a problem if you prefer.
> > -include/bits:
> > +$(objdir)/include/bits:
> > @test "$(ARCH)" || { echo "Please set ARCH in config.mak before
> running make." ; exit 1 ; }
> > ln -sf ../arch/$(ARCH)/bits $@
>
> I think this may be problematic -- for an in-tree build, you'll get a
> bits symlink in the source include dir, and then out-of-tree builds
> might use it. Include order might prevent that but it sounds fragile.
> We should probably eliminate the bits symlink here.
>
I agree, if we're not going to support the objdir=. scenario, we can remove
the symlink. It'll also simplify some of the directory dependencies.
> > -include/bits/alltypes.h.in: include/bits
> > -
> > -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 > $@
> > +$(objdir)/include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/
> alltypes.h.in $(srcdir)/include/alltypes.h.in
> $(srcdir)/tools/mkalltypes.sed $(objdir)/include/bits
> > + sed -f $(srcdir)/tools/mkalltypes.sed $(srcdir)/arch/$(ARCH)/bits/
> alltypes.h.in $(srcdir)/include/alltypes.h.in > $@
>
> So the generated alltypes.h goes in obj/include/bits? But the
> installation rule does not seem to get it from there. It seems to only
> look in arch/$(ARCH)/bits/%. I guess the above symlink causes them to
> be the same, but I don't think there's actually a dependency in the
> makefile to let make know that...
>
That's fixed, well spotted.
> > -src/internal/version.h: $(wildcard VERSION .git)
> > - printf '#define VERSION "%s"\n' "$$(sh tools/version.sh)" > $@
> > +$(objdir)/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
> > +$(objdir)/src/internal/version.lo: $(objdir)/src/internal/version.h
> >
> > -crt/rcrt1.o src/ldso/dlstart.lo src/ldso/dynlink.lo:
> src/internal/dynlink.h arch/$(ARCH)/reloc.h
> > +$(objdir)/crt/rcrt1.o $(objdir)/src/ldso/dlstart.lo
> $(objdir)/src/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h
> $(srcdir)/arch/$(ARCH)/reloc.h
> >
> > -crt/crt1.o crt/Scrt1.o crt/rcrt1.o src/ldso/dlstart.lo: $(wildcard
> arch/$(ARCH)/crt_arch.h)
> > +$(objdir)/crt/crt1.o $(objdir)/crt/scrt1.o $(objdir)/crt/rcrt1.o
> $(objdir)/src/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h
> >
> > -crt/rcrt1.o: src/ldso/dlstart.c
> > +$(objdir)/crt/rcrt1.o: $(srcdir)/src/ldso/dlstart.c
> >
> > -crt/Scrt1.o crt/rcrt1.o: CFLAGS_ALL += -fPIC
> > +$(objdir)/crt/Scrt1.o $(objdir)/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=$(objdir)/%.o)
> $(OPTIMIZE_SRCS:$(srcdir)/%.c=$(objdir)/%.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)
> > +$(MEMOPS_SRCS:%.c=$(objdir)/%.o) $(MEMOPS_SRCS:%.c=$(objdir)/%.lo):
> CFLAGS_ALL += $(CFLAGS_MEMOPS)
> >
> > NOSSP_SRCS = $(wildcard crt/*.c) \
> > - src/env/__libc_start_main.c src/env/__init_tls.c \
> > - src/thread/__set_thread_area.c src/env/__stack_chk_fail.c \
> > - src/string/memset.c src/string/memcpy.c \
> > - src/ldso/dlstart.c src/ldso/dynlink.c
> > -$(NOSSP_SRCS:%.c=%.o) $(NOSSP_SRCS:%.c=%.lo): CFLAGS_ALL +=
> $(CFLAGS_NOSSP)
> > -
> > -$(CRT_LIBS:lib/%=crt/%): CFLAGS_ALL += -DCRT
> > -
> > -# This incantation ensures that changes to any subarch asm files will
> > -# 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)
> > -endef
> > -$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call
> mkasmdep,$(s))))
>
> Simply removing this will break dependency-based regeneration of
> object files that use .sub files when the underlying .s file changes.
> Maybe we don't care since .sub files will be removed soon, but it
> should be noted as a regression for the time being, or we should just
> transform this for out-of-tree support.
>
Reverted and update to work with the new setup.
> > + $(srcdir)/src/env/__libc_start_main.c
> $(srcdir)/src/env/__init_tls.c \
> > + $(srcdir)/src/thread/__set_thread_area.c
> $(srcdir)/src/env/__stack_chk_fail.c \
> > + $(srcdir)/src/string/memset.c $(srcdir)/src/string/memcpy.c \
> > + $(srcdir)/src/ldso/dlstart.c $(srcdir)/src/ldso/dynlink.c
>
> It might make sense to use a function to apply a prefix to all of
> these rather than repeating $(srcdir)/ over and over.
>
> > +$(NOSSP_SRCS:$(srcdir)/%.c=$(objdir)/%.o)
> $(NOSSP_SRCS:$(srcdir)/%.c=$(objdir)/%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP)
>
> Actually I think we don't even want $(srcdir) there to begin with.
> It's just removed immediately.
>
Removed.
> > +
> > +$(CRT_LIBS:lib/%=$(objdir)/crt/%): CFLAGS_ALL += -DCRT
>
> I'm not clear on whether crti.o/crtn.o end up in crt/ or crt/$(ARCH)/
> but if it's the latter we need to handle this somehow.
>
These end up in crt/ even in the current upstream implementation.
> > -%.lo: $(ARCH)$(ASMSUBARCH)/%.sub
> > - $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
> > +$(objdir)/%.lo: $(srcdir)/%.sub
> > + $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
>
> Looks like you got a spurious space in there.
>
Removed.
> > -lib/%.o: crt/%.o
> > +lib/%.o: $(objdir)/crt/%.o
> > cp $< $@
>
> This also depends on crti.o/crtn.o not being in an arch subdir.
>
> > +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/$(ARCH)/bits/%
> > + $(INSTALL) -D -m 644 $< $@
> > +
> > $(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
> > $(INSTALL) -D -m 644 $< $@
>
> This is the rule I mentioned above that doesn't seem to have any way
> for make to know how to generate arch/$(ARCH)/bits/alltypes.h unless
> it already happened to be generated.
>
Fixed.
> > +# Get the musl source dir for out-of-tree builds
>
> I don't recall if I've followed this principle myself, but it probably
> makes sense to avoid writing musl explicitly all over the configure
> script in case someone goes and reuses parts of it for another
> project.
>
Removed.
> > +#
> > +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 .
>
> Doesn't this do ln -sf ./Makefile . when srcdir=.? That needs to be
> suppressed, and the ln should probably not happen until the configure
> script has "succeeded", at the same time config.mak is generated.
>
Check added and moved to the bottom. of the configure script.
[-- Attachment #1.2: Type: text/html, Size: 13614 bytes --]
[-- Attachment #2: support-out-of-tree-build.patch --]
[-- Type: text/x-patch, Size: 13615 bytes --]
From a0e52a03744ddc72a4803efbb2cd904d1ff4012c Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek@chromium.org>
Date: Wed, 18 Nov 2015 12:07:32 -0800
Subject: [PATCH] support 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.
to support both in-tree and out-of-tree builds with implicit make
rules, all object files are now placed into a separate directory.
---
.gitignore | 1 +
Makefile | 109 +++++++++++++++++++++++++++++++++++--------------------------
configure | 25 ++++++++++++--
3 files changed, 86 insertions(+), 49 deletions(-)
diff --git a/.gitignore b/.gitignore
index c5d5c46..36dc5f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
*.a
*.so
*.so.1
+obj
arch/*/bits/alltypes.h
config.mak
include/bits
diff --git a/Makefile b/Makefile
index df20f94..7c8954d 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,8 @@
# Do not make changes here.
#
+srcdir = .
+objdir = obj
exec_prefix = /usr/local
bindir = $(exec_prefix)/bin
@@ -16,12 +18,16 @@ includedir = $(prefix)/include
libdir = $(prefix)/lib
syslibdir = /lib
-SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
-OBJS = $(SRCS:.c=.o)
+BASE_SRCS = $(sort $(wildcard $(srcdir)/src/*/*.c $(srcdir)/arch/$(ARCH)/src/*.c))
+BASE_OBJS = $(patsubst $(srcdir)/%.c,%.o,$(BASE_SRCS))
+ARCH_SRCS = $(wildcard $(srcdir)/src/*/$(ARCH)/*.s $(srcdir)/src/*/$(ARCH)$(ASMSUBARCH)/*.sub)
+ARCH_OBJS = $(patsubst $(srcdir)/%.sub,%.o,$(patsubst $(srcdir)/%.s,%.o,$(ARCH_SRCS)))
+EXCLUDE_OBJS = $(patsubst $(srcdir)/%,%,$(subst /$(ARCH)$(ASMSUBARCH)/,/,$(subst /$(ARCH)/,/,$(patsubst $(srcdir)/%,%,$(ARCH_OBJS)))))
+OBJS = $(addprefix $(objdir)/, $(filter-out $(EXCLUDE_OBJS), $(BASE_OBJS)) $(ARCH_OBJS) $(SUB_OBJS))
LOBJS = $(OBJS:.o=.lo)
-GENH = include/bits/alltypes.h
-GENH_INT = src/internal/version.h
-IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
+GENH = $(objdir)/include/bits/alltypes.h
+GENH_INT = $(objdir)/src/internal/version.h
+IMPH = $(addprefix $(srcdir)/, src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h)
LDFLAGS =
LDFLAGS_AUTO =
@@ -32,7 +38,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$(objdir)/src/internal -I$(srcdir)/src/internal -I$(objdir)/include -I$(srcdir)/include
CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS)
CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
@@ -41,10 +47,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:$(objdir)/%=%) $(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,10 +71,22 @@ LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
all: $(ALL_LIBS) $(ALL_TOOLS)
+$(ALL_LIBS): | lib/
+$(ALL_TOOLS): | tools/
+$(CRT_LIBS:lib/%=$(objdir)/crt/%): | $(objdir)/crt/
+$(OBJS) $(LOBJS): | $(sort $(dir $(OBJS)))
+$(GENH): | $(objdir)/include/bits/
+$(GENH_INT): | $(objdir)/src/internal/
+
+SRC_DIRS = $(sort $(dir $(ALL_LIBS) $(ALL_TOOLS) $(OBJS) $(GENH) $(GENH_INT)) $(addprefix $(objdir)/, crt/ include/))
+
+$(SRC_DIRS):
+ mkdir -p $@
+
install: install-libs install-headers install-tools
clean:
- rm -f crt/*.o
+ rm -f $(objdir)/crt/*.o
rm -f $(OBJS)
rm -f $(LOBJS)
rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
@@ -78,75 +97,70 @@ clean:
distclean: clean
rm -f config.mak
-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
+$(objdir)/include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in $(srcdir)/tools/mkalltypes.sed $(objdir)/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 > $@
+$(objdir)/src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git)
+ printf '#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@
-src/internal/version.h: $(wildcard VERSION .git)
- printf '#define VERSION "%s"\n' "$$(sh tools/version.sh)" > $@
+$(objdir)/src/internal/version.o $(objdir)/src/internal/version.lo: $(objdir)/src/internal/version.h
-src/internal/version.o src/internal/version.lo: src/internal/version.h
+$(objdir)/crt/rcrt1.o $(objdir)/src/ldso/dlstart.lo $(objdir)/src/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h
-crt/rcrt1.o src/ldso/dlstart.lo src/ldso/dynlink.lo: src/internal/dynlink.h arch/$(ARCH)/reloc.h
+$(objdir)/crt/crt1.o $(objdir)/crt/scrt1.o $(objdir)/crt/rcrt1.o $(objdir)/src/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h
-crt/crt1.o crt/Scrt1.o crt/rcrt1.o src/ldso/dlstart.lo: $(wildcard arch/$(ARCH)/crt_arch.h)
+$(objdir)/crt/rcrt1.o: $(srcdir)/src/ldso/dlstart.c
-crt/rcrt1.o: src/ldso/dlstart.c
+$(objdir)/crt/Scrt1.o $(objdir)/crt/rcrt1.o: CFLAGS_ALL += -fPIC
-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=$(objdir)/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=$(objdir)/%.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)
+$(MEMOPS_SRCS:%.c=$(objdir)/%.o) $(MEMOPS_SRCS:%.c=$(objdir)/%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS)
NOSSP_SRCS = $(wildcard crt/*.c) \
src/env/__libc_start_main.c src/env/__init_tls.c \
src/thread/__set_thread_area.c src/env/__stack_chk_fail.c \
src/string/memset.c src/string/memcpy.c \
src/ldso/dlstart.c src/ldso/dynlink.c
-$(NOSSP_SRCS:%.c=%.o) $(NOSSP_SRCS:%.c=%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP)
+$(NOSSP_SRCS:%.c=$(objdir)/%.o) $(NOSSP_SRCS:%.c=$(objdir)/%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP)
-$(CRT_LIBS:lib/%=crt/%): CFLAGS_ALL += -DCRT
+$(CRT_LIBS:lib/%=$(objdir)/crt/%): CFLAGS_ALL += -DCRT
# This incantation ensures that changes to any subarch asm files will
# force the corresponding object file to be rebuilt, even if the implicit
# rule below goes indirectly through a .sub file.
+#$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1)
define mkasmdep
-$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1)
+$(patsubst $(srcdir)/%,$(objdir)/%,$(dir $(patsubst %/,%,$(dir $(1))))$(ARCH)$(ASMSUBARCH)/$(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
-%.o: $(ARCH)$(ASMSUBARCH)/%.sub
+$(objdir)/%.o: $(srcdir)/%.sub
$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
-%.o: $(ARCH)/%.s
+$(objdir)/%.o: $(srcdir)/%.s
$(AS_CMD) $(CFLAGS_ALL_STATIC)
-%.o: %.c $(GENH) $(IMPH)
+$(objdir)/%.o: $(srcdir)/%.c $(GENH) $(IMPH)
$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
-%.lo: $(ARCH)$(ASMSUBARCH)/%.sub
+$(objdir)/%.lo: $(srcdir)/%.sub
$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
-%.lo: $(ARCH)/%.s
+$(objdir)/%.lo: $(srcdir)/%.s
$(AS_CMD) $(CFLAGS_ALL_SHARED)
-%.lo: %.c $(GENH) $(IMPH)
+$(objdir)/%.lo: $(srcdir)/%.c $(GENH) $(IMPH)
$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
lib/libc.so: $(LOBJS)
@@ -163,17 +177,17 @@ $(EMPTY_LIBS):
rm -f $@
$(AR) rc $@
-lib/%.o: crt/%.o
+lib/%.o: $(objdir)/crt/%.o
cp $< $@
-lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
+lib/musl-gcc.specs: $(srcdir)/tools/musl-gcc.specs.sh config.mak
sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
tools/musl-gcc: config.mak
printf '#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
chmod +x $@
-tools/%-clang: tools/%-clang.in config.mak
+tools/%-clang: $(srcdir)/tools/%-clang.in config.mak
sed -e 's!@CC@!$(WRAPCC_CLANG)!g' -e 's!@PREFIX@!$(prefix)!g' -e 's!@INCDIR@!$(includedir)!g' -e 's!@LIBDIR@!$(libdir)!g' -e 's!@LDSO@!$(LDSO_PATHNAME)!g' $< > $@
chmod +x $@
@@ -186,10 +200,13 @@ $(DESTDIR)$(libdir)/%.so: lib/%.so
$(DESTDIR)$(libdir)/%: lib/%
$(INSTALL) -D -m 644 $< $@
-$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
+$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/$(ARCH)/bits/%
+ $(INSTALL) -D -m 644 $< $@
+
+$(DESTDIR)$(includedir)/bits/%: $(objdir)/include/bits/%
$(INSTALL) -D -m 644 $< $@
-$(DESTDIR)$(includedir)/%: include/%
+$(DESTDIR)$(includedir)/%: $(srcdir)/include/%
$(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
@@ -202,9 +219,9 @@ 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,%,$@)
.PHONY: all clean install install-libs install-headers install-tools
diff --git a/configure b/configure
index ee21771..0fac304 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,22 @@ 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 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=.
+
+#
# Get a temp filename we can use
#
i=0
@@ -321,7 +337,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
@@ -625,7 +641,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
@@ -648,6 +664,7 @@ cat << EOF
ARCH = $ARCH
SUBARCH = $SUBARCH
ASMSUBARCH = $ASMSUBARCH
+srcdir = $srcdir
prefix = $prefix
exec_prefix = $exec_prefix
bindir = $bindir
@@ -676,4 +693,6 @@ test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)'
test "x$cc_family" = xclang && echo 'WRAPCC_CLANG = $(CC)'
exec 1>&3 3>&-
+test -f Makefile || ln -sf $srcdir/Makefile .
+
printf "done\n"
--
2.6.0.rc2.230.g3dd15c0
next prev parent reply other threads:[~2015-11-19 0:22 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-06 23:40 Petr Hosek
2015-11-07 13:05 ` Szabolcs Nagy
2015-11-08 0:43 ` Rich Felker
2015-11-08 2:16 ` Szabolcs Nagy
2015-11-08 2:29 ` Rich Felker
2015-11-11 22:02 ` Petr Hosek
2015-11-11 23:08 ` Rich Felker
2015-11-12 0:01 ` Rich Felker
2015-11-12 0:28 ` Petr Hosek
2015-11-12 14:50 ` Szabolcs Nagy
2015-11-12 20:17 ` Petr Hosek
2015-11-12 20:30 ` Rich Felker
2015-11-12 21:10 ` Szabolcs Nagy
2015-11-12 21:52 ` Rich Felker
2015-11-12 22:35 ` Petr Hosek
2015-11-12 23:41 ` Rich Felker
2015-11-17 2:45 ` Petr Hosek
2015-11-17 6:05 ` Petr Hosek
2015-11-17 19:51 ` Szabolcs Nagy
2015-11-17 21:00 ` Rich Felker
2015-11-17 21:37 ` Petr Hosek
2015-11-17 22:01 ` Rich Felker
2015-11-17 22:15 ` Petr Hosek
2015-11-17 22:58 ` Rich Felker
2015-11-17 23:06 ` Szabolcs Nagy
2015-11-17 23:27 ` Rich Felker
2015-11-17 23:43 ` Rich Felker
2015-11-17 23:54 ` Petr Hosek
2015-11-18 0:19 ` Szabolcs Nagy
2015-11-18 0:19 ` Rich Felker
2015-11-18 20:19 ` Petr Hosek
2015-11-18 21:44 ` Rich Felker
2015-11-19 0:22 ` Petr Hosek [this message]
2015-11-20 4:09 ` Rich Felker
2015-11-20 5:02 ` Rich Felker
2015-11-20 10:51 ` Szabolcs Nagy
2015-11-30 1:25 ` Petr Hosek
2015-11-20 22:20 ` Rich Felker
2015-11-30 1:29 ` Petr Hosek
2015-11-30 1:35 ` Rich Felker
2015-11-30 2:49 ` Petr Hosek
2015-11-30 21:14 ` Rich Felker
2015-11-30 22:14 ` Rich Felker
2015-12-01 2:14 ` Petr Hosek
2015-12-09 0:39 ` Rich Felker
2015-12-10 1:39 ` Petr Hosek
2015-12-10 12:47 ` Szabolcs Nagy
2016-01-17 22:32 ` Rich Felker
2016-01-17 23:41 ` Szabolcs Nagy
2016-01-20 3:49 ` Rich Felker
2015-11-21 1:05 ` Szabolcs Nagy
2015-11-21 1:16 ` Szabolcs Nagy
2015-11-22 14:56 ` Szabolcs Nagy
2015-11-30 1:30 ` Petr Hosek
2015-11-30 12:01 ` Szabolcs Nagy
2015-11-30 22:22 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABBv4TYv2z3+=dESvMiMnZr43UXGskr8SZjXw+R=8epD0FRToA@mail.gmail.com' \
--to=phosek@chromium.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).