[target] derive system from hostcc to allow building inside a chroot
[target] derive system from hostcc to allow building inside a chroot

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@33228 3c298f89-4303-0410-b956-a3cf2f4a3e73

# #
# Copyright (C) 2006-2012 OpenWrt.org # Copyright (C) 2006-2012 OpenWrt.org
# #
# This is free software, licensed under the GNU General Public License v2. # This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information. # See /LICENSE for more information.
# #
   
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/host.mk include $(INCLUDE_DIR)/host.mk
include $(INCLUDE_DIR)/version.mk include $(INCLUDE_DIR)/version.mk
   
override MAKEFLAGS= override MAKEFLAGS=
   
PKG_OS:=$(shell uname -s) PKG_OS:=$(word 2,$(subst -, ,$(shell $(HOSTCC) -dumpmachine)))
PKG_CPU:=$(shell uname -m | sed "s/ //g") PKG_CPU:=$(word 1,$(subst -, ,$(shell $(HOSTCC) -dumpmachine)))
   
IB_NAME:=OpenWrt-ImageBuilder-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))-for-$(PKG_OS)-$(PKG_CPU) IB_NAME:=OpenWrt-ImageBuilder-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))-for-$(PKG_OS)-$(PKG_CPU)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(IB_NAME) PKG_BUILD_DIR:=$(BUILD_DIR)/$(IB_NAME)
IB_KDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(KERNEL_BUILD_DIR)) IB_KDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(KERNEL_BUILD_DIR))
IB_LDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(LINUX_DIR)) IB_LDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(LINUX_DIR))
   
all: compile all: compile
   
$(BIN_DIR)/$(IB_NAME).tar.bz2: clean $(BIN_DIR)/$(IB_NAME).tar.bz2: clean
rm -rf $(PKG_BUILD_DIR) rm -rf $(PKG_BUILD_DIR)
mkdir -p $(IB_KDIR) $(IB_LDIR) $(PKG_BUILD_DIR)/staging_dir/host \ mkdir -p $(IB_KDIR) $(IB_LDIR) $(PKG_BUILD_DIR)/staging_dir/host \
$(PKG_BUILD_DIR)/target $(PKG_BUILD_DIR)/scripts $(PKG_BUILD_DIR)/target $(PKG_BUILD_DIR)/scripts
-cp $(TOPDIR)/.config $(PKG_BUILD_DIR)/.config -cp $(TOPDIR)/.config $(PKG_BUILD_DIR)/.config
$(CP) \ $(CP) \
$(INCLUDE_DIR) $(SCRIPT_DIR) \ $(INCLUDE_DIR) $(SCRIPT_DIR) \
$(TOPDIR)/rules.mk \ $(TOPDIR)/rules.mk \
./files/Makefile \ ./files/Makefile \
./files/repositories.conf \ ./files/repositories.conf \
$(TMP_DIR)/.targetinfo \ $(TMP_DIR)/.targetinfo \
$(TMP_DIR)/.packageinfo \ $(TMP_DIR)/.packageinfo \
$(PKG_BUILD_DIR)/ $(PKG_BUILD_DIR)/
$(VERSION_SED) $(PKG_BUILD_DIR)/repositories.conf $(VERSION_SED) $(PKG_BUILD_DIR)/repositories.conf
$(CP) $(PACKAGE_DIR) $(PKG_BUILD_DIR)/packages $(CP) $(PACKAGE_DIR) $(PKG_BUILD_DIR)/packages
$(CP) $(TOPDIR)/target/linux $(PKG_BUILD_DIR)/target/ $(CP) $(TOPDIR)/target/linux $(PKG_BUILD_DIR)/target/
rm -rf \ rm -rf \
$(PKG_BUILD_DIR)/target/linux/*/files{,-*} \ $(PKG_BUILD_DIR)/target/linux/*/files{,-*} \
$(PKG_BUILD_DIR)/target/linux/*/patches{,-*} $(PKG_BUILD_DIR)/target/linux/*/patches{,-*}
-cp $(KERNEL_BUILD_DIR)/* $(IB_KDIR)/ # don't copy subdirectories here -cp $(KERNEL_BUILD_DIR)/* $(IB_KDIR)/ # don't copy subdirectories here
-cp $(LINUX_DIR)/.config $(IB_LDIR)/ -cp $(LINUX_DIR)/.config $(IB_LDIR)/
$(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(PKG_BUILD_DIR)/include/version.mk $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(PKG_BUILD_DIR)/include/version.mk
find $(PKG_BUILD_DIR) -name CVS -o -name .git -o -name .svn \ find $(PKG_BUILD_DIR) -name CVS -o -name .git -o -name .svn \
| $(XARGS) rm -rf | $(XARGS) rm -rf
find $(STAGING_DIR_HOST)/bin -maxdepth 1 -type f -perm -u=x \ find $(STAGING_DIR_HOST)/bin -maxdepth 1 -type f -perm -u=x \
| $(XARGS) $(SCRIPT_DIR)/bundle-libraries.sh $(PKG_BUILD_DIR)/staging_dir/host/bin | $(XARGS) $(SCRIPT_DIR)/bundle-libraries.sh $(PKG_BUILD_DIR)/staging_dir/host/bin
$(TAR) c -C $(BUILD_DIR) $(IB_NAME) | bzip2 -c > $@ $(TAR) c -C $(BUILD_DIR) $(IB_NAME) | bzip2 -c > $@
   
download: download:
prepare: prepare:
compile: $(BIN_DIR)/$(IB_NAME).tar.bz2 compile: $(BIN_DIR)/$(IB_NAME).tar.bz2
install: compile install: compile
   
clean: FORCE clean: FORCE
rm -rf $(PKG_BUILD_DIR) $(BIN_DIR)/$(IB_NAME).tar.bz2 rm -rf $(PKG_BUILD_DIR) $(BIN_DIR)/$(IB_NAME).tar.bz2
   
# #
# Copyright (C) 2006-2008 OpenWrt.org # Copyright (C) 2006-2008 OpenWrt.org
# #
# This is free software, licensed under the GNU General Public License v2. # This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information. # See /LICENSE for more information.
# #
   
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/host.mk include $(INCLUDE_DIR)/host.mk
   
override MAKEFLAGS= override MAKEFLAGS=
   
PKG_OS:=$(shell uname -s) PKG_OS:=$(word 2,$(subst -, ,$(shell $(HOSTCC) -dumpmachine)))
PKG_CPU:=$(shell uname -m) PKG_CPU:=$(word 1,$(subst -, ,$(shell $(HOSTCC) -dumpmachine)))
   
SDK_NAME:=OpenWrt-SDK-$(BOARD)-for-$(PKG_OS)-$(PKG_CPU)-gcc-$(GCCV)_$(LIBC)-$(LIBCV) SDK_NAME:=OpenWrt-SDK-$(BOARD)-for-$(PKG_OS)-$(PKG_CPU)-gcc-$(GCCV)_$(LIBC)-$(LIBCV)
SDK_BUILD_DIR:=$(BUILD_DIR)/$(SDK_NAME) SDK_BUILD_DIR:=$(BUILD_DIR)/$(SDK_NAME)
EXCLUDE_DIRS:=*/ccache \ EXCLUDE_DIRS:=*/ccache \
*/stamp \ */stamp \
*/stampfiles \ */stampfiles \
*/man \ */man \
*/info */info
   
SVN_PACKAGE_URL=$(shell svn info ../../package | awk '/^URL:/ { print $$2; }') SVN_PACKAGE_URL=$(shell svn info ../../package | awk '/^URL:/ { print $$2; }')
   
all: compile all: compile
   
$(BIN_DIR)/$(SDK_NAME).tar.bz2: clean $(BIN_DIR)/$(SDK_NAME).tar.bz2: clean
mkdir -p $(SDK_BUILD_DIR)/dl $(SDK_BUILD_DIR)/package mkdir -p $(SDK_BUILD_DIR)/dl $(SDK_BUILD_DIR)/package
$(CP) $(INCLUDE_DIR) $(SCRIPT_DIR) $(TOPDIR)/docs $(SDK_BUILD_DIR)/ $(CP) $(INCLUDE_DIR) $(SCRIPT_DIR) $(TOPDIR)/docs $(SDK_BUILD_DIR)/
$(TAR) -cf - -C $(TOPDIR) \ $(TAR) -cf - -C $(TOPDIR) \
$(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \ $(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
--exclude="staging_dir/$(ARCH)" \ --exclude="staging_dir/$(ARCH)" \
staging_dir/host staging_dir/target-$(ARCH)$(ARCH_SUFFIX)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi) \ staging_dir/host staging_dir/target-$(ARCH)$(ARCH_SUFFIX)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi) \
staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi) | \ staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi) | \
$(TAR) -xf - -C $(SDK_BUILD_DIR) $(TAR) -xf - -C $(SDK_BUILD_DIR)
mkdir -p $(SDK_BUILD_DIR)/target/linux mkdir -p $(SDK_BUILD_DIR)/target/linux
$(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/ $(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/
rm -rf \ rm -rf \
$(SDK_BUILD_DIR)/target/linux/*/files \ $(SDK_BUILD_DIR)/target/linux/*/files \
$(SDK_BUILD_DIR)/target/linux/*/patches $(SDK_BUILD_DIR)/target/linux/*/patches
$(CP) -L \ $(CP) -L \
$(TOPDIR)/LICENSE \ $(TOPDIR)/LICENSE \
$(TOPDIR)/rules.mk \ $(TOPDIR)/rules.mk \
$(TOPDIR)/.config \ $(TOPDIR)/.config \
./files/Config.in \ ./files/Config.in \
./files/Makefile \ ./files/Makefile \
./files/README.SDK \ ./files/README.SDK \
$(SDK_BUILD_DIR)/ $(SDK_BUILD_DIR)/
$(CP) \ $(CP) \
./files/package/rules.mk \ ./files/package/rules.mk \
$(TOPDIR)/package/Makefile \ $(TOPDIR)/package/Makefile \
$(SDK_BUILD_DIR)/package/ $(SDK_BUILD_DIR)/package/
echo "src-svn trunk $(SVN_PACKAGE_URL)" \ echo "src-svn trunk $(SVN_PACKAGE_URL)" \
> $(SDK_BUILD_DIR)/feeds.conf.default > $(SDK_BUILD_DIR)/feeds.conf.default
cat $(TOPDIR)/feeds.conf.default \ cat $(TOPDIR)/feeds.conf.default \
>> $(SDK_BUILD_DIR)/feeds.conf.default >> $(SDK_BUILD_DIR)/feeds.conf.default
$(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(SDK_BUILD_DIR)/include/version.mk $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(SDK_BUILD_DIR)/include/version.mk
find $(SDK_BUILD_DIR) -name .git | $(XARGS) rm -rf find $(SDK_BUILD_DIR) -name .git | $(XARGS) rm -rf
find $(SDK_BUILD_DIR) -name .svn | $(XARGS) rm -rf find $(SDK_BUILD_DIR) -name .svn | $(XARGS) rm -rf
find $(SDK_BUILD_DIR) -name CVS | $(XARGS) rm -rf find $(SDK_BUILD_DIR) -name CVS | $(XARGS) rm -rf
(cd $(BUILD_DIR); \ (cd $(BUILD_DIR); \
tar cfj $@ $(SDK_NAME); \ tar cfj $@ $(SDK_NAME); \
) )
   
download: download:
prepare: prepare:
compile: $(BIN_DIR)/$(SDK_NAME).tar.bz2 compile: $(BIN_DIR)/$(SDK_NAME).tar.bz2
install: compile install: compile
   
clean: clean:
rm -rf $(SDK_BUILD_DIR) $(BIN_DIR)/$(SDK_NAME).tar.bz2 rm -rf $(SDK_BUILD_DIR) $(BIN_DIR)/$(SDK_NAME).tar.bz2
   
# #
# Copyright (C) 2008-2009 Industrie Dial Face S.p.A. # Copyright (C) 2008-2009 Industrie Dial Face S.p.A.
# Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com> # Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com>
# Copyright (C) 2006-2008 OpenWrt.org # Copyright (C) 2006-2008 OpenWrt.org
# #
# This is free software, licensed under the GNU General Public License v2. # This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information. # See /LICENSE for more information.
# #
   
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/host.mk include $(INCLUDE_DIR)/host.mk
   
override MAKEFLAGS= override MAKEFLAGS=
   
PKG_OS:=$(shell uname -s) PKG_OS:=$(word 2,$(subst -, ,$(shell $(HOSTCC) -dumpmachine)))
PKG_CPU:=$(shell uname -m) PKG_CPU:=$(word 1,$(subst -, ,$(shell $(HOSTCC) -dumpmachine)))
   
TOOLCHAIN_NAME:=OpenWrt-Toolchain-$(BOARD)-for-$(ARCH)$(ARCH_SUFFIX)-gcc-$(GCCV)$(DIR_SUFFIX) TOOLCHAIN_NAME:=OpenWrt-Toolchain-$(BOARD)-for-$(ARCH)$(ARCH_SUFFIX)-gcc-$(GCCV)$(DIR_SUFFIX)
TOOLCHAIN_BUILD_DIR:=$(BUILD_DIR)/$(TOOLCHAIN_NAME) TOOLCHAIN_BUILD_DIR:=$(BUILD_DIR)/$(TOOLCHAIN_NAME)
EXCLUDE_DIRS:=*/ccache \ EXCLUDE_DIRS:=*/ccache \
*/stamp \ */stamp \
*/stampfiles \ */stampfiles \
*/man \ */man \
*/info */info
   
all: compile all: compile
   
TOOLCHAIN_PREFIX:=$(TOOLCHAIN_BUILD_DIR)/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)$(DIR_SUFFIX) TOOLCHAIN_PREFIX:=$(TOOLCHAIN_BUILD_DIR)/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)$(DIR_SUFFIX)
   
$(BIN_DIR)/$(TOOLCHAIN_NAME).tar.bz2: clean $(BIN_DIR)/$(TOOLCHAIN_NAME).tar.bz2: clean
mkdir -p $(TOOLCHAIN_BUILD_DIR) mkdir -p $(TOOLCHAIN_BUILD_DIR)
$(TAR) -cf - -C $(TOPDIR)/staging_dir/ \ $(TAR) -cf - -C $(TOPDIR)/staging_dir/ \
$(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \ $(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)$(DIR_SUFFIX) | \ toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)$(DIR_SUFFIX) | \
$(TAR) -xf - -C $(TOOLCHAIN_BUILD_DIR) $(TAR) -xf - -C $(TOOLCHAIN_BUILD_DIR)
   
$(CP) $(TOPDIR)/LICENSE ./files/README.TOOLCHAIN \ $(CP) $(TOPDIR)/LICENSE ./files/README.TOOLCHAIN \
$(TOOLCHAIN_BUILD_DIR)/ $(TOOLCHAIN_BUILD_DIR)/
   
$(CP) ./files/wrapper.sh $(TOOLCHAIN_PREFIX)/bin/$(REAL_GNU_TARGET_NAME)-wrapper.sh $(CP) ./files/wrapper.sh $(TOOLCHAIN_PREFIX)/bin/$(REAL_GNU_TARGET_NAME)-wrapper.sh
chmod +x $(TOOLCHAIN_PREFIX)/bin/$(REAL_GNU_TARGET_NAME)-wrapper.sh chmod +x $(TOOLCHAIN_PREFIX)/bin/$(REAL_GNU_TARGET_NAME)-wrapper.sh
(cd $(TOOLCHAIN_PREFIX)/bin; \ (cd $(TOOLCHAIN_PREFIX)/bin; \
for app in cc gcc g++ c++ cpp ld as ; do \ for app in cc gcc g++ c++ cpp ld as ; do \
[ -f $(REAL_GNU_TARGET_NAME)-$${app} ] && mv $(REAL_GNU_TARGET_NAME)-$${app} $(REAL_GNU_TARGET_NAME)-$${app}.bin ; \ [ -f $(REAL_GNU_TARGET_NAME)-$${app} ] && mv $(REAL_GNU_TARGET_NAME)-$${app} $(REAL_GNU_TARGET_NAME)-$${app}.bin ; \
ln -sf $(REAL_GNU_TARGET_NAME)-wrapper.sh $(REAL_GNU_TARGET_NAME)-$${app} ; \ ln -sf $(REAL_GNU_TARGET_NAME)-wrapper.sh $(REAL_GNU_TARGET_NAME)-$${app} ; \
done; \ done; \
) )
echo REVISION:="$(REVISION)" > $(TOOLCHAIN_BUILD_DIR)/version.mk echo REVISION:="$(REVISION)" > $(TOOLCHAIN_BUILD_DIR)/version.mk
find $(TOOLCHAIN_BUILD_DIR) -name .git | $(XARGS) rm -rf find $(TOOLCHAIN_BUILD_DIR) -name .git | $(XARGS) rm -rf
find $(TOOLCHAIN_BUILD_DIR) -name .svn | $(XARGS) rm -rf find $(TOOLCHAIN_BUILD_DIR) -name .svn | $(XARGS) rm -rf
find $(TOOLCHAIN_BUILD_DIR) -name CVS | $(XARGS) rm -rf find $(TOOLCHAIN_BUILD_DIR) -name CVS | $(XARGS) rm -rf
(cd $(BUILD_DIR); \ (cd $(BUILD_DIR); \
tar cfj $@ $(TOOLCHAIN_NAME); \ tar cfj $@ $(TOOLCHAIN_NAME); \
) )
   
download: download:
prepare: prepare:
compile: $(BIN_DIR)/$(TOOLCHAIN_NAME).tar.bz2 compile: $(BIN_DIR)/$(TOOLCHAIN_NAME).tar.bz2
install: compile install: compile
   
clean: clean:
rm -rf $(TOOLCHAIN_BUILD_DIR) $(BIN_DIR)/$(TOOLCHAIN_NAME).tar.bz2 rm -rf $(TOOLCHAIN_BUILD_DIR) $(BIN_DIR)/$(TOOLCHAIN_NAME).tar.bz2
   
comments