Skip to content

Commit

Permalink
support building out-of-tree
Browse files Browse the repository at this point in the history
  Handle O=

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
  • Loading branch information
aldot committed Aug 17, 2009
1 parent 7f779e7 commit 49d8a0e
Show file tree
Hide file tree
Showing 72 changed files with 683 additions and 433 deletions.
11 changes: 7 additions & 4 deletions Makefile
Expand Up @@ -6,9 +6,12 @@
#

top_srcdir=./
top_builddir=./
#include $(top_builddir)Rules.mak
#all: libs
include Makefile.in
top_builddir=$(if $(O),$(O),.)/
export top_builddir

# We do not need built-in implicit rules
MAKEFLAGS += -r

include $(top_srcdir)Makefile.in
include $(top_srcdir)Makerules
include $(top_srcdir)Makefile.help
1 change: 1 addition & 0 deletions Makefile.help
Expand Up @@ -42,6 +42,7 @@ help:
@echo ' release - create a distribution tarball'
@echo
@echo 'Environment variables:'
@echo ' O=<abspath> - Use <abspath> as object directory'
@echo ' V="" - Quiet build (default)'
@echo ' V=1 - Verbose build'
@echo ' V=2 - Very verbose build'
Expand Down
142 changes: 74 additions & 68 deletions Makefile.in
Expand Up @@ -14,16 +14,21 @@ noconfig_targets := menuconfig config oldconfig silentoldconfig randconfig \
defconfig allyesconfig allnoconfig \
release dist tags help

include $(top_builddir)Rules.mak
include $(top_srcdir)Rules.mak
sub_headers := headers

ifndef KCONFIG_CONFIG
KCONFIG_CONFIG := $(top_builddir).config
endif
export KCONFIG_CONFIG

ifeq ($(HAVE_DOT_CONFIG),y)

all: pregen libs
libs: pregen

# In this section, we need .config
-include .config.cmd
-include $(top_builddir).config.cmd

else # ifeq ($(HAVE_DOT_CONFIG),y)

Expand Down Expand Up @@ -55,16 +60,17 @@ ifeq ($(HAVE_DOT_CONFIG),y)
# have uClibc_config.h as prerequisite but since we _symlink_ the headers
# and do not (?) want to rely on 'make -L' we better update them right here,
# on spot to save us from alot of hazzle.
include/bits/uClibc_config.h: extra/config/conf .config $(top_srcdir)extra/scripts/conf-header.sh | include/bits
$(top_builddir)include/bits/uClibc_config.h: $(top_builddir)extra/config/conf $(KCONFIG_CONFIG) $(top_srcdir)extra/scripts/conf-header.sh | $(top_builddir)include/bits $(top_builddir)include/config
@$(disp_gen)
$(Q)@$< -s $(top_srcdir)extra/Configs/Config.in
$(Q)$(top_srcdir)extra/scripts/conf-header.sh .config > $@
$(Q)$(top_srcdir)extra/scripts/conf-header.sh $(KCONFIG_CONFIG) > $@
$(Q)$(MAKE) headers-y

# The above doesn't work for threads, though. Just using check-symlinks for now.
# XXX: FIXME: this is ugly
MAKEFLAGS += -L
include/config/linuxthreads/old.h include/config/linuxthreads/new.h:

$(top_builddir)include/config/linuxthreads/old.h $(top_builddir)include/config/linuxthreads/new.h:
@true

# For the moment, we have to keep re-running this target
Expand All @@ -89,17 +95,18 @@ HEADERS_SYS_COMMON := $(notdir $(wildcard $(top_srcdir)libc/sysdeps/linux/common
HEADERS_SYS_ARCH := $(notdir $(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/sys/*.h))
HEADERS_SYS_COMMON := $(filter-out $(HEADERS_SYS_ARCH),$(HEADERS_SYS_COMMON))

ALL_HEADERS_COMMON := include/fpu_control.h include/dl-osinfo.h \
include/hp-timing.h
ALL_HEADERS_BITS_COMMON := $(addprefix include/bits/,$(HEADERS_BITS_COMMON))
ALL_HEADERS_BITS_ARCH := $(addprefix include/bits/,$(HEADERS_BITS_ARCH))
ALL_HEADERS_COMMON := $(top_builddir)include/fpu_control.h \
$(top_builddir)include/dl-osinfo.h \
$(top_builddir)include/hp-timing.h
ALL_HEADERS_BITS_COMMON := $(addprefix $(top_builddir)include/bits/,$(HEADERS_BITS_COMMON))
ALL_HEADERS_BITS_ARCH := $(addprefix $(top_builddir)include/bits/,$(HEADERS_BITS_ARCH))
ifneq ($(TARGET_SUBARCH),)
ALL_HEADERS_BITS_SUBARCH := $(addprefix include/bits/,$(HEADERS_BITS_SUBARCH))
ALL_HEADERS_BITS_SUBARCH := $(addprefix $(top_builddir)include/bits/,$(HEADERS_BITS_SUBARCH))
else
ALL_HEADERS_BITS_SUBARCH :=
endif
ALL_HEADERS_SYS_COMMON := $(addprefix include/sys/,$(HEADERS_SYS_COMMON))
ALL_HEADERS_SYS_ARCH := $(addprefix include/sys/,$(HEADERS_SYS_ARCH))
ALL_HEADERS_SYS_COMMON := $(addprefix $(top_builddir)include/sys/,$(HEADERS_SYS_COMMON))
ALL_HEADERS_SYS_ARCH := $(addprefix $(top_builddir)include/sys/,$(HEADERS_SYS_ARCH))

target-headers-sysdep := \
$(ALL_HEADERS_COMMON) \
Expand All @@ -109,37 +116,37 @@ target-headers-sysdep := \
$(ALL_HEADERS_SYS_COMMON) \
$(ALL_HEADERS_SYS_ARCH)

include/fpu_control.h:
$(top_builddir)include/fpu_control.h:
@$(disp_ln)
$(Q)[ -r libc/sysdeps/linux/$(TARGET_ARCH)/$(@F) ] && \
$(LN) -fs ../libc/sysdeps/linux/$(TARGET_ARCH)/$(@F) $@ || \
$(LN) -fs ../libc/sysdeps/linux/common/$(@F) $@
$(Q)[ -r $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(@F) ] && \
$(LN) -fs $(call rel_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(@F) $@ || \
$(LN) -fs $(call rel_srcdir)libc/sysdeps/linux/common/$(@F) $@

include/dl-osinfo.h include/hp-timing.h:
$(do_ln) ../libc/sysdeps/linux/common/$(@F) $@
$(top_builddir)include/dl-osinfo.h $(top_builddir)include/hp-timing.h:
$(do_ln) $(call rel_srcdir)libc/sysdeps/linux/common/$(@F) $@

$(ALL_HEADERS_BITS_COMMON):
$(do_ln) ../../libc/sysdeps/linux/common/bits/$(@F) $@
$(do_ln) $(call rel_srcdir)libc/sysdeps/linux/common/bits/$(@F) $@

$(ALL_HEADERS_BITS_ARCH):
$(do_ln) ../../libc/sysdeps/linux/$(TARGET_ARCH)/bits/$(@F) $@
$(do_ln) $(call rel_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/bits/$(@F) $@

ifneq ($(TARGET_SUBARCH),)
$(ALL_HEADERS_BITS_SUBARCH):
$(do_ln) ../../../libc/sysdeps/linux/$(TARGET_ARCH)/bits/$(TARGET_SUBARCH)/$(@F) $@
$(do_ln) $(call rel_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/bits/$(TARGET_SUBARCH)/$(@F) $@
endif

ifneq ($(strip $(ALL_HEADERS_SYS_COMMON)),)
$(ALL_HEADERS_SYS_COMMON):
$(do_ln) ../../libc/sysdeps/linux/common/sys/$(@F) $@
$(do_ln) $(call rel_srcdir)libc/sysdeps/linux/common/sys/$(@F) $@
endif

ifneq ($(strip $(ALL_HEADERS_SYS_ARCH)),)
$(ALL_HEADERS_SYS_ARCH):
$(do_ln) ../../libc/sysdeps/linux/$(TARGET_ARCH)/sys/$(@F) $@
$(do_ln) $(call rel_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/sys/$(@F) $@
endif

$(target-headers-sysdep): | include/bits
$(target-headers-sysdep): | $(top_builddir)include/bits $(top_builddir)include/sys

sysdep_common_headers-clean:
$(RM) $(ALL_HEADERS_COMMON)
Expand All @@ -150,22 +157,21 @@ headers_clean-y += sysdep_common_headers-clean
# libc/sysdeps/linux/Makefile.commonarch to headers-y
headers-y += $(target-headers-sysdep)

headers: include/bits/uClibc_config.h

pregen: include/bits/sysnum.h headers
headers: $(top_builddir)include/bits/uClibc_config.h
subdirs: $(addprefix $(top_builddir),$(subdirs))
pregen: $(top_builddir)include/bits/sysnum.h headers subdirs

include/bits/sysnum.h: $(top_srcdir)extra/scripts/gen_bits_syscall_h.sh
$(top_builddir)include/bits/sysnum.h: $(top_srcdir)extra/scripts/gen_bits_syscall_h.sh
$(Q)$(INSTALL) -d $(@D)
@$(disp_gen)
$(Q)set -e; \
cd $(top_builddir); \
tmp=`mktemp include/bits/sysnum.h.XXXXXX 2>/dev/null || true`; \
[ -z "$$tmp" ] && tmp='include/bits/sysnum.h.new'; \
KERNEL_HEADERS="${KERNEL_HEADERS}" top_builddir=. CC="$(CC) $(CPU_CFLAGS)" $(SHELL) extra/scripts/gen_bits_syscall_h.sh > $$tmp; \
if cmp include/bits/sysnum.h $$tmp >/dev/null 2>&1; then \
tmp=`mktemp $(top_builddir)include/bits/sysnum.h.XXXXXX 2>/dev/null || true`; \
[ -z "$$tmp" ] && tmp='$(top_builddir)include/bits/sysnum.h.new'; \
KERNEL_HEADERS="${KERNEL_HEADERS}" top_builddir="$(top_builddir)" CC="$(CC) $(CPU_CFLAGS)" $(SHELL) $< > $$tmp; \
if cmp $(top_builddir)include/bits/sysnum.h $$tmp >/dev/null 2>&1; then \
$(RM) $$tmp; \
else \
mv -f $$tmp include/bits/sysnum.h; \
mv -f $$tmp $(top_builddir)include/bits/sysnum.h; \
fi
@# Ugly linux specific hack..
$(Q)if grep -q __NR_ $@; then true; else \
Expand Down Expand Up @@ -380,70 +386,70 @@ hostutils:
install_hostutils: hostutils
$(MAKE) CROSS="$(CROSS)" CC="$(CC)" -C utils utils_install DOTHOST=.host

include/bits include/config:
@$(disp_mkdir)
$(Q)$(INSTALL) -d $@
$(addprefix $(top_builddir),include/bits include/sys include/config extra/config/lxdialog extra/locale $(subdirs)):
$(do_mkdir)

# configuration
# ---------------------------------------------------------------------------
extra/config/conf extra/config/mconf: | include/config
$(Q)$(MAKE) -C extra/config $(notdir $@)
$(top_builddir)extra/config/conf $(top_builddir)extra/config/mconf: | $(top_builddir)include/config $(top_builddir)extra/config/lxdialog
$(Q)$(MAKE) -C extra/config $(@F)

menuconfig: extra/config/mconf
$(Q)./extra/config/mconf extra/Configs/Config.in
menuconfig: $(top_builddir)extra/config/mconf
$(Q)$(top_builddir)extra/config/mconf extra/Configs/Config.in

config: extra/config/conf
$(Q)./extra/config/conf extra/Configs/Config.in
config: $(top_builddir)extra/config/conf
$(Q)$(top_builddir)extra/config/conf extra/Configs/Config.in

oldconfig: extra/config/conf
$(Q)./extra/config/conf -o extra/Configs/Config.in
oldconfig: $(top_builddir)extra/config/conf
$(Q)$(top_builddir)extra/config/conf -o extra/Configs/Config.in

silentoldconfig: extra/config/conf
$(Q)./extra/config/conf -s extra/Configs/Config.in
silentoldconfig: $(top_builddir)extra/config/conf
$(Q)$(top_builddir)extra/config/conf -s extra/Configs/Config.in

randconfig: extra/config/conf
$(Q)./extra/config/conf -r extra/Configs/Config.in
randconfig: $(top_builddir)extra/config/conf
$(Q)$(top_builddir)extra/config/conf -r extra/Configs/Config.in

allyesconfig: extra/config/conf
$(Q)./extra/config/conf -y extra/Configs/Config.in
$(SED) -i -e "s/^DODEBUG=.*/# DODEBUG is not set/" .config
$(SED) -i -e "s/^DOASSERTS=.*/# DOASSERTS is not set/" .config
$(SED) -i -e "s/^SUPPORT_LD_DEBUG_EARLY=.*/# SUPPORT_LD_DEBUG_EARLY is not set/" .config
$(SED) -i -e "s/^SUPPORT_LD_DEBUG=.*/# SUPPORT_LD_DEBUG is not set/" .config
$(SED) -i -e "s/^UCLIBC_MJN3_ONLY=.*/# UCLIBC_MJN3_ONLY is not set/" .config
$(Q)./extra/config/conf -o extra/Configs/Config.in
allyesconfig: $(top_builddir)extra/config/conf
$(Q)$(top_builddir)extra/config/conf -y extra/Configs/Config.in
$(SED) -i -e "s/^DODEBUG=.*/# DODEBUG is not set/" \
-e "s/^DOASSERTS=.*/# DOASSERTS is not set/" \
-e "s/^SUPPORT_LD_DEBUG_EARLY=.*/# SUPPORT_LD_DEBUG_EARLY is not set/" \
-e "s/^SUPPORT_LD_DEBUG=.*/# SUPPORT_LD_DEBUG is not set/" \
-e "s/^UCLIBC_MJN3_ONLY=.*/# UCLIBC_MJN3_ONLY is not set/" \
$(KCONFIG_CONFIG)
$(Q)$(top_builddir)extra/config/conf -o extra/Configs/Config.in

allnoconfig: extra/config/conf
$(Q)./extra/config/conf -n extra/Configs/Config.in
allnoconfig: $(top_builddir)extra/config/conf
$(Q)$(top_builddir)extra/config/conf -n extra/Configs/Config.in

defconfig: extra/config/conf
$(Q)./extra/config/conf -d extra/Configs/Config.in \
defconfig: $(top_builddir)extra/config/conf
$(Q)$(top_builddir)extra/config/conf -d extra/Configs/Config.in \
-D extra/Configs/defconfigs/$(ARCH)

include_clean:
$(Q)$(RM) include/fpu_control.h include/dl-osinfo.h include/hp-timing.h
$(Q)$(RM) $(top_builddir)include/fpu_control.h $(top_builddir)include/dl-osinfo.h $(top_builddir)include/hp-timing.h
@set -e; \
for i in `(cd libc/sysdeps/linux/common/sys; ls *.h)` ; do \
$(RM) include/sys/$$i; \
$(RM) $(top_builddir)include/sys/$$i; \
done; \
if [ -d libc/sysdeps/linux/$(TARGET_ARCH)/sys ] ; then \
for i in `(cd libc/sysdeps/linux/$(TARGET_ARCH)/sys; ls *.h)` ; do \
$(RM) include/sys/$$i; \
$(RM) $(top_builddir)include/sys/$$i; \
done; \
fi

clean: include_clean
$(Q)$(RM) -r lib include/bits
$(Q)$(RM) -r $(top_builddir)lib $(top_builddir)include/bits
@$(MAKE) -C utils utils_clean
+$(MAKE) -s -C test clean
@$(RM) include/linux include/asm*
@$(RM) $(top_builddir)include/linux $(top_builddir)include/asm*
$(Q)$(RM) $(top_builddir)extra/scripts/unifdef
$(Q)$(RM) -r $(LOCAL_INSTALL_PATH)

distclean: clean
-find . \( -name core -o -name \*.orig -o -name \*~ -o -name .\*.dep \) -exec $(RM) {} \;
$(RM) .config .config.old .config.cmd
$(RM) extra/locale/*.tgz
$(RM) $(top_builddir).config $(top_builddir).config.old $(top_builddir).config.cmd
$(RM) $(top_builddir)extra/locale/*.tgz
$(MAKE) -C extra/config distclean

dist release:
Expand Down
53 changes: 30 additions & 23 deletions Makerules
Expand Up @@ -6,10 +6,10 @@

PHONY := FORCE

.PHONY: dummy $(PHONY) \
.PHONY: dummy $(PHONY) subdirs \
all check test $(clean_targets) \
config dist menuconfig oldconfig release \
subdirs utils help
utils help

# order is important, the stripping uses STRIP_FLAGS for lib-so, but not for lib-a
ifeq ($(HAVE_SHARED),y)
Expand Down Expand Up @@ -54,6 +54,9 @@ headers-y: $(headers-y)

MAKEFLAGS += --no-print-directory
SHELL_SET_X := set +x
define rel_srcdir
$(shell $(CONFIG_SHELL) $(top_srcdir)/extra/scripts/relative_path.sh $(@D) .)
endef
ifneq ($(findstring s,$(MAKEFLAGS)),)
export MAKE_IS_SILENT := y
SECHO := -@false
Expand All @@ -72,7 +75,7 @@ Q := @
endif
endif

show_objs = $(subst ../,,$@)
show_objs = $(subst $(top_builddir),,$(subst ../,,$@))

pur_disp_compile.c = echo " "CC $(show_objs)
pur_disp_compile.i = echo " "CPP $(show_objs)
Expand All @@ -88,10 +91,10 @@ pur_disp_strip = echo " "STRIP $(STRIP_FLAGS) $@
pur_disp_t_strip = echo " "STRIP $(STRIP_FLAGS) $@
pur_disp_ar = echo " "AR $(ARFLAGS) $@
pur_disp_ld = echo " "LD $(1)
pur_disp_ln = echo " "LN $@
pur_disp_mkdir = echo " "MKDIR $@
pur_disp_gen = echo " "GEN $@
pur_disp_unifdef = echo " "UNIFDEF $@
pur_disp_ln = echo " "LN $(show_objs)
pur_disp_mkdir = echo " "MKDIR $(show_objs)
pur_disp_gen = echo " "GEN $(show_objs)
pur_disp_unifdef = echo " "UNIFDEF $(show_objs)
pur_disp_rm = echo " "CLEAN $(@:_clean=)

sil_disp_compile.c = true
Expand Down Expand Up @@ -205,6 +208,10 @@ define do_ln
$(Q)$(LN) -fs
endef

define do_mkdir
@$(disp_mkdir)
$(Q)$(INSTALL) -d $@
endef

define do_rm
@$(disp_rm)
Expand Down Expand Up @@ -237,8 +244,8 @@ define compile.u
@$(disp_compile.u) ; $(cmd_compile.u)
@$(disp_t_strip)
endef
cmd_hcompile.u = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -o $@ $(BUILD_LDFLAGS) $(BUILD_LDFLAGS-$(notdir $(^D))) $(BUILD_LDFLAGS-$(notdir $@)) $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
cmd_hcompile.o = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
cmd_hcompile.u = $(HOSTCC) $(filter-out $(PHONY),$^) $(DEPS-$(notdir $@)) -o $@ $(BUILD_LDFLAGS) $(BUILD_LDFLAGS-$(notdir $(^D))) $(BUILD_LDFLAGS-$(notdir $@)) $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
cmd_hcompile.o = $(HOSTCC) $(filter-out $(PHONY),$<) $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))

define link.so
$(Q)$(INSTALL) -d $(dir $@)
Expand Down Expand Up @@ -294,20 +301,20 @@ endef
CFLAGS-.os+=$(PICFLAG)
CFLAGS-.oS+=$(PICFLAG) -DSHARED

%.o: %.c FORCE ; $(compile.c)
%.os: %.c FORCE ; $(compile.c)
%.oS: %.c FORCE ; $(compile.c)
%.o: %.S FORCE ; $(compile.S)
%.os: %.S FORCE ; $(compile.S)
%.oS: %.S FORCE ; $(compile.S)
%.o: %.s FORCE ; $(compile.S)
%.os: %.s FORCE ; $(compile.S)
%.oS: %.s FORCE ; $(compile.S)
%.i: %.c FORCE ; $(compile.i)
%.i: %.S FORCE ; $(compile.i)
%.s: %.c FORCE ; $(compile.s)
%.s: %.S FORCE ; $(compile.s)
%.dep:
$(top_builddir)%.o: $(top_srcdir)%.c FORCE ; $(compile.c)
$(top_builddir)%.os: $(top_srcdir)%.c FORCE ; $(compile.c)
$(top_builddir)%.oS: $(top_srcdir)%.c FORCE ; $(compile.c)
$(top_builddir)%.o: $(top_srcdir)%.S FORCE ; $(compile.S)
$(top_builddir)%.os: $(top_srcdir)%.S FORCE ; $(compile.S)
$(top_builddir)%.oS: $(top_srcdir)%.S FORCE ; $(compile.S)
$(top_builddir)%.o: $(top_srcdir)%.s FORCE ; $(compile.S)
$(top_builddir)%.os: $(top_srcdir)%.s FORCE ; $(compile.S)
$(top_builddir)%.oS: $(top_srcdir)%.s FORCE ; $(compile.S)
$(top_builddir)%.i: $(top_srcdir)%.c FORCE ; $(compile.i)
$(top_builddir)%.i: $(top_srcdir)%.S FORCE ; $(compile.i)
$(top_builddir)%.s: $(top_srcdir)%.c FORCE ; $(compile.s)
$(top_builddir)%.s: $(top_srcdir)%.S FORCE ; $(compile.s)
$(top_builddir)%.dep:

$(top_builddir)lib/interp.c: | $(sub_headers)
$(Q)$(INSTALL) -d $(dir $@)
Expand Down

0 comments on commit 49d8a0e

Please sign in to comment.