mailing list of musl libc
 help / color / mirror / code / Atom feed
* Out-of-tree builds
@ 2014-02-06 17:15 Oliver Schneider
  2014-02-06 17:39 ` Szabolcs Nagy
  0 siblings, 1 reply; 11+ messages in thread
From: Oliver Schneider @ 2014-02-06 17:15 UTC (permalink / raw)
  To: musl

Hi,

currently I am trying to perform an out-of-tree build on musl and I am
hitting a problem.

When I run this (in-tree) it works fine:

./configure --disable-shared

however, then I switch to an empty directory and run this:

../musl/configure --disable-shared

I get:

using compiler runtime libraries: -lgcc -lgcc_eh
checking whether compiler's long double definition matches float.h... no
../musl/configure: error: unsupported long double type

Are out-of-tree builds generally not supported, or am I doing something
wrong?

I am using the Git repository and it's checked out at:

b589fb4 release 0.9.15

Thanks and best regards,

// Oliver


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-06 17:15 Out-of-tree builds Oliver Schneider
@ 2014-02-06 17:39 ` Szabolcs Nagy
  2014-02-06 18:25   ` Oliver Schneider
  2014-02-06 19:04   ` Rich Felker
  0 siblings, 2 replies; 11+ messages in thread
From: Szabolcs Nagy @ 2014-02-06 17:39 UTC (permalink / raw)
  To: musl

* Oliver Schneider <musl-mailinglist@f-prot.com> [2014-02-06 17:15:21 +0000]:
> however, then I switch to an empty directory and run this:
> 
> ../musl/configure --disable-shared
> 
> I get:
> 
> using compiler runtime libraries: -lgcc -lgcc_eh
> checking whether compiler's long double definition matches float.h... no
> ../musl/configure: error: unsupported long double type
> 
> Are out-of-tree builds generally not supported, or am I doing something
> wrong?

not supported (yet)

it probably wouldn't be hard to add though

(eg the paths in the makefile can be prefixed with the build path
and the generated config.mak can set that prefix up, but i'm not
sure what's the best way to detect the path and there might be
issues around the generated alltypes.h and include/bits)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-06 17:39 ` Szabolcs Nagy
@ 2014-02-06 18:25   ` Oliver Schneider
  2014-02-06 19:04   ` Rich Felker
  1 sibling, 0 replies; 11+ messages in thread
From: Oliver Schneider @ 2014-02-06 18:25 UTC (permalink / raw)
  To: musl

On 2014-02-06 17:39, Szabolcs Nagy wrote:
> not supported (yet)
> 
> it probably wouldn't be hard to add though
Thanks for your quick response.

I'll see whether I'm allowed to spend time on this and contribute a
patch back. I certainly hope so.

Thanks for musl-libc!

// Oliver


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-06 17:39 ` Szabolcs Nagy
  2014-02-06 18:25   ` Oliver Schneider
@ 2014-02-06 19:04   ` Rich Felker
  2014-02-06 23:27     ` Szabolcs Nagy
  1 sibling, 1 reply; 11+ messages in thread
From: Rich Felker @ 2014-02-06 19:04 UTC (permalink / raw)
  To: musl

On Thu, Feb 06, 2014 at 06:39:32PM +0100, Szabolcs Nagy wrote:
> * Oliver Schneider <musl-mailinglist@f-prot.com> [2014-02-06 17:15:21 +0000]:
> > however, then I switch to an empty directory and run this:
> > 
> > ../musl/configure --disable-shared
> > 
> > I get:
> > 
> > using compiler runtime libraries: -lgcc -lgcc_eh
> > checking whether compiler's long double definition matches float.h... no
> > ../musl/configure: error: unsupported long double type
> > 
> > Are out-of-tree builds generally not supported, or am I doing something
> > wrong?
> 
> not supported (yet)
> 
> it probably wouldn't be hard to add though
> 
> (eg the paths in the makefile can be prefixed with the build path
> and the generated config.mak can set that prefix up, but i'm not
> sure what's the best way to detect the path and there might be
> issues around the generated alltypes.h and include/bits)

It's not as easy as it sounds because of the way implicit % rules
work. I don't know how to get them to work when adding a leading path.
If someone can figure out how to do this without doing anything
horribly ugly/bloated/slow in the makefile, I'm open to adding support
for out-of-tree builds this way.

Rich


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-06 19:04   ` Rich Felker
@ 2014-02-06 23:27     ` Szabolcs Nagy
  2014-02-06 23:31       ` Szabolcs Nagy
  0 siblings, 1 reply; 11+ messages in thread
From: Szabolcs Nagy @ 2014-02-06 23:27 UTC (permalink / raw)
  To: musl

* Rich Felker <dalias@aerifal.cx> [2014-02-06 14:04:10 -0500]:
> It's not as easy as it sounds because of the way implicit % rules
> work. I don't know how to get them to work when adding a leading path.

ok i see the problem, this dependency cannot be expressed
for all foo and bar easily:

  src/foo/bar.o: $(SOMEDIR)/src/foo/$(ARCH)/bar.s

without $(SOMEDIR)

  %.o: $(ARCH)/%.s

works


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-06 23:27     ` Szabolcs Nagy
@ 2014-02-06 23:31       ` Szabolcs Nagy
  2014-02-07  1:01         ` Szabolcs Nagy
  0 siblings, 1 reply; 11+ messages in thread
From: Szabolcs Nagy @ 2014-02-06 23:31 UTC (permalink / raw)
  To: musl

* Szabolcs Nagy <nsz@port70.net> [2014-02-07 00:27:06 +0100]:
> ok i see the problem, this dependency cannot be expressed
> for all foo and bar easily:
> 
>   src/foo/bar.o: $(SOMEDIR)/src/foo/$(ARCH)/bar.s
> 
> without $(SOMEDIR)
> 
>   %.o: $(ARCH)/%.s
> 
> works

VPATH=$(SOMEDIR)
%.o: $(ARCH)/%.s

seems to work but i have no clue why :)
(i don't think this follows from the make manual)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-06 23:31       ` Szabolcs Nagy
@ 2014-02-07  1:01         ` Szabolcs Nagy
  2014-02-07  1:07           ` Rich Felker
  0 siblings, 1 reply; 11+ messages in thread
From: Szabolcs Nagy @ 2014-02-07  1:01 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

* Szabolcs Nagy <nsz@port70.net> [2014-02-07 00:31:22 +0100]:
> 
> VPATH=$(SOMEDIR)
> %.o: $(ARCH)/%.s
> 

attached a make diff that can do out-of-tree build, by specifying
M=relative/path/to/musl

- config is not ready
- directory creation is a hack
- include/bits/alltypes.h is generated into the original repo
(include/bits is a symlink to the arch/bits dir)


[-- Attachment #2: make.diff --]
[-- Type: text/x-diff, Size: 4024 bytes --]

diff --git a/Makefile b/Makefile
index 0ab0bfd..fb9a83e 100644
--- a/Makefile
+++ b/Makefile
@@ -16,8 +16,9 @@ includedir = $(prefix)/include
 libdir = $(prefix)/lib
 syslibdir = /lib
 
-SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
-OBJS = $(SRCS:.c=.o)
+M = .
+SRCS = $(sort $(wildcard $(M)/src/*/*.c $(M)/arch/$(ARCH)/src/*.c))
+OBJS = $(SRCS:$(M)/%.c=%.o)
 LOBJS = $(OBJS:.o=.lo)
 GENH = include/bits/alltypes.h
 GENH_INT = src/internal/version.h
@@ -30,17 +31,17 @@ CFLAGS = -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$(M)/arch/$(ARCH) -I./src/internal -I$(M)/src/internal -I./include -I$(M)/include
 CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
 CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
 CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
 
 AR      = $(CROSS_COMPILE)ar
 RANLIB  = $(CROSS_COMPILE)ranlib
-INSTALL = ./tools/install.sh
+INSTALL = $(M)/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 $(M)/arch/$(ARCH)/bits/*.h)
+ALL_INCLUDES = $(sort $(wildcard $(M)/include/*.h $(M)/include/*/*.h) $(GENH) $(ARCH_INCLUDES:$(M)/arch/$(ARCH)/%=include/%))
 
 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
@@ -55,7 +56,12 @@ LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
 
 -include config.mak
 
-all: $(ALL_LIBS) $(ALL_TOOLS)
+VPATH = $(M)
+
+all: dirhack $(ALL_LIBS) $(ALL_TOOLS)
+
+dirhack:
+	mkdir -p $(sort $(dir $(OBJS))) crt include lib tools
 
 install: install-libs install-headers install-tools
 
@@ -73,26 +79,26 @@ distclean: clean
 
 include/bits:
 	@test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
-	ln -sf ../arch/$(ARCH)/bits $@
+	ln -sf ../$(M)/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: include/bits/alltypes.h.in $(M)/include/alltypes.h.in $(M)/tools/mkalltypes.sed
+	sed -f $(M)/tools/mkalltypes.sed include/bits/alltypes.h.in $(M)/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 $(M)/VERSION $(M)/.git)
+	printf '#define VERSION "%s"\n' "$$(cd $(M); sh tools/version.sh)" > $@
 
 src/internal/version.lo: src/internal/version.h
 
 src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
 
-crt/crt1.o crt/Scrt1.o: $(wildcard arch/$(ARCH)/crt_arch.h)
+crt/crt1.o crt/Scrt1.o: $(wildcard $(M)/arch/$(ARCH)/crt_arch.h)
 
 crt/Scrt1.o: CFLAGS += -fPIC
 
-OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%))
-$(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3
+OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(M)/src/%))
+$(OPTIMIZE_SRCS:$(M)/%.c=%.o) $(OPTIMIZE_SRCS:$(M)/%.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 += $(CFLAGS_MEMOPS)
@@ -101,9 +107,9 @@ $(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_MEMOPS)
 # 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 $(M)/%/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1)
 endef
-$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
+$(foreach s,$(wildcard $(M)/src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
 
 %.o: $(ARCH)$(ASMSUBARCH)/%.sub
 	$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-07  1:01         ` Szabolcs Nagy
@ 2014-02-07  1:07           ` Rich Felker
  2014-02-08  2:49             ` Szabolcs Nagy
  0 siblings, 1 reply; 11+ messages in thread
From: Rich Felker @ 2014-02-07  1:07 UTC (permalink / raw)
  To: musl

On Fri, Feb 07, 2014 at 02:01:36AM +0100, Szabolcs Nagy wrote:
> +dirhack:
> +	mkdir -p $(sort $(dir $(OBJS))) crt include lib tools

How does this avoid having the $(M) source root from $(OBJS)?

>  include/bits:
>  	@test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
> -	ln -sf ../arch/$(ARCH)/bits $@
> +	ln -sf ../$(M)/arch/$(ARCH)/bits $@

Having ../ prior to a possibly-absolute path $(M) seems wrong.

Rich


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-07  1:07           ` Rich Felker
@ 2014-02-08  2:49             ` Szabolcs Nagy
  2014-02-26 22:56               ` Szabolcs Nagy
  0 siblings, 1 reply; 11+ messages in thread
From: Szabolcs Nagy @ 2014-02-08  2:49 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 819 bytes --]

* Rich Felker <dalias@aerifal.cx> [2014-02-06 20:07:55 -0500]:
> On Fri, Feb 07, 2014 at 02:01:36AM +0100, Szabolcs Nagy wrote:
> > +dirhack:
> > +	mkdir -p $(sort $(dir $(OBJS))) crt include lib tools
> 
> How does this avoid having the $(M) source root from $(OBJS)?

objs have no $(M) prefix

> >  include/bits:
> >  	@test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
> > -	ln -sf ../arch/$(ARCH)/bits $@
> > +	ln -sf ../$(M)/arch/$(ARCH)/bits $@
> 
> Having ../ prior to a possibly-absolute path $(M) seems wrong.

this was problematic for other reasons too so i create
the arch/... dir and symlink locally

attached second try (fixes install, dirs, symlink)

for in-tree builds it creates spurious '.mark' files
otherwise the same make should work in-tree and out-of-tree

[-- Attachment #2: make.diff --]
[-- Type: text/x-diff, Size: 4778 bytes --]

diff --git a/Makefile b/Makefile
index 0ab0bfd..db0a040 100644
--- a/Makefile
+++ b/Makefile
@@ -16,8 +16,9 @@ includedir = $(prefix)/include
 libdir = $(prefix)/lib
 syslibdir = /lib
 
-SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
-OBJS = $(SRCS:.c=.o)
+M = .
+SRCS = $(sort $(wildcard $(M)/src/*/*.c $(M)/arch/$(ARCH)/src/*.c))
+OBJS = $(SRCS:$(M)/%.c=%.o)
 LOBJS = $(OBJS:.o=.lo)
 GENH = include/bits/alltypes.h
 GENH_INT = src/internal/version.h
@@ -30,17 +31,18 @@ CFLAGS = -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$(M)/arch/$(ARCH) -I./src/internal -I$(M)/src/internal -I./include -I$(M)/include
 CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
 CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
 CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
 
 AR      = $(CROSS_COMPILE)ar
 RANLIB  = $(CROSS_COMPILE)ranlib
-INSTALL = ./tools/install.sh
+INSTALL = $(M)/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 $(M)/arch/$(ARCH)/bits/*.h)
+INCLUDES = $(wildcard $(M)/include/*.h $(M)/include/*/*.h)
+ALL_INCLUDES = $(sort $(INCLUDES:$(M)/%=%) $(GENH) $(ARCH_INCLUDES:$(M)/arch/$(ARCH)/%=include/%))
 
 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
@@ -57,6 +59,18 @@ LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
 
 all: $(ALL_LIBS) $(ALL_TOOLS)
 
+vpath %.s $(M)
+vpath %.c $(M)
+vpath %.h $(M)
+
+$(ALL_TOOLS): tools/.mark
+$(ALL_LIBS): lib/.mark
+$(CRT_LIBS:lib/%=crt/%): crt/.mark
+$(OBJS) $(LOBJS): $(patsubst %/,%/.mark,$(sort $(dir $(OBJS))))
+%/.mark:
+	mkdir -p $*
+	touch $@
+
 install: install-libs install-headers install-tools
 
 clean:
@@ -71,28 +85,27 @@ clean:
 distclean: clean
 	rm -f config.mak
 
-include/bits:
+include/bits: include/.mark arch/$(ARCH)/bits/.mark
 	@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 > $@
+INS = $(M)/arch/$(ARCH)/bits/alltypes.h.in $(M)/include/alltypes.h.in
+include/bits/alltypes.h: $(M)/tools/mkalltypes.sed $(INS) include/bits
+	sed -f $(M)/tools/mkalltypes.sed $(INS) > $@
 
-src/internal/version.h: $(wildcard VERSION .git)
-	printf '#define VERSION "%s"\n' "$$(sh tools/version.sh)" > $@
+src/internal/version.h: $(wildcard $(M)/VERSION $(M)/.git) src/internal/.mark
+	printf '#define VERSION "%s"\n' "$$(cd $(M); sh tools/version.sh)" > $@
 
 src/internal/version.lo: src/internal/version.h
 
 src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
 
-crt/crt1.o crt/Scrt1.o: $(wildcard arch/$(ARCH)/crt_arch.h)
+crt/crt1.o crt/Scrt1.o: $(wildcard $(M)/arch/$(ARCH)/crt_arch.h)
 
 crt/Scrt1.o: CFLAGS += -fPIC
 
-OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%))
-$(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3
+OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(M)/src/%))
+$(OPTIMIZE_SRCS:$(M)/%.c=%.o) $(OPTIMIZE_SRCS:$(M)/%.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 += $(CFLAGS_MEMOPS)
@@ -101,9 +114,9 @@ $(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_MEMOPS)
 # 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 $(M)/%/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1)
 endef
-$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
+$(foreach s,$(wildcard $(M)/src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
 
 %.o: $(ARCH)$(ASMSUBARCH)/%.sub
 	$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
@@ -140,7 +153,7 @@ $(EMPTY_LIBS):
 lib/%.o: crt/%.o
 	cp $< $@
 
-lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
+lib/musl-gcc.specs: $(M)/tools/musl-gcc.specs.sh config.mak
 	sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
 
 tools/musl-gcc: config.mak
@@ -156,7 +169,7 @@ $(DESTDIR)$(libdir)/%.so: lib/%.so
 $(DESTDIR)$(libdir)/%: lib/%
 	$(INSTALL) -D -m 644 $< $@
 
-$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
+$(DESTDIR)$(includedir)/bits/%: $(M)/arch/$(ARCH)/bits/%
 	$(INSTALL) -D -m 644 $< $@
 
 $(DESTDIR)$(includedir)/%: include/%

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-08  2:49             ` Szabolcs Nagy
@ 2014-02-26 22:56               ` Szabolcs Nagy
  2014-02-27 13:29                 ` Szabolcs Nagy
  0 siblings, 1 reply; 11+ messages in thread
From: Szabolcs Nagy @ 2014-02-26 22:56 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 442 bytes --]

* Szabolcs Nagy <nsz@port70.net> [2014-02-08 03:49:22 +0100]:
> attached second try (fixes install, dirs, symlink)
> 
> for in-tree builds it creates spurious '.mark' files
> otherwise the same make should work in-tree and out-of-tree

third try, with configure changes and some simplifications

(configure detects out-of-tree build and copies the Makefile,
there is an ifndef block in the Makefile to add extra rules
for directory creation)

[-- Attachment #2: out-of-tree.diff --]
[-- Type: text/x-diff, Size: 6990 bytes --]

diff --git a/Makefile b/Makefile
index 0ab0bfd..43dea0d 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
@@ -30,17 +31,19 @@ CFLAGS = -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)
+CFLAGS_ALL += $(sort -I./src/internal -I$(srcdir)/src/internal) $(sort -I./include -I$(srcdir)/include)
 CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
 CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
 CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
 
 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)
@@ -57,6 +60,19 @@ LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
 
 all: $(ALL_LIBS) $(ALL_TOOLS)
 
+ifneq ($(srcdir),.)
+VPATH = $(srcdir)
+$(ALL_TOOLS): tools/.dir
+$(ALL_LIBS): lib/.dir
+$(CRT_LIBS:lib/%=crt/%): crt/.dir
+$(OBJS) $(LOBJS): $(patsubst %/,%/.dir,$(sort $(dir $(OBJS))))
+include/bits: include/.dir arch/$(ARCH)/bits/.dir
+src/internal/version.h: src/internal/.dir
+%/.dir:
+	mkdir -p $*
+	touch $@
+endif
+
 install: install-libs install-headers install-tools
 
 clean:
@@ -75,24 +91,23 @@ 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 > $@
+INS = $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in
+include/bits/alltypes.h: $(srcdir)/tools/mkalltypes.sed $(INS) include/bits
+	sed -f $(srcdir)/tools/mkalltypes.sed $(INS) > $@
 
-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
 
 src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
 
-crt/crt1.o crt/Scrt1.o: $(wildcard arch/$(ARCH)/crt_arch.h)
+crt/crt1.o crt/Scrt1.o: $(wildcard $(srcdir)/arch/$(ARCH)/crt_arch.h)
 
 crt/Scrt1.o: CFLAGS += -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 += $(CFLAGS_MEMOPS)
@@ -101,9 +116,9 @@ $(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_MEMOPS)
 # 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))))
 
 %.o: $(ARCH)$(ASMSUBARCH)/%.sub
 	$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
diff --git a/configure b/configure
index c622366..9ed785a 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]
@@ -113,6 +116,7 @@ CFLAGS_AUTO=
 CFLAGS_MEMOPS=
 LDFLAGS_AUTO=
 OPTIMIZE_GLOBS=
+srcdir=
 prefix=/usr/local/musl
 exec_prefix='$(prefix)'
 bindir='$(exec_prefix)/bin'
@@ -129,6 +133,7 @@ static=yes
 for arg ; do
 case "$arg" in
 --help) usage ;;
+--srcdir=*) srcdir=${arg#*=} ;;
 --prefix=*) prefix=${arg#*=} ;;
 --exec-prefix=*) exec_prefix=${arg#*=} ;;
 --bindir=*) bindir=${arg#*=} ;;
@@ -162,11 +167,28 @@ 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 current directory"
+abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir"
+test "$abs_srcdir" = "$abs_builddir" && srcdir=.
+printf "source directory: %s\n" "$srcdir"
+if test -f Makefile ; then
+echo "using existing Makefile"
+else
+cp $srcdir/Makefile . || fail "$0: cannot create Makefile"
+fi
+
+#
 # Get a temp filename we can use
 #
 i=0
@@ -258,7 +280,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
@@ -445,7 +467,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
@@ -468,6 +490,7 @@ cat << EOF
 ARCH = $ARCH
 SUBARCH = $SUBARCH
 ASMSUBARCH = $ASMSUBARCH
+srcdir = $srcdir
 prefix = $prefix
 exec_prefix = $exec_prefix
 bindir = $bindir

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Out-of-tree builds
  2014-02-26 22:56               ` Szabolcs Nagy
@ 2014-02-27 13:29                 ` Szabolcs Nagy
  0 siblings, 0 replies; 11+ messages in thread
From: Szabolcs Nagy @ 2014-02-27 13:29 UTC (permalink / raw)
  To: musl

* Szabolcs Nagy <nsz@port70.net> [2014-02-26 23:56:14 +0100]:
> third try, with configure changes and some simplifications
> 
> (configure detects out-of-tree build and copies the Makefile,
> there is an ifndef block in the Makefile to add extra rules
> for directory creation)

hm the makefile shouldn't be copied, it's enough to link it
or create one with "include $srcdir/Makefile"
(so if the source repo is updated the new makefile will be
used for the out-of-tree build)

> +if test -f Makefile ; then
> +echo "using existing Makefile"
> +else
> +cp $srcdir/Makefile . || fail "$0: cannot create Makefile"
> +fi
> +

else
printf "creating Makefile... "
echo "include $srcdir/Makefile" >Makefile
echo "done"
fi


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-02-27 13:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-06 17:15 Out-of-tree builds Oliver Schneider
2014-02-06 17:39 ` Szabolcs Nagy
2014-02-06 18:25   ` Oliver Schneider
2014-02-06 19:04   ` Rich Felker
2014-02-06 23:27     ` Szabolcs Nagy
2014-02-06 23:31       ` Szabolcs Nagy
2014-02-07  1:01         ` Szabolcs Nagy
2014-02-07  1:07           ` Rich Felker
2014-02-08  2:49             ` Szabolcs Nagy
2014-02-26 22:56               ` Szabolcs Nagy
2014-02-27 13:29                 ` Szabolcs Nagy

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).