From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4555 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Out-of-tree builds Date: Sat, 8 Feb 2014 03:49:22 +0100 Message-ID: <20140208024922.GG1685@port70.net> References: <52F3C329.6040208@f-prot.com> <20140206173932.GB1685@port70.net> <20140206190410.GJ15627@brightrain.aerifal.cx> <20140206232706.GC1685@port70.net> <20140206233121.GD1685@port70.net> <20140207010135.GE1685@port70.net> <20140207010755.GL15627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="i3lJ51RuaGWuFYNw" X-Trace: ger.gmane.org 1391827768 2093 80.91.229.3 (8 Feb 2014 02:49:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 8 Feb 2014 02:49:28 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4559-gllmg-musl=m.gmane.org@lists.openwall.com Sat Feb 08 03:49:38 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WBxz6-0008RE-3i for gllmg-musl@plane.gmane.org; Sat, 08 Feb 2014 03:49:36 +0100 Original-Received: (qmail 5445 invoked by uid 550); 8 Feb 2014 02:49:34 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5434 invoked from network); 8 Feb 2014 02:49:34 -0000 Content-Disposition: inline In-Reply-To: <20140207010755.GL15627@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4555 Archived-At: --i3lJ51RuaGWuFYNw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Rich Felker [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 --i3lJ51RuaGWuFYNw Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="make.diff" 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/% --i3lJ51RuaGWuFYNw--