From: Petr Hosek <phosek@chromium.org>
To: musl@lists.openwall.com
Subject: Re: Support for out-of-tree build
Date: Thu, 12 Nov 2015 00:28:44 +0000 [thread overview]
Message-ID: <CABBv4TZwJ067Q5toAsAhT2buJSCPOyNSmPuTV6SF4LBT7V6XRg@mail.gmail.com> (raw)
In-Reply-To: <20151111230848.GZ3818@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 9380 bytes --]
On Wed, Nov 11, 2015 at 3:09 PM Rich Felker <dalias@libc.org> wrote:
> On Wed, Nov 11, 2015 at 10:02:50PM +0000, Petr Hosek wrote:
> > Attached is an update version which doesn't use VPATH and supports both
> > in-tree and out-of-tree builds.
>
> Is there a reason you prefer not to use VPATH?
>
This was to allow combining in tree and out-of-tree builds as mentioned buy
Szabolcs. It's not something I really need, but if there are others who
need this functionality I'll do my best to support that scenario.
> > One way to improve this even further would be to completely avoid the
> > mkasmdep and instead include the architecture specific object files into
> > the list of objects directly (filtering out the generic versions). Would
> > that be a preferred way?
>
> My intent is to remove the *.sub system entirely. The current idea is
> to replace it with make fragments in the arch dirs that add the
> implicit rules for whatever subarch dirs should be searched.
>
> > From 1336bc5c1eddc43214559712f85702efba8aa864 Mon Sep 17 00:00:00 2001
> > From: Petr Hosek <phosek@chromium.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.
>
> Some quick comments here, and then more inline below:
>
> Assuming this all works, it looks to me like you've done a remarkable
> job of preserving existing behavior while making out-of-tree work.
> What I'd really like to do, though, is figure out what parts of the
> current build system are "unclean" for out-of-tree and improve them so
> that we can simplify the build system at the same time (or at least
> keep the complexity around the same level). For instance eliminating
> all generated files from directories that contain non-generated files
> would probably be good idea. I'm not asking you to do things like that
> right away, more for input on what changes would actually be good for
> achieving this so we can discuss them.
>
Right now the biggest headache for me is really the *.sub system. If that
gets replaced, it should be possible to avoid some the "hacks" I had to use
around the static rules.
> > ---
> > Makefile | 93
> +++++++++++++++++++++++++++++++++++++++++----------------------
> > configure | 24 ++++++++++++++---
> > 2 files changed, 82 insertions(+), 35 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 2b21015..a022411 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -8,6 +8,7 @@
> > # Do not make changes here.
> > #
> >
> > +srcdir = .
> > exec_prefix = /usr/local
> > bindir = $(exec_prefix)/bin
> >
> > @@ -16,12 +17,24 @@ 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
> > -IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h
> src/internal/libc.h
> > +IMPH = $(addprefix $(srcdir)/, src/internal/stdio_impl.h
> src/internal/pthread_impl.h src/internal/libc.h)
> > +
> > +SRCS_SUB = $(wildcard $(srcdir)/src/*/$(ARCH)$(ASMSUBARCH)/*.sub)
> > +OBJS_SUB = $(foreach s,$(SRCS_SUB),$(dir $(patsubst
> $(srcdir)/%/,%,$(dir $(s))))$(notdir $(s:.sub=.o)))
> > +LOBJS_SUB = $(OBJS_SUB:.o=.lo)
> > +
> > +SRCS_S = $(wildcard $(srcdir)/src/*/$(ARCH)*/*.s)
> > +OBJS_S = $(foreach s,$(SRCS_S),$(dir $(patsubst $(srcdir)/%/,%,$(dir
> $(s))))$(notdir $(s:.s=.o)))
> > +LOBJS_S = $(OBJS_S:.o=.lo)
> > +
> > +OBJS_C = $(filter-out $(OBJS_S) $(OBJS_SUB), $(OBJS))
> > +LOBJS_C = $(OBJS_C:.o=.lo)
> > +OBJS_C += crt/crt1.o crt/Scrt1.o crt/rcrt1.o crt/crti.o crt/crtn.o
> >
> > LDFLAGS =
> > LDFLAGS_AUTO =
> > @@ -32,7 +45,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) $(sort
> -I./src/internal -I$(srcdir)/src/internal) $(sort -I./include
> -I$(srcdir)/include)
>
> I'm confused about why you are applying $(sort...) to include paths.
> It seems like the resulting order may differ depending on $(srcdir).
> Maybe this doesn't matter, but I'd rather not rely on that.
>
sort here is not for sorting but for removing duplicates; in case you're
doing an in tree build, $(srcdir) will be . in which case each include path
will be listed twice, sort removes those duplicates.
> > +SRC_DIRS = $(sort $(dir $(OBJS) $(ALL_LIBS) $(ALL_TOOLS))
> arch/$(ARCH)/bits/ crt/ include/ src/internal/)
> > +
> > WRAPCC_GCC = gcc
> > WRAPCC_CLANG = clang
> >
> > @@ -64,6 +80,17 @@ LDSO_PATHNAME =
> $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
> >
> > all: $(ALL_LIBS) $(ALL_TOOLS)
> >
> > +$(ALL_LIBS): | lib/
> > +$(ALL_TOOLS): | tools/
> > +$(CRT_LIBS:lib/%=crt/%): | crt/
> > +$(OBJS) $(LOBJS): | $(sort $(dir $(OBJS)))
> > +$(GENH): | arch/$(ARCH)/bits/
> > +$(GENH_INT): | src/internal/
> > +include/bits: | include
> > +
> > +$(SRC_DIRS):
> > + mkdir -p $@
>
> This all looks nice.
>
> > @@ -82,26 +109,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: 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 > $@
> > +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 > $@
> >
> > -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/rcrt1.o src/ldso/dlstart.lo 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)
> > +crt/crt1.o crt/scrt1.o crt/rcrt1.o src/ldso/dlstart.lo: $(wildcard
> $(srcdir)/arch/$(ARCH)/crt_arch.h)
>
> Just a note: this $(wildcard...) is obsolete. crt_arch.h is now mandatory.
>
I'll fix that.
> > 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,34 +144,35 @@ $(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)
> > +$(dir $(patsubst $(srcdir)/%/,%,$(dir $(1))))$(notdir $(1:.s=.lo)): $(1)
> > endef
> > -$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call
> mkasmdep,$(s))))
> > +$(foreach s,$(wildcard $(srcdir)/src/*/$(ARCH)*/*.s),$(eval $(call
> mkasmdep,$(s))))
>
> Was this missing the dep rules for .lo files?
>
I'm not sure how this worked before, I was getting build errors without the
explicit dep rule for .lo files.
> > -%.o: $(ARCH)$(ASMSUBARCH)/%.sub
> > +$(OBJS_SUB): %.o:
> > $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
> >
> > -%.o: $(ARCH)/%.s
> > +$(OBJS_S): %.o:
> > $(AS_CMD) $(CFLAGS_ALL_STATIC)
> >
> > -%.o: %.c $(GENH) $(IMPH)
> > +$(OBJS_C): %.o: $(srcdir)/%.c $(GENH) $(IMPH)
> > $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
> >
> > -%.lo: $(ARCH)$(ASMSUBARCH)/%.sub
> > +$(LOBJS_SUB): %.lo:
> > $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
> >
> > -%.lo: $(ARCH)/%.s
> > +$(LOBJS_S): %.lo:
> > $(AS_CMD) $(CFLAGS_ALL_SHARED)
> >
> > -%.lo: %.c $(GENH) $(IMPH)
> > +$(LOBJS_C): %.lo: $(srcdir)/%.c $(GENH) $(IMPH)
> > $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
>
> I don't understand these rules with two :'s. I assume it's some trick
> I don't yet know. But in the case of the %.s ones, the new rules have
> no %.s in them... this looks wrong, no?
>
This is bit of hack which uses the static rules. I think we might be able
to get rid of those if we remove the *.sub system as mentioned earlier, but
this is the only way I got it to work without having a per file rule in the
current setup.
[-- Attachment #2: Type: text/html, Size: 12246 bytes --]
next prev parent reply other threads:[~2015-11-12 0:28 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 [this message]
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
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=CABBv4TZwJ067Q5toAsAhT2buJSCPOyNSmPuTV6SF4LBT7V6XRg@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).