Skip to content

Commit

Permalink
build system cleanup/restructuring as described in http://lists.openw…
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Fietkau committed Aug 7, 2007
1 parent 9882253 commit c6bc77e
Show file tree
Hide file tree
Showing 45 changed files with 316 additions and 345 deletions.
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ else
include rules.mk
include $(INCLUDE_DIR)/depends.mk
include $(INCLUDE_DIR)/subdir.mk
include $(INCLUDE_DIR)/target.mk
include target/Makefile
include package/Makefile
include tools/Makefile
include toolchain/Makefile

$(toolchain/stamp-compile): $(tools/stamp-compile)
$(target/stamp-compile): $(toolchain/stamp-install) $(tools/stamp-install)
$(target/stamp-compile): $(toolchain/stamp-install) $(tools/stamp-install) $(BUILD_DIR)/.prepared
$(package/stamp-compile): $(target/stamp-compile)
$(target/stamp-install): $(package/stamp-compile) $(package/stamp-install)

$(BUILD_DIR)/.prepared: Makefile
@mkdir -p $$(dirname $@)
@touch $@

clean: FORCE
rm -rf build_* bin tmp
rm -rf $(BUILD_DIR) $(BIN_DIR)
$(MAKE) target/linux/clean
rm -rf $(TMP_DIR)

dirclean: clean
rm -rf staging_dir_* toolchain_build_* tool_build

distclean: dirclean
rm -rf dl .config*
rm -rf $(STAGING_DIR) $(STAGING_DIR_HOST) $(STAGING_DIR_TOOLCHAIN) $(BUILD_DIR_TOOLCHAIN) $(BUILD_DIR_HOST)

# check prerequisites before starting to build
prereq: $(package/stamp-prereq) $(target/stamp-prereq) ;
Expand Down
36 changes: 18 additions & 18 deletions include/host-build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
# See /LICENSE for more information.
#

PKG_BUILD_DIR ?= $(BUILD_DIR_HOST)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/host-install

include $(INCLUDE_DIR)/host.mk
include $(INCLUDE_DIR)/unpack.mk
include $(INCLUDE_DIR)/depends.mk

STAMP_PREPARED:=$(PKG_BUILD_DIR)/.prepared_$(shell find ${CURDIR} $(PKG_FILE_DEPEND) $(DEP_FINDPARAMS) | md5s)
STAMP_CONFIGURED:=$(PKG_BUILD_DIR)/.configured
STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
STAMP_INSTALLED:=$(STAGING_DIR_HOST)/stamp/.$(PKG_NAME)_installed

override MAKEFLAGS=

include $(INCLUDE_DIR)/quilt.mk
Expand All @@ -33,24 +38,19 @@ define Build/Configure/Default
[ -x configure ] && \
$(CP) $(SCRIPT_DIR)/config.{guess,sub} $(PKG_BUILD_DIR)/$(3)/ && \
$(2) \
CPPFLAGS="-I$(STAGING_DIR)/host/include" \
LDFLAGS="-L$(STAGING_DIR)/host/lib" \
CPPFLAGS="$(HOST_CFLAGS)" \
LDFLAGS="$(HOST_LDFLAGS)" \
SHELL="$(BASH)" \
./configure \
--target=$(GNU_TARGET_NAME) \
--host=$(GNU_TARGET_NAME) \
--target=$(GNU_HOST_NAME) \
--host=$(GNU_HOST_NAME) \
--build=$(GNU_HOST_NAME) \
--program-prefix="" \
--program-suffix="" \
--prefix=/usr \
--exec-prefix=/usr \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--libexecdir=/usr/lib \
--sysconfdir=/etc \
--datadir=/usr/share \
--localstatedir=/var \
--mandir=/usr/man \
--infodir=/usr/info \
--prefix=$(STAGING_DIR_HOST) \
--exec-prefix=$(STAGING_DIR_HOST) \
--sysconfdir=$(STAGING_DIR_HOST)/etc \
--localstatedir=$(STAGING_DIR_HOST)/var \
$(DISABLE_NLS) \
$(1); \
true; \
Expand Down Expand Up @@ -84,7 +84,7 @@ ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
define HostBuild/Autoclean
$(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
$(call rdep,${CURDIR} $(PKG_FILE_DEPEND),$(STAMP_PREPARED))
$(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),$(PKG_BUILD_DIR)/.dep_files, -and -not -path "/.*" -and -not -path "*/ipkg*"))
$(if $(if $(Build/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),$(PKG_BUILD_DIR)/.dep_files, -and -not -path "/.*" -and -not -path "*/ipkg*"))
endef
endif

Expand All @@ -107,19 +107,19 @@ define HostBuild
$(call Build/Compile)
touch $$@

$(STAGING_DIR)/stampfiles/.host_$(PKG_NAME)-installed: $(STAMP_BUILT)
$(STAMP_INSTALLED): $(STAMP_BUILT)
$(call Build/Install)
mkdir -p $$(shell dirname $$@)
touch $$@

ifdef Build/Install
install: $(STAGING_DIR)/stampfiles/.host_$(PKG_NAME)-installed
install: $(STAMP_INSTALLED)
endif

package-clean: FORCE
$(call Build/Clean)
$(call Build/Uninstall)
rm -f $(STAGING_DIR)/stampfiles/.host_$(PKG_NAME)-installed
rm -f $(STAMP_INSTALLED) $(STAMP_BUILT)

download:
prepare: $(STAMP_PREPARED)
Expand Down
24 changes: 12 additions & 12 deletions include/image.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/host.mk

override MAKEFLAGS=
override MAKE:=$(SUBMAKE)
KDIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
KDIR=$(KERNEL_BUILD_DIR)

ifneq ($(CONFIG_BIG_ENDIAN),y)
JFFS2OPTS := --pad --little-endian --squash
Expand Down Expand Up @@ -40,27 +40,27 @@ ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
ifeq ($(CONFIG_TARGET_ROOTFS_JFFS2),y)
define Image/mkfs/jffs2/sub
# FIXME: removing this line will cause strange behaviour in the foreach loop below
$(STAGING_DIR)/bin/mkfs.jffs2 $(JFFS2OPTS) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(1) -d $(BUILD_DIR)/root
$(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(JFFS2OPTS) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(1) -d $(TARGET_DIR)
$(call add_jffs2_mark,$(KDIR)/root.jffs2-$(1))
$(call Image/Build,jffs2-$(1))
endef
define Image/mkfs/jffs2
rm -rf $(BUILD_DIR)/root/jffs
rm -rf $(TARGET_DIR)/jffs
$(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ)))
endef
endif

ifeq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),y)
define Image/mkfs/squashfs
@mkdir -p $(BUILD_DIR)/root/jffs
$(STAGING_DIR)/bin/mksquashfs-lzma $(BUILD_DIR)/root $(KDIR)/root.squashfs -nopad -noappend -root-owned $(SQUASHFS_OPTS)
@mkdir -p $(TARGET_DIR)/jffs
$(STAGING_DIR_HOST)/bin/mksquashfs-lzma $(TARGET_DIR) $(KDIR)/root.squashfs -nopad -noappend -root-owned $(SQUASHFS_OPTS)
$(call Image/Build,squashfs)
endef
endif

ifeq ($(CONFIG_TARGET_ROOTFS_TGZ),y)
define Image/mkfs/tgz
$(TAR) -zcf $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-rootfs.tgz --owner=root --group=root -C $(BUILD_DIR)/root/ .
$(TAR) -zcf $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-rootfs.tgz --owner=root --group=root -C $(TARGET_DIR)/ .
endef
endif
else
Expand All @@ -75,18 +75,18 @@ ifeq ($(CONFIG_TARGET_ROOTFS_EXT2FS),y)
E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_FSPART)*1024)))

define Image/mkfs/ext2
$(STAGING_DIR)/bin/genext2fs -U -b $(E2SIZE) -I $(CONFIG_TARGET_ROOTFS_MAXINODE) -d $(BUILD_DIR)/root/ $(KDIR)/root.ext2
$(STAGING_DIR_HOST)/bin/genext2fs -U -b $(E2SIZE) -I $(CONFIG_TARGET_ROOTFS_MAXINODE) -d $(TARGET_DIR)/ $(KDIR)/root.ext2
$(call Image/Build,ext2)
endef
endif


define Image/mkfs/prepare/default
find $(BUILD_DIR)/root -type f -not -perm +0100 -not -name 'ssh_host*' | $(XARGS) chmod 0644
find $(BUILD_DIR)/root -type f -perm +0100 | $(XARGS) chmod 0755
find $(BUILD_DIR)/root -type d | $(XARGS) chmod 0755
mkdir -p $(BUILD_DIR)/root/tmp
chmod 0777 $(BUILD_DIR)/root/tmp
find $(TARGET_DIR) -type f -not -perm +0100 -not -name 'ssh_host*' | $(XARGS) chmod 0644
find $(TARGET_DIR) -type f -perm +0100 | $(XARGS) chmod 0755
find $(TARGET_DIR) -type d | $(XARGS) chmod 0755
$(INSTALL_DIR) $(TARGET_DIR)/tmp
chmod 0777 $(TARGET_DIR)/tmp
endef

define Image/mkfs/prepare
Expand Down
2 changes: 2 additions & 0 deletions include/kernel-build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ $(eval $(call shexport,Target/Description))
download: $(DL_DIR)/$(LINUX_SOURCE)
prepare: $(STAMP_CONFIGURED)
compile: $(LINUX_DIR)/.modules
$(MAKE) -C image compile

oldconfig menuconfig: $(STAMP_PREPARED) FORCE
$(call Kernel/Configure)
$(SCRIPT_DIR)/config.pl '+' $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG) > $(LINUX_DIR)/.config
Expand Down
4 changes: 2 additions & 2 deletions include/kernel-defaults.mk
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ ifeq ($(KERNEL),2.6)
define Kernel/SetInitramfs
mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
echo 'CONFIG_INITRAMFS_SOURCE="$(TARGET_DIR)"' >> $(LINUX_DIR)/.config
echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
endef
else
define Kernel/SetInitramfs
mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
rm -f $(BUILD_DIR)/root/init
rm -f $(TARGET_DIR)/init
echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
endef
endif
Expand Down
6 changes: 3 additions & 3 deletions include/kernel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ else

KERNEL_PATCHVER:=$(shell echo $(LINUX_VERSION) | cut -d. -f1,2,3 | cut -d- -f1)
PLATFORM_DIR := $(TOPDIR)/target/linux/$(BOARD)-$(KERNEL)
PATCH_DIR := ./patches$(shell [ -d "./patches-$(KERNEL_PATCHVER)" ] && printf -- "-$(KERNEL_PATCHVER)" || true )
KERNEL_BUILD_DIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
LINUX_DIR := $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
PATCH_DIR ?= ./patches$(shell [ -d "./patches-$(KERNEL_PATCHVER)" ] && printf -- "-$(KERNEL_PATCHVER)" || true )
KERNEL_BUILD_DIR ?= $(BUILD_DIR_BASE)/linux-$(KERNEL)-$(BOARD)$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX))
LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)

MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)
TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
Expand Down
1 change: 1 addition & 0 deletions include/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ all: $(if $(DUMP),dumpinfo,compile)

PKG_BUILD_DIR ?= $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
PKG_MD5SUM ?= unknown

include $(INCLUDE_DIR)/prereq.mk
include $(INCLUDE_DIR)/host.mk
Expand Down
2 changes: 1 addition & 1 deletion include/subdir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ endef
# Parameters: <subdir> <name> <target>
define stampfile
$(1)/stamp-$(3):=$(STAGING_DIR)/stampfiles/.$(2)_$(3)
$(if __rdep_$(1),,
$(if $(__rdep_$(1)),,
$(call rdep,$(1),$$($(1)/stamp-$(3)),)
__rdep_$(1):=1
)
Expand Down
5 changes: 4 additions & 1 deletion include/toplevel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ download: .config FORCE
$(MAKE) -j1 package/download
$(MAKE) -j1 target/download

clean dirclean distclean:
clean dirclean:
@$(MAKE) $@

prereq:: .config
Expand All @@ -118,6 +118,9 @@ symlinkclean:
-find package -type l | xargs rm -f
rm -rf tmp

distclean:
rm -rf tmp build_dir staging_dir dl .config*

ifeq ($(findstring v,$(DEBUG)),)
.SILENT: symlinkclean clean dirclean distclean config-clean download help tmpinfo-clean .config scripts/config/mconf scripts/config/conf menuconfig tmp/.prereq-build tmp/.prereq-package tmp/.prereq-target prepare-tmpinfo
endif
Expand Down
16 changes: 8 additions & 8 deletions package/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ $(curdir)/builddirs-install:=. $(sort $(package-y))
$(curdir)/install:=$(curdir)/install-cleanup

$(curdir)/cleanup: $(TMP_DIR)/.build
rm -rf $(BUILD_DIR)/root
rm -rf $(TARGET_DIR)

$(curdir)/rootfs-prepare: $(TMP_DIR)/.build
@if [ -d $(TOPDIR)/files ]; then \
$(CP) $(TOPDIR)/files/. $(BUILD_DIR)/root; \
$(CP) $(TOPDIR)/files/. $(TARGET_DIR); \
fi
@mkdir -p $(BUILD_DIR)/root/etc/rc.d
@mkdir -p $(TARGET_DIR)/etc/rc.d
@( \
cd $(BUILD_DIR)/root; \
cd $(TARGET_DIR); \
for script in ./etc/init.d/*; do \
grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$script enable; \
IPKG_INSTROOT=$(TARGET_DIR) $(which bash) ./etc/rc.common $$script enable; \
done || true \
)
@-find $(BUILD_DIR)/root -name CVS | $(XARGS) rm -rf
@-find $(BUILD_DIR)/root -name .svn | $(XARGS) rm -rf
@-find $(BUILD_DIR)/root -name '.#*' | $(XARGS) rm -f
@-find $(TARGET_DIR) -name CVS | $(XARGS) rm -rf
@-find $(TARGET_DIR) -name .svn | $(XARGS) rm -rf
@-find $(TARGET_DIR) -name '.#*' | $(XARGS) rm -f

$(curdir)/index: FORCE
@(cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages)
Expand Down
24 changes: 11 additions & 13 deletions package/base-files/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ include $(INCLUDE_DIR)/package.mk

ifneq ($(DUMP),1)
TARGET:=-$(BOARD)-$(KERNEL)
UCLIBC_VERSION:=${shell cat $(STAGING_DIR)/uclibc_version 2>/dev/null}
UCLIBC_EXTRA_VERSION:=${shell cat $(STAGING_DIR)/uclibc_extra_version 2>/dev/null}
LIBGCC_VERSION:=${shell cat $(STAGING_DIR)/gcc_version 2>/dev/null}
LIBGCC_VERSION:=$(GCC_VERSION)
else
UCLIBC_VERSION:=<UCLIBC_VERSION>
LIBGCC_VERSION:=<LIBGCC_VERSION>
Expand Down Expand Up @@ -92,7 +90,7 @@ define Package/uclibc/Default
CATEGORY:=Base system
DEPENDS:=@!NATIVE_TOOLCHAIN
URL:=http://uclibc.org/
VERSION:=$(UCLIBC_VERSION)-$(PKG_RELEASE)
VERSION:=$(UCLIBC_VERSION)$(UCLIBC_PATCHVER)-$(PKG_RELEASE)
endef

define Package/libpthread
Expand Down Expand Up @@ -158,43 +156,43 @@ endef

define Package/libgcc/install
$(INSTALL_DIR) $(1)/lib
$(CP) $(STAGING_DIR)/lib/libgcc_s.so.* $(1)/lib/
$(CP) $(TOOLCHAIN_DIR)/lib/libgcc_s.so.* $(1)/lib/
endef

ifeq ($(word 1,$(subst ., ,$(LIBGCC_VERSION))),4)
define Package/libssp/install
$(INSTALL_DIR) $(1)/lib
$(CP) $(STAGING_DIR)/lib/libssp.so.* $(1)/lib/
$(CP) $(TOOLCHAIN_DIR)/lib/libssp.so.* $(1)/lib/
endef
endif

define Package/libstdcpp/install
$(INSTALL_DIR) $(1)/lib
$(CP) $(STAGING_DIR)/lib/libstdc++.so.* $(1)/lib/
$(CP) $(TOOLCHAIN_DIR)/lib/libstdc++.so.* $(1)/lib/
endef

define Package/libpthread/install
$(INSTALL_DIR) $(1)/lib
$(CP) $(STAGING_DIR)/lib/libpthread.so.* $(1)/lib/
$(CP) $(STAGING_DIR)/lib/libpthread-$(UCLIBC_VERSION).so $(1)/lib/
$(CP) $(TOOLCHAIN_DIR)/lib/libpthread.so.* $(1)/lib/
$(CP) $(TOOLCHAIN_DIR)/lib/libpthread-$(UCLIBC_VERSION).so $(1)/lib/
endef

define Package/uclibc/install
$(INSTALL_DIR) $(1)/lib
for file in ld-uClibc libc libcrypt libdl libm libnsl libresolv librt libuClibc libutil; do \
$(CP) $(STAGING_DIR)/lib/$$$$file.so.* $(1)/lib/; \
$(CP) $(STAGING_DIR)/lib/$$$$file-$(UCLIBC_VERSION).so $(1)/lib/; \
$(CP) $(TOOLCHAIN_DIR)/lib/$$$$file.so.* $(1)/lib/; \
$(CP) $(TOOLCHAIN_DIR)/lib/$$$$file-$(UCLIBC_VERSION).so $(1)/lib/; \
done
endef

define Package/ldd/install
$(INSTALL_DIR) $(1)/bin/
$(CP) $(TOOLCHAIN_BUILD_DIR)/uClibc-$(UCLIBC_EXTRA_VERSION)/utils/ldd $(1)/bin/
$(CP) $(TOOLCHAIN_DIR)/utils/ldd $(1)/bin/
endef

define Package/ldconfig/install
$(INSTALL_DIR) $(1)/bin/
$(CP) $(TOOLCHAIN_BUILD_DIR)/uClibc-$(UCLIBC_EXTRA_VERSION)/utils/ldconfig $(1)/bin/
$(CP) $(TOOLCHAIN_DIR)/utils/ldconfig $(1)/bin/
endef

ifneq ($(DUMP),1)
Expand Down
1 change: 1 addition & 0 deletions package/bridge/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd

PKG_BUILD_DIR:=$(BUILD_DIR)/bridge-utils-$(PKG_VERSION)

include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk

define Package/bridge
Expand Down
Loading

0 comments on commit c6bc77e

Please sign in to comment.