next round of build system cleanup - convert package/ to new structure
next round of build system cleanup - convert package/ to new structure

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

file:a/Makefile -> file:b/Makefile
# Makefile for OpenWrt # Makefile for OpenWrt
# #
# Copyright (C) 2007 OpenWrt.org # Copyright (C) 2007 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.
# #
   
all: world  
   
TOPDIR:=${CURDIR} TOPDIR:=${CURDIR}
LC_ALL:=C LC_ALL:=C
LANG:=C LANG:=C
IS_TTY:=${shell tty -s && echo 1 || echo 0} IS_TTY:=${shell tty -s && echo 1 || echo 0}
export TOPDIR LC_ALL LANG IS_TTY export TOPDIR LC_ALL LANG IS_TTY
   
  world:
   
  include $(TOPDIR)/include/debug.mk
  include $(TOPDIR)/include/host.mk
   
ifneq ($(OPENWRT_BUILD),1) ifneq ($(OPENWRT_BUILD),1)
export OPENWRT_BUILD:=1 override OPENWRT_BUILD=1
  export OPENWRT_BUILD
include $(TOPDIR)/include/toplevel.mk include $(TOPDIR)/include/toplevel.mk
else else
include $(TOPDIR)/include/host.mk  
   
include rules.mk include rules.mk
include $(INCLUDE_DIR)/depends.mk include $(INCLUDE_DIR)/depends.mk
include $(INCLUDE_DIR)/subdir.mk include $(INCLUDE_DIR)/subdir.mk
  include package/Makefile
include tools/Makefile include tools/Makefile
include toolchain/Makefile include toolchain/Makefile
   
clean: FORCE clean: FORCE
rm -rf build_* bin tmp rm -rf build_* bin tmp
   
dirclean: clean dirclean: clean
rm -rf staging_dir_* toolchain_build_* tool_build rm -rf staging_dir_* toolchain_build_* tool_build
   
distclean: dirclean config-clean symlinkclean docs/clean distclean: dirclean config-clean symlinkclean docs/clean
rm -rf dl rm -rf dl
   
package/% target/%: FORCE target/%: FORCE
$(MAKE) -C $(patsubst %/$*,%,$@) $* $(MAKE) -C $(patsubst %/$*,%,$@) $*
   
world: .config $(tools/stamp) $(toolchain/stamp) FORCE # check prerequisites before starting to build
  prereq: tmp/.prereq-target $(package/stamp-prereq) ;
   
  world: .config $(tools/stamp-install) $(toolchain/stamp-install) FORCE
$(MAKE) target/compile $(MAKE) target/compile
$(MAKE) package/compile $(MAKE) package/compile
$(MAKE) package/install $(MAKE) package/install
$(MAKE) target/install $(MAKE) target/install
$(MAKE) package/index $(MAKE) package/index
   
  package/symlinks:
  $(SCRIPT_DIR)/feeds.sh $(CONFIG_SOURCE_FEEDS) $(CONFIG_SOURCE_FEEDS_REV)
   
  # FIXME: remove after converting target/ to new structure
  tmp/.prereq-target: tmp/.targetinfo .config
  tmp/.prereq-target: include/prereq.mk
  mkdir -p tmp
  rm -f tmp/.host.mk
  @+$(NO_TRACE_MAKE) -s -C target prereq 2>/dev/null || { \
  echo "Prerequisite check failed. Use FORCE=1 to override."; \
  false; \
  }
  touch $@
  .SILENT: tmp/.prereq-target
   
endif endif
   
file:b/include/debug.mk (new)
  #
  # Copyright (C) 2007 OpenWrt.org
  #
  # This is free software, licensed under the GNU General Public License v2.
  # See /LICENSE for more information.
  #
 
  # debug flags:
  #
  # d: show subdirectory tree
  # t: show added targets
  # l: show legacy targets
  # v: verbose (no .SILENCE for common targets)
 
  ifeq ($(DEBUG),all)
  build_debug:=dltv
  else
  build_debug:=$(DEBUG)
  endif
 
  define debug
  $$(findstring $(2),$$(if $$(DEBUG_DIR),$$(if $$(filter $$(DEBUG_DIR)%,$(1)),$(build_debug)),$(build_debug)))
  endef
 
  define warn
  $$(if $(call debug,$(1),$(2)),$$(warning $(3)))
  endef
 
  define warn_eval
  $(call warn,$(1),$(2),$(3) $(4))
  $(4)
  endef
 
 
 
# #
# Copyright (C) 2006 OpenWrt.org # Copyright (C) 2007 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.
# #
   
  TMP_DIR ?= $(TOPDIR)/tmp
-include $(TMP_DIR)/.host.mk -include $(TMP_DIR)/.host.mk
   
export TAR export TAR
TMP_DIR ?= $(TOPDIR)/tmp  
   
ifneq ($(__host_inc),1) ifneq ($(__host_inc),1)
__host_inc:=1 __host_inc:=1
  .PRECIOUS: $(TMP_DIR)/.host.mk
$(TMP_DIR)/.host.mk: $(TOPDIR)/include/host.mk $(TMP_DIR)/.host.mk: $(TOPDIR)/include/host.mk
@mkdir -p $(TMP_DIR) @mkdir -p $(TMP_DIR)
@( \ @( \
HOST_OS=`uname`; \ HOST_OS=`uname`; \
case "$$HOST_OS" in \ case "$$HOST_OS" in \
Linux) HOST_ARCH=`uname -m`;; \ Linux) HOST_ARCH=`uname -m`;; \
*) HOST_ARCH=`uname -p`;; \ *) HOST_ARCH=`uname -p`;; \
esac; \ esac; \
GNU_HOST_NAME=`gcc -dumpmachine`; \ GNU_HOST_NAME=`gcc -dumpmachine`; \
[ -n "$$GNU_HOST_NAME" ] || \ [ -n "$$GNU_HOST_NAME" ] || \
GNU_HOST_NAME=`$(SCRIPT_DIR)/config.guess`; \ GNU_HOST_NAME=`$(SCRIPT_DIR)/config.guess`; \
echo "HOST_OS:=$$HOST_OS" > $@; \ echo "HOST_OS:=$$HOST_OS" > $@; \
echo "HOST_ARCH:=$$HOST_ARCH" >> $@; \ echo "HOST_ARCH:=$$HOST_ARCH" >> $@; \
echo "GNU_HOST_NAME:=$$GNU_HOST_NAME" >> $@; \ echo "GNU_HOST_NAME:=$$GNU_HOST_NAME" >> $@; \
TAR=`which gtar 2>/dev/null`; \ TAR=`which gtar 2>/dev/null`; \
[ -n "$$TAR" -a -x "$$TAR" ] || TAR=`which tar 2>/dev/null`; \ [ -n "$$TAR" -a -x "$$TAR" ] || TAR=`which tar 2>/dev/null`; \
echo "TAR:=$$TAR" >> $@; \ echo "TAR:=$$TAR" >> $@; \
echo "BASH:=$(shell which bash)" >> $@; \ echo "BASH:=$(shell which bash)" >> $@; \
if find -L /tmp -maxdepth 0 >/dev/null 2>/dev/null; then \ if find -L /tmp -maxdepth 0 >/dev/null 2>/dev/null; then \
echo 'FIND_L=find -L $$(1)' >>$@; \ echo 'FIND_L=find -L $$(1)' >>$@; \
else \ else \
echo 'FIND_L=find $$(1) -follow' >> $@; \ echo 'FIND_L=find $$(1) -follow' >> $@; \
fi; \ fi; \
) )
   
endif endif
   
ifeq ($(HOST_OS),Linux) ifeq ($(HOST_OS),Linux)
XARGS:=xargs -r XARGS:=xargs -r
else else
XARGS:=xargs XARGS:=xargs
endif endif
   
# #
# Copyright (C) 2007 OpenWrt.org # Copyright (C) 2007 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.
# #
   
ifeq ($(KERNEL_BUILD),1) ifeq ($(KERNEL_BUILD),1)
PKG_BUILD_DIR:=$(LINUX_DIR) PKG_BUILD_DIR:=$(LINUX_DIR)
endif endif
PATCH_DIR?=./patches PATCH_DIR?=./patches
   
  ifeq ($(MAKECMDGOALS),refresh)
  override QUILT=1
  endif
   
define Quilt/Patch define Quilt/Patch
@for patch in $$$$( (cd $(1) && ls) 2>/dev/null ); do ( \ @for patch in $$$$( (cd $(1) && ls) 2>/dev/null ); do ( \
cp "$(1)/$$$$patch" $(PKG_BUILD_DIR); \ cp "$(1)/$$$$patch" $(PKG_BUILD_DIR); \
cd $(PKG_BUILD_DIR); \ cd $(PKG_BUILD_DIR); \
quilt import -P$(2)$$$$patch -p 1 "$$$$patch"; \ quilt import -P$(2)$$$$patch -p 1 "$$$$patch"; \
quilt push -f >/dev/null 2>/dev/null; \ quilt push -f >/dev/null 2>/dev/null; \
rm -f "$$$$patch"; \ rm -f "$$$$patch"; \
); done ); done
endef endef
   
QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y)) QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
ifneq ($(QUILT),) ifneq ($(QUILT),)
STAMP_PREPARED:=$(strip $(STAMP_PREPARED))_q STAMP_PREPARED:=$(strip $(STAMP_PREPARED))_q
STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
override CONFIG_AUTOREBUILD= override CONFIG_AUTOREBUILD=
define Build/Patch/Default define Build/Patch/Default
rm -rf $(PKG_BUILD_DIR)/patches rm -rf $(PKG_BUILD_DIR)/patches
mkdir -p $(PKG_BUILD_DIR)/patches mkdir -p $(PKG_BUILD_DIR)/patches
$(call Quilt/Patch,$(PATCH_DIR),) $(call Quilt/Patch,$(PATCH_DIR),)
@echo @echo
touch $(PKG_BUILD_DIR)/.quilt_used touch $(PKG_BUILD_DIR)/.quilt_used
endef endef
$(STAMP_CONFIGURED): $(STAMP_PATCHED) FORCE $(STAMP_CONFIGURED): $(STAMP_PATCHED) FORCE
prepare: $(STAMP_PATCHED) prepare: $(STAMP_PATCHED)
quilt-check: $(STAMP_PATCHED) quilt-check: $(STAMP_PATCHED)
else else
define Build/Patch/Default define Build/Patch/Default
@if [ -d $(PATCH_DIR) -a "$$$$(ls $(PATCH_DIR) | wc -l)" -gt 0 ]; then \ @if [ -d $(PATCH_DIR) -a "$$$$(ls $(PATCH_DIR) | wc -l)" -gt 0 ]; then \
$(PATCH) $(PKG_BUILD_DIR) $(PATCH_DIR); \ $(PATCH) $(PKG_BUILD_DIR) $(PATCH_DIR); \
fi fi
endef endef
endif endif
   
define Kernel/Patch/Default define Kernel/Patch/Default
if [ -d $(GENERIC_PLATFORM_DIR)/files ]; then $(CP) $(GENERIC_PLATFORM_DIR)/files/* $(LINUX_DIR)/; fi if [ -d $(GENERIC_PLATFORM_DIR)/files ]; then $(CP) $(GENERIC_PLATFORM_DIR)/files/* $(LINUX_DIR)/; fi
if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi
$(if $(strip $(QUILT)),$(call Quilt/Patch,$(GENERIC_PATCH_DIR),generic/), \ $(if $(strip $(QUILT)),$(call Quilt/Patch,$(GENERIC_PATCH_DIR),generic/), \
if [ -d $(GENERIC_PATCH_DIR) ]; then $(PATCH) $(LINUX_DIR) $(GENERIC_PATCH_DIR); fi \ if [ -d $(GENERIC_PATCH_DIR) ]; then $(PATCH) $(LINUX_DIR) $(GENERIC_PATCH_DIR); fi \
) )
$(if $(strip $(QUILT)),$(call Quilt/Patch,$(PATCH_DIR),platform/), \ $(if $(strip $(QUILT)),$(call Quilt/Patch,$(PATCH_DIR),platform/), \
if [ -d $(PATCH_DIR) ]; then $(PATCH) $(LINUX_DIR) $(PATCH_DIR); fi \ if [ -d $(PATCH_DIR) ]; then $(PATCH) $(LINUX_DIR) $(PATCH_DIR); fi \
) )
$(if $(strip $(QUILT)),touch $(PKG_BUILD_DIR)/.quilt_used) $(if $(strip $(QUILT)),touch $(PKG_BUILD_DIR)/.quilt_used)
endef endef
   
$(STAMP_PATCHED): $(STAMP_PREPARED) $(STAMP_PATCHED): $(STAMP_PREPARED)
@cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
(\ (\
cd $(PKG_BUILD_DIR)/patches; \ cd $(PKG_BUILD_DIR)/patches; \
find * -type f \! -name series | sort > series; \ find * -type f \! -name series | sort > series; \
) )
if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi
touch $@ touch $@
   
define Quilt/RefreshDir define Quilt/RefreshDir
mkdir -p $(1) mkdir -p $(1)
-rm -f $(1)/* 2>/dev/null >/dev/null -rm -f $(1)/* 2>/dev/null >/dev/null
@( \ @( \
for patch in $$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$1}'); do \ for patch in $$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$1}'); do \
$(CP) -v "$(PKG_BUILD_DIR)/patches/$$patch" $(1); \ $(CP) -v "$(PKG_BUILD_DIR)/patches/$$patch" $(1); \
done; \ done; \
) )
endef endef
   
define Quilt/Refresh/Package define Quilt/Refresh/Package
$(call Quilt/RefreshDir,$(PATCH_DIR)) $(call Quilt/RefreshDir,$(PATCH_DIR))
endef endef
   
define Quilt/Refresh/Kernel define Quilt/Refresh/Kernel
@[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \ @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
echo "All kernel patches must start with either generic/ or platform/"; \ echo "All kernel patches must start with either generic/ or platform/"; \
false; \ false; \
} }
$(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/) $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
$(call Quilt/RefreshDir,$(PATCH_DIR),platform/) $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
endef endef
   
quilt-check: $(STAMP_PREPARED) FORCE quilt-check: $(STAMP_PREPARED) FORCE
@[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \ @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \ echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
false; \ false; \
} }
@[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \ @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
echo "The source directory contains no quilt patches."; \ echo "The source directory contains no quilt patches."; \
false; \ false; \
} }
@[ "$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \ @[ "$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
echo "The patches are not sorted in the right order. Please fix."; \ echo "The patches are not sorted in the right order. Please fix."; \
false; \ false; \
} }
   
refresh: quilt-check refresh: quilt-check
@cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null
@cd $(PKG_BUILD_DIR); while quilt next 2>/dev/null >/dev/null && quilt push; do \ @cd $(PKG_BUILD_DIR); while quilt next 2>/dev/null >/dev/null && quilt push; do \
quilt refresh; \ quilt refresh; \
done; ! quilt next 2>/dev/null >/dev/null done; ! quilt next 2>/dev/null >/dev/null
$(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package)) $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
update: quilt-check update: quilt-check
$(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package)) $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
   
   
# debug flags: #
  # Copyright (C) 2007 OpenWrt.org
# #
# d: show subdirectory tree # This is free software, licensed under the GNU General Public License v2.
# t: show added targets # See /LICENSE for more information.
# l: show legacy targets #
   
ifeq ($(DEBUG),all)  
build_debug:=dlt  
else  
build_debug:=$(DEBUG)  
endif  
   
define debug  
$$(findstring $(2),$$(if $$(DEBUG_DIR),$$(if $$(filter $$(DEBUG_DIR)%,$(1)),$(build_debug)),$(build_debug)))  
endef  
   
define warn  
$$(if $(call debug,$(1),$(2)),$$(warning $(3)))  
endef  
   
define warn_eval  
$(call warn,$(1),$(2),$(3) $(4))  
$(4)  
endef  
   
SUBTARGETS:=clean download prepare compile install update refresh prereq SUBTARGETS:=clean download prepare compile install update refresh prereq
   
define subtarget define subtarget
$(call warn_eval,$(1),t,T,$(1)/$(2): $($(1)/) $(foreach bd,$(if $($(1)/builddirs-$(2)),$($(1)/builddirs-$(2)),$($(1)/builddirs)),$(1)/$(bd)/$(2))) $(call warn_eval,$(1),t,T,$(1)/$(2): $($(1)/) $(foreach bd,$(if $($(1)/builddirs-$(2)),$(filter-out .,$($(1)/builddirs-$(2))),$($(1)/builddirs)),$(1)/$(bd)/$(2)))
   
endef endef
   
# Parameters: <subdir> # Parameters: <subdir>
define subdir define subdir
$(call warn,$(1),d,D $(1)) $(call warn,$(1),d,D $(1))
$(foreach bd,$($(1)/builddirs), $(foreach bd,$($(1)/builddirs),
$(call warn,$(1),d,BD $(1)/$(bd)) $(call warn,$(1),d,BD $(1)/$(bd))
$(foreach target,$(SUBTARGETS), $(foreach target,$(SUBTARGETS),
$(call warn_eval,$(1)/$(bd),t,T,$(1)/$(bd)/$(target): $($(1)/$(bd)/$(target)) $(call $(1)//$(target),$(1)/$(bd))) $(call warn_eval,$(1)/$(bd),t,T,$(1)/$(bd)/$(target): $($(1)/$(bd)/$(target)) $(call $(1)//$(target),$(1)/$(bd)))
@+$$(MAKE) -j1 -C $(1)/$(bd) $(target) @+$$(MAKE) -j1 -C $(1)/$(bd) $(target)
   
# legacy targets # legacy targets
$(call warn_eval,$(1)/$(bd),l,T,$(1)/$(bd)-$(target): $(1)/$(bd)/$(target)) $(call warn_eval,$(1)/$(bd),l,T,$(1)/$(bd)-$(target): $(1)/$(bd)/$(target))
) )
) )
$(foreach target,$(SUBTARGETS),$(call subtarget,$(1),$(target))) $(foreach target,$(SUBTARGETS),$(call subtarget,$(1),$(target)))
endef endef
   
# Parameters: <subdir> <name> # Parameters: <subdir> <name> <target>
define stampfile define stampfile
$(1)/stamp:=$(STAGING_DIR)/stampfiles/.$(2)_installed $(1)/stamp-$(3):=$(STAGING_DIR)/stampfiles/.$(2)_$(3)
$(call rdep,$(1),$$($(1)/stamp)) $(call rdep,$(1),$$($(1)/stamp-$(3)),)
   
$$($(1)/stamp): $$($(1)/stamp-$(3)):
@+$(MAKE) $(1)/install @+$(MAKE) $(1)/$(3)
@mkdir -p $$$$(dirname $$($(1)/stamp)) @mkdir -p $$$$(dirname $$($(1)/stamp-$(3)))
@touch $$($(1)/stamp) @touch $$($(1)/stamp-$(3))
.PRECIOUS: $$($(1)/stamp) # work around a make bug .PRECIOUS: $$($(1)/stamp-$(3)) # work around a make bug
   
$(1)//clean:=$(1)/stamp/clean $(1)//clean:=$(1)/stamp-$(3)/clean
$(1)/stamp/clean: FORCE $(1)/stamp-$(3)/clean: FORCE
@rm -f $$($(1)/stamp) @rm -f $$($(1)/stamp-$(3))
   
endef endef
   
# Makefile for OpenWrt # Makefile for OpenWrt
# #
# Copyright (C) 2007 OpenWrt.org # Copyright (C) 2007 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.
# #
   
RELEASE:=Kamikaze RELEASE:=Kamikaze
#VERSION:=2.0 # uncomment for final release #VERSION:=2.0 # uncomment for final release
   
all: world  
   
SHELL:=/usr/bin/env bash SHELL:=/usr/bin/env bash
OPENWRTVERSION:=$(RELEASE) OPENWRTVERSION:=$(RELEASE)
  PREP_MK= OPENWRT_BUILD= QUIET=0
include $(TOPDIR)/include/verbose.mk include $(TOPDIR)/include/verbose.mk
ifneq ($(VERSION),) ifneq ($(VERSION),)
OPENWRTVERSION:=$(VERSION) ($(OPENWRTVERSION)) OPENWRTVERSION:=$(VERSION) ($(OPENWRTVERSION))
else else
REV:=$(shell LANG=C svn info | awk '/^Revision:/ { print$$2 }' ) REV:=$(shell LANG=C svn info | awk '/^Revision:/ { print$$2 }' )
ifneq ($(REV),) ifneq ($(REV),)
OPENWRTVERSION:=$(OPENWRTVERSION)/r$(REV) OPENWRTVERSION:=$(OPENWRTVERSION)/r$(REV)
endif endif
endif endif
export OPENWRTVERSION export OPENWRTVERSION
   
ifeq ($(FORCE),) ifeq ($(FORCE),)
.config scripts/config/conf scripts/config/mconf: tmp/.prereq-build .config scripts/config/conf scripts/config/mconf: tmp/.prereq-build
world: prereq  
endif endif
   
SCAN_COOKIE?=$(shell echo $$$$) SCAN_COOKIE?=$(shell echo $$$$)
export SCAN_COOKIE export SCAN_COOKIE
   
tmp/.packageinfo tmp/.targetinfo prepare-tmpinfo: tmp/.packageinfo tmp/.targetinfo prepare-tmpinfo: FORCE
@mkdir -p tmp/info mkdir -p tmp/info
@+$(NO_TRACE_MAKE) -s -f include/scan.mk SCAN_TARGET="packageinfo" SCAN_DIR="package" SCAN_NAME="package" SCAN_DEPS="$(TOPDIR)/include/package*.mk" SCAN_DEPTH=4 SCAN_EXTRA="" +$(NO_TRACE_MAKE) -s -f include/scan.mk SCAN_TARGET="packageinfo" SCAN_DIR="package" SCAN_NAME="package" SCAN_DEPS="$(TOPDIR)/include/package*.mk" SCAN_DEPTH=4 SCAN_EXTRA=""
@+$(NO_TRACE_MAKE) -s -f include/scan.mk SCAN_TARGET="targetinfo" SCAN_DIR="target/linux" SCAN_NAME="target" SCAN_DEPS="profiles/*.mk $(TOPDIR)/include/kernel*.mk" SCAN_DEPTH=2 SCAN_EXTRA="" +$(NO_TRACE_MAKE) -s -f include/scan.mk SCAN_TARGET="targetinfo" SCAN_DIR="target/linux" SCAN_NAME="target" SCAN_DEPS="profiles/*.mk $(TOPDIR)/include/kernel*.mk" SCAN_DEPTH=2 SCAN_EXTRA=""
@for type in package target; do \ for type in package target; do \
f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \ f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
[ "$$t" -nt "$$f" ] || ./scripts/metadata.pl $${type}_config < "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \ [ "$$t" -nt "$$f" ] || ./scripts/metadata.pl $${type}_config < "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
done done
  ./scripts/metadata.pl package_mk < tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
   
.config: ./scripts/config/conf prepare-tmpinfo .config: ./scripts/config/conf prepare-tmpinfo
@+if [ \! -f .config ]; then \ @+if [ \! -f .config ]; then \
[ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig .config; \ [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig .config; \
$(NO_TRACE_MAKE) menuconfig QUIET=0 OPENWRT_BUILD=; \ $(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
fi fi
$< -D .config Config.in &> /dev/null  
   
scripts/config/mconf: scripts/config/mconf:
@+$(MAKE) -C scripts/config all @+$(MAKE) -C scripts/config all
   
scripts/config/conf: scripts/config/conf:
@+$(MAKE) -C scripts/config conf @+$(MAKE) -C scripts/config conf
   
config: scripts/config/conf prepare-tmpinfo FORCE config: scripts/config/conf prepare-tmpinfo FORCE
$< Config.in $< Config.in
   
config-clean: FORCE config-clean: FORCE
$(NO_TRACE_MAKE) -C scripts/config clean $(NO_TRACE_MAKE) -C scripts/config clean
   
defconfig: scripts/config/conf prepare-tmpinfo FORCE defconfig: scripts/config/conf prepare-tmpinfo FORCE
touch .config touch .config
$< -D .config Config.in $< -D .config Config.in
   
oldconfig: scripts/config/conf prepare-tmpinfo FORCE oldconfig: scripts/config/conf prepare-tmpinfo FORCE
$< -o Config.in $< -o Config.in
   
menuconfig: scripts/config/mconf prepare-tmpinfo FORCE menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
if [ \! -f .config -a -e $(HOME)/.openwrt/defconfig ]; then \ if [ \! -f .config -a -e $(HOME)/.openwrt/defconfig ]; then \
cp $(HOME)/.openwrt/defconfig .config; \ cp $(HOME)/.openwrt/defconfig .config; \
fi fi
$< Config.in $< Config.in
   
kernel_oldconfig: .config FORCE kernel_oldconfig: .config FORCE
$(NO_TRACE_MAKE) -C target/linux oldconfig $(NO_TRACE_MAKE) -C target/linux oldconfig
   
kernel_menuconfig: .config FORCE kernel_menuconfig: .config FORCE
$(NO_TRACE_MAKE) -C target/linux menuconfig $(NO_TRACE_MAKE) -C target/linux menuconfig
   
tmp/.prereq-build: include/prereq-build.mk tmp/.prereq-build: include/prereq-build.mk
mkdir -p tmp mkdir -p tmp
rm -f tmp/.host.mk rm -f tmp/.host.mk
@+$(NO_TRACE_MAKE) -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \ @+$(NO_TRACE_MAKE) -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
echo "Prerequisite check failed. Use FORCE=1 to override."; \ echo "Prerequisite check failed. Use FORCE=1 to override."; \
false; \ false; \
} }
touch $@ touch $@
   
tmp/.prereq-package: tmp/.packageinfo .config  
tmp/.prereq-target: tmp/.targetinfo .config  
tmp/.prereq-package tmp/.prereq-target: include/prereq.mk  
mkdir -p tmp  
rm -f tmp/.host.mk  
@+$(NO_TRACE_MAKE) -s -C $(patsubst tmp/.prereq-%,%,$@) prereq 2>/dev/null || { \  
echo "Prerequisite check failed. Use FORCE=1 to override."; \  
false; \  
}  
touch $@  
   
prereq: tmp/.prereq-build tmp/.prereq-package tmp/.prereq-target .config FORCE  
@true  
   
download: .config FORCE download: .config FORCE
$(MAKE) -j1 tools/download $(MAKE) -j1 tools/download
$(MAKE) -j1 toolchain/download $(MAKE) -j1 toolchain/download
$(MAKE) -j1 package/download $(MAKE) -j1 package/download
$(MAKE) -j1 target/download $(MAKE) -j1 target/download
   
clean dirclean distclean: clean dirclean distclean:
@$(MAKE) $@ @$(MAKE) $@
   
  prereq:: .config
  @+$(SUBMAKE) -s tmp/.prereq-build $(PREP_MK)
  @$(NO_TRACE_MAKE) -s $@
   
%:: %::
@$(SUBMAKE) -s prereq QUIET=0 OPENWRT_BUILD= @+$(PREP_MK) $(NO_TRACE_MAKE) -s prereq
@+$(MAKE) $@ @+$(MAKE) $@
   
help: help:
cat README cat README
   
docs docs/compile: FORCE docs docs/compile: FORCE
$(MAKE) -C docs compile $(MAKE) -C docs compile
   
docs/clean: FORCE docs/clean: FORCE
$(MAKE) -C docs clean $(MAKE) -C docs clean
   
symlinkclean: symlinkclean:
-find package -type l | xargs rm -f -find package -type l | xargs rm -f
rm -rf tmp rm -rf tmp
   
.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 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 tmp/.packageinfo tmp/.targetinfo prepare-tmpinfo
  endif
.PHONY: help FORCE .PHONY: help FORCE
.NOTPARALLEL: .NOTPARALLEL:
   
   
# #
# Copyright (C) 2006 OpenWrt.org # Copyright (C) 2006 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.
# #
# $Id:$ # $Id:$
   
ifeq ($(NO_TRACE_MAKE),) ifeq ($(NO_TRACE_MAKE),)
NO_TRACE_MAKE := $(MAKE) V=99 NO_TRACE_MAKE := $(MAKE) V=99
SUBMAKE := $(MAKE) SUBMAKE := $(MAKE)
export NO_TRACE_MAKE export NO_TRACE_MAKE
export SUBMAKE export SUBMAKE
endif endif
   
ifndef KBUILD_VERBOSE ifndef KBUILD_VERBOSE
KBUILD_VERBOSE:=0 KBUILD_VERBOSE:=0
endif endif
ifeq ("$(origin V)", "command line") ifeq ("$(origin V)", "command line")
KBUILD_VERBOSE:=$(V) KBUILD_VERBOSE:=$(V)
endif endif
   
ifeq ($(IS_TTY),1) ifeq ($(IS_TTY),1)
_Y:="\\033[33m" # yellow _Y:="\\033[33m" # yellow
_N:="\\033[m" #normal _N:="\\033[m" #normal
endif endif
   
define MESSAGE define MESSAGE
/bin/echo -e "$(_Y)$(1)$(_N)" >&3 /bin/echo -e "$(_Y)$(1)$(_N)" >&3
endef endef
   
ifneq ($(KBUILD_VERBOSE),99) ifneq ($(KBUILD_VERBOSE),99)
ifeq ($(QUIET),1) ifeq ($(QUIET),1)
ifneq ($(CURDIR),$(TOPDIR)) ifneq ($(CURDIR),$(TOPDIR))
_DIR:=$(patsubst $(TOPDIR)/%,%,${CURDIR}) _DIR:=$(patsubst $(TOPDIR)/%,%,${CURDIR})
else else
_DIR:= _DIR:=
endif endif
_NULL:=$(if $(MAKECMDGOALS),$(shell \ _NULL:=$(if $(MAKECMDGOALS),$(shell \
$(call MESSAGE, "make[$(MAKELEVEL)]$(if $(_DIR), -C $(_DIR)) $(MAKECMDGOALS)"); \ $(call MESSAGE, "make[$(MAKELEVEL)]$(if $(_DIR), -C $(_DIR)) $(MAKECMDGOALS)"); \
)) ))
else else
ifeq ($(KBUILD_VERBOSE),0) ifeq ($(KBUILD_VERBOSE),0)
MAKE:=&>/dev/null $(MAKE) MAKE:=&>/dev/null $(MAKE)
endif endif
export QUIET:=1 export QUIET:=1
MAKE:=cmd() { $(MAKE) $$* || { echo "make $$*: build failed. Please re-run make with V=99 to see what's going on"; false; } } 3>&1 4>&2; cmd MAKE:=cmd() { $(MAKE) -s $$* || { echo "make $$*: build failed. Please re-run make with V=99 to see what's going on"; false; } } 3>&1 4>&2; cmd
endif endif
   
.SILENT: $(MAKECMDGOALS) .SILENT: $(MAKECMDGOALS)
endif endif
   
# #
# Copyright (C) 2006 OpenWrt.org # Copyright (C) 2006 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.
# #
# $Id$ # $Id$
   
include $(TOPDIR)/rules.mk curdir:=package
include $(TOPDIR)/.config  
include $(INCLUDE_DIR)/host.mk  
   
all: compile include .config
  -include $(TMP_DIR)/.packagedeps
  $(curdir)/builddirs:=$(sort $(package-) $(package-y) $(package-m))
  $(curdir)/builddirs-compile:=$(sort $(package-y) $(package-m))
  $(curdir)/builddirs-install:=. $(sort $(package-y))
  $(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m))
   
include $(TMP_DIR)/.packagedeps $(curdir)//compile:=.config prereq
  $(curdir)/install:=$(curdir)/install-cleanup
PREREQ_PACKAGES:=$(patsubst %,%-prereq,$(prereq-y) $(prereq-m)) $(curdir)/install-cleanup:
DOWNLOAD_PACKAGES:=$(patsubst %,%-download,$(package-y) $(package-m))  
COMPILE_PACKAGES:=$(patsubst %,%-compile,$(package-y) $(package-m))  
INSTALL_PACKAGES:=$(patsubst %,%-install,$(package-y))  
   
$(STAMP_DIR) $(TARGET_DIR):  
mkdir -p $@  
   
ifeq ($(QUIET),1)  
%-compile %-install: FORCE  
$(MAKE) -j1 -C $* $(patsubst $*-%,%,$@) || { $(call MESSAGE, "*** $* $(patsubst $*-%,%,$@) failed"); false; }  
   
%-prepare %-prereq %-download %-clean: FORCE  
else  
%-prepare %-prereq %-download %-clean %-compile %-install: FORCE  
endif  
$(MAKE) -j1 -C $* $(patsubst $*-%,%,$@)  
   
%-refresh %-update:  
-$(MAKE) -C $* $(patsubst $*-%,%,$@)  
   
%-autorefresh:  
-$(MAKE) -C $* clean refresh QUILT=1  
   
   
# .IGNORE: $(COMPILE_PACKAGES)  
   
$(TMP_DIR)/.packagedeps: $(TMP_DIR)/.packageinfo  
@$(TOPDIR)/scripts/metadata.pl package_mk < $< > $@ || rm -f $@  
   
preconfig:  
clean: $(patsubst %,%-clean,$(package-) $(package-y) $(package-m))  
prereq: $(PREREQ_PACKAGES)  
download: $(DOWNLOAD_PACKAGES)  
compile: $(COMPILE_PACKAGES)  
refresh: $(patsubst %,%-autorefresh,$(package-y) $(package-m) $(package-))  
   
install-targets: $(INSTALL_PACKAGES)  
install:  
rm -rf $(BUILD_DIR)/root rm -rf $(BUILD_DIR)/root
$(MAKE) install-targets $(MAKE) install-targets
$(MAKE) preconfig $(MAKE) preconfig
@if [ -d $(TOPDIR)/files ]; then \ @if [ -d $(TOPDIR)/files ]; then \
$(CP) $(TOPDIR)/files/. $(BUILD_DIR)/root; \ $(CP) $(TOPDIR)/files/. $(BUILD_DIR)/root; \
fi fi
@mkdir -p $(BUILD_DIR)/root/etc/rc.d @mkdir -p $(BUILD_DIR)/root/etc/rc.d
@( \ @( \
cd $(BUILD_DIR)/root; \ cd $(BUILD_DIR)/root; \
for script in ./etc/init.d/*; do \ for script in ./etc/init.d/*; do \
grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \ grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$script enable; \ IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$script enable; \
done || true \ done || true \
) )
@-find $(BUILD_DIR)/root -name CVS | $(XARGS) rm -rf @-find $(BUILD_DIR)/root -name CVS | $(XARGS) rm -rf
@-find $(BUILD_DIR)/root -name .svn | $(XARGS) rm -rf @-find $(BUILD_DIR)/root -name .svn | $(XARGS) rm -rf
@-find $(BUILD_DIR)/root -name '.#*' | $(XARGS) rm -f @-find $(BUILD_DIR)/root -name '.#*' | $(XARGS) rm -f
   
index: $(PACKAGE_DIR)/Packages $(curdir)/index: FORCE
   
$(PACKAGE_DIR)/Packages: $(PACKAGE_DIR)/*.ipk  
(cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages) (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages)
   
symlinks: $(eval $(call stampfile,$(curdir),package,prereq))
../scripts/feeds.sh $(CONFIG_SOURCE_FEEDS) $(CONFIG_SOURCE_FEEDS_REV) $(eval $(call subdir,$(curdir)))
   
ifeq ($(MAKECMDGOALS),compile)  
MAKEFLAGS:=$(MAKEFLAGS) -j$(CONFIG_JLEVEL)  
else  
.NOTPARALLEL:  
endif  
   
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
my %preconfig; my %preconfig;
my %package; my %package;
my %srcpackage; my %srcpackage;
my %category; my %category;
my %subdir; my %subdir;
   
sub get_multiline { sub get_multiline {
my $prefix = shift; my $prefix = shift;
my $str; my $str;
while (<>) { while (<>) {
last if /^@@/; last if /^@@/;
s/^\s*//g; s/^\s*//g;
$str .= (($_ and $prefix) ? $prefix . $_ : $_); $str .= (($_ and $prefix) ? $prefix . $_ : $_);
} }
   
return $str; return $str;
} }
   
sub parse_target_metadata() { sub parse_target_metadata() {
my ($target, @target, $profile); my ($target, @target, $profile);
while (<>) { while (<>) {
chomp; chomp;
/^Target:\s*((.+)-(\d+\.\d+))\s*$/ and do { /^Target:\s*((.+)-(\d+\.\d+))\s*$/ and do {
my $conf = uc $3.'_'.$2; my $conf = uc $3.'_'.$2;
$conf =~ tr/\.-/__/; $conf =~ tr/\.-/__/;
$target = { $target = {
id => $1, id => $1,
conf => $conf, conf => $conf,
board => $2, board => $2,
kernel => $3, kernel => $3,
profiles => [] profiles => []
}; };
push @target, $target; push @target, $target;
}; };
/^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1; /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
/^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1; /^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1;
/^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1; /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
/^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ]; /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
/^Target-Description:/ and $target->{desc} = get_multiline(); /^Target-Description:/ and $target->{desc} = get_multiline();
/^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1; /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
/^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1; /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
/^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1; /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
/^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ]; /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
/^Target-Profile:\s*(.+)\s*$/ and do { /^Target-Profile:\s*(.+)\s*$/ and do {
$profile = { $profile = {
id => $1, id => $1,
name => $1, name => $1,
packages => [] packages => []
}; };
push @{$target->{profiles}}, $profile; push @{$target->{profiles}}, $profile;
}; };
/^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1; /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
/^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ]; /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
/^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(); /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline();
/^Target-Profile-Config:/ and $profile->{config} = get_multiline("\t"); /^Target-Profile-Config:/ and $profile->{config} = get_multiline("\t");
/^Target-Profile-Kconfig:/ and $profile->{kconfig} = 1; /^Target-Profile-Kconfig:/ and $profile->{kconfig} = 1;
} }
foreach my $target (@target) { foreach my $target (@target) {
@{$target->{profiles}} > 0 or $target->{profiles} = [ @{$target->{profiles}} > 0 or $target->{profiles} = [
{ {
id => 'Default', id => 'Default',
name => 'Default', name => 'Default',
packages => [] packages => []
} }
]; ];
} }
return @target; return @target;
} }
   
sub parse_package_metadata() { sub parse_package_metadata() {
my $pkg; my $pkg;
my $makefile; my $makefile;
my $preconfig; my $preconfig;
my $subdir; my $subdir;
my $src; my $src;
while (<>) { while (<>) {
chomp; chomp;
/^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do { /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
$makefile = $1; $makefile = $1;
$subdir = $2; $subdir = $2;
$src = $3; $src = $3;
$subdir =~ s/^package\///; $subdir =~ s/^package\///;
$subdir{$src} = $subdir; $subdir{$src} = $subdir;
$srcpackage{$src} = []; $srcpackage{$src} = [];
undef $pkg; undef $pkg;
}; };
/^Package:\s*(.+?)\s*$/ and do { /^Package:\s*(.+?)\s*$/ and do {
$pkg = {}; $pkg = {};
$pkg->{src} = $src; $pkg->{src} = $src;
$pkg->{makefile} = $makefile; $pkg->{makefile} = $makefile;
$pkg->{name} = $1; $pkg->{name} = $1;
$pkg->{default} = "m if ALL"; $pkg->{default} = "m if ALL";
$pkg->{depends} = []; $pkg->{depends} = [];
$pkg->{builddepends} = []; $pkg->{builddepends} = [];
$pkg->{subdir} = $subdir; $pkg->{subdir} = $subdir;
$package{$1} = $pkg; $package{$1} = $pkg;
push @{$srcpackage{$src}}, $pkg; push @{$srcpackage{$src}}, $pkg;
}; };
/^Version: \s*(.+)\s*$/ and $pkg->{version} = $1; /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
/^Title: \s*(.+)\s*$/ and $pkg->{title} = $1; /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
/^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1; /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
/^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1; /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
/^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1; /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
/^Default: \s*(.+)\s*$/ and $pkg->{default} = $1; /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
/^Provides: \s*(.+)\s*$/ and do { /^Provides: \s*(.+)\s*$/ and do {
my @vpkg = split /\s+/, $1; my @vpkg = split /\s+/, $1;
foreach my $vpkg (@vpkg) { foreach my $vpkg (@vpkg) {
$package{$vpkg} or $package{$vpkg} = { vdepends => [] }; $package{$vpkg} or $package{$vpkg} = { vdepends => [] };
push @{$package{$vpkg}->{vdepends}}, $pkg->{name}; push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
} }
}; };
/^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ]; /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
/^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ]; /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
/^Category: \s*(.+)\s*$/ and do { /^Category: \s*(.+)\s*$/ and do {
$pkg->{category} = $1; $pkg->{category} = $1;
defined $category{$1} or $category{$1} = {}; defined $category{$1} or $category{$1} = {};
defined $category{$1}->{$src} or $category{$1}->{$src} = []; defined $category{$1}->{$src} or $category{$1}->{$src} = [];
push @{$category{$1}->{$src}}, $pkg; push @{$category{$1}->{$src}}, $pkg;
}; };
/^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline("\t\t "); /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline("\t\t ");
/^Config: \s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(); /^Config: \s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline();
/^Prereq-Check:/ and $pkg->{prereq} = 1; /^Prereq-Check:/ and $pkg->{prereq} = 1;
/^Preconfig:\s*(.+)\s*$/ and do { /^Preconfig:\s*(.+)\s*$/ and do {
my $pkgname = $pkg->{name}; my $pkgname = $pkg->{name};
$preconfig{$pkgname} or $preconfig{$pkgname} = []; $preconfig{$pkgname} or $preconfig{$pkgname} = [];
$preconfig = { $preconfig = {
id => $1 id => $1
}; };
push @{$preconfig{$pkgname}}, $preconfig; push @{$preconfig{$pkgname}}, $preconfig;
}; };
/^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1; /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
/^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1; /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
/^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1; /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
} }
return %category; return %category;
} }
   
sub gen_kconfig_overrides() { sub gen_kconfig_overrides() {
my %config; my %config;
my %kconfig; my %kconfig;
my $package; my $package;
my $pkginfo = shift @ARGV; my $pkginfo = shift @ARGV;
my $cfgfile = shift @ARGV; my $cfgfile = shift @ARGV;
   
# parameter 2: build system config # parameter 2: build system config
open FILE, "<$cfgfile" or return; open FILE, "<$cfgfile" or return;
while (<FILE>) { while (<FILE>) {
/^(CONFIG_.+?)=(.+)$/ and $config{$1} = 1; /^(CONFIG_.+?)=(.+)$/ and $config{$1} = 1;
} }
close FILE; close FILE;
   
# parameter 1: package metadata # parameter 1: package metadata
open FILE, "<$pkginfo" or return; open FILE, "<$pkginfo" or return;
while (<FILE>) { while (<FILE>) {
/^Package:\s*(.+?)\s*$/ and $package = $1; /^Package:\s*(.+?)\s*$/ and $package = $1;
/^Kernel-Config:\s*(.+?)\s*$/ and do { /^Kernel-Config:\s*(.+?)\s*$/ and do {
my @config = split /\s+/, $1; my @config = split /\s+/, $1;
foreach my $config (@config) { foreach my $config (@config) {
my $val = 'm'; my $val = 'm';
my $override; my $override;
if ($config =~ /^(.+?)=(.+)$/) { if ($config =~ /^(.+?)=(.+)$/) {
$config = $1; $config = $1;
$override = 1; $override = 1;
$val = $2; $val = $2;
} }
if ($config{"CONFIG_PACKAGE_$package"} and ($config ne 'n')) { if ($config{"CONFIG_PACKAGE_$package"} and ($config ne 'n')) {
$kconfig{$config} = $val; $kconfig{$config} = $val;
} elsif (!$override) { } elsif (!$override) {
$kconfig{$config} or $kconfig{$config} = 'n'; $kconfig{$config} or $kconfig{$config} = 'n';
} }
} }
}; };
}; };
close FILE; close FILE;
   
foreach my $kconfig (sort keys %kconfig) { foreach my $kconfig (sort keys %kconfig) {
if ($kconfig{$kconfig} eq 'n') { if ($kconfig{$kconfig} eq 'n') {
print "# $kconfig is not set\n"; print "# $kconfig is not set\n";
} else { } else {
print "$kconfig=$kconfig{$kconfig}\n"; print "$kconfig=$kconfig{$kconfig}\n";
} }
} }
} }
   
sub merge_package_lists($$) { sub merge_package_lists($$) {
my $list1 = shift; my $list1 = shift;
my $list2 = shift; my $list2 = shift;
my @l = (); my @l = ();
my %pkgs; my %pkgs;
   
foreach my $pkg (@$list1, @$list2) { foreach my $pkg (@$list1, @$list2) {
$pkgs{$pkg} = 1; $pkgs{$pkg} = 1;
} }
foreach my $pkg (keys %pkgs) { foreach my $pkg (keys %pkgs) {
push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"}); push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
} }
return sort(@l); return sort(@l);
} }
   
sub gen_target_mk() { sub gen_target_mk() {
my @target = parse_target_metadata(); my @target = parse_target_metadata();
@target = sort { @target = sort {
$a->{id} cmp $b->{id} $a->{id} cmp $b->{id}
} @target; } @target;
foreach my $target (@target) { foreach my $target (@target) {
my ($profiles_def, $profiles_eval); my ($profiles_def, $profiles_eval);
my $conf = uc $target->{kernel}.'_'.$target->{board}; my $conf = uc $target->{kernel}.'_'.$target->{board};
$conf =~ tr/\.-/__/; $conf =~ tr/\.-/__/;
foreach my $profile (@{$target->{profiles}}) { foreach my $profile (@{$target->{profiles}}) {
$profiles_def .= " $profiles_def .= "
define Profile/$conf\_$profile->{id} define Profile/$conf\_$profile->{id}
ID:=$profile->{id} ID:=$profile->{id}
NAME:=$profile->{name} NAME:=$profile->{name}
PACKAGES:=".join(" ", merge_package_lists($target->{packages}, $profile->{packages}))."\n"; PACKAGES:=".join(" ", merge_package_lists($target->{packages}, $profile->{packages}))."\n";
$profile->{kconfig} and $profiles_def .= " KCONFIG:=1\n"; $profile->{kconfig} and $profiles_def .= " KCONFIG:=1\n";
$profiles_def .= " endef"; $profiles_def .= " endef";
$profiles_eval .= " $profiles_eval .= "
\$(eval \$(call AddProfile,$conf\_$profile->{id}))" \$(eval \$(call AddProfile,$conf\_$profile->{id}))"
} }
print " print "
ifeq (\$(CONFIG_LINUX_$conf),y) ifeq (\$(CONFIG_LINUX_$conf),y)
define Target define Target
KERNEL:=$target->{kernel} KERNEL:=$target->{kernel}
BOARD:=$target->{board} BOARD:=$target->{board}
BOARDNAME:=$target->{name} BOARDNAME:=$target->{name}
LINUX_VERSION:=$target->{version} LINUX_VERSION:=$target->{version}
LINUX_RELEASE:=$target->{release} LINUX_RELEASE:=$target->{release}
LINUX_KARCH:=$target->{karch} LINUX_KARCH:=$target->{karch}
DEFAULT_PACKAGES:=".join(" ", @{$target->{packages}})." DEFAULT_PACKAGES:=".join(" ", @{$target->{packages}})."
endef$profiles_def endef$profiles_def
endif$profiles_eval endif$profiles_eval
   
" "
} }
print "\$(eval \$(call Target))\n"; print "\$(eval \$(call Target))\n";
} }
   
sub target_config_features(@) { sub target_config_features(@) {
my $ret; my $ret;
   
while ($_ = shift @_) { while ($_ = shift @_) {
/broken/ and $ret .= "\tdepends BROKEN\n"; /broken/ and $ret .= "\tdepends BROKEN\n";
/pci/ and $ret .= "\tselect PCI_SUPPORT\n"; /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
/usb/ and $ret .= "\tselect USB_SUPPORT\n"; /usb/ and $ret .= "\tselect USB_SUPPORT\n";
/pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n"; /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
/squashfs/ and $ret .= "\tselect USES_SQUASHFS\n"; /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
/jffs2/ and $ret .= "\tselect USES_JFFS2\n"; /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
/ext2/ and $ret .= "\tselect USES_EXT2\n"; /ext2/ and $ret .= "\tselect USES_EXT2\n";
/tgz/ and $ret .= "\tselect USES_TGZ\n"; /tgz/ and $ret .= "\tselect USES_TGZ\n";
} }
return $ret; return $ret;
} }
   
   
sub gen_target_config() { sub gen_target_config() {
my @target = parse_target_metadata(); my @target = parse_target_metadata();
   
@target = sort { @target = sort {
$a->{name} cmp $b->{name} $a->{name} cmp $b->{name}
} @target; } @target;
print <<EOF; print <<EOF;
choice choice
prompt "Target System" prompt "Target System"
default LINUX_2_4_BRCM default LINUX_2_4_BRCM
reset if !DEVEL reset if !DEVEL
EOF EOF
   
foreach my $target (@target) { foreach my $target (@target) {
my $features = target_config_features(@{$target->{features}}); my $features = target_config_features(@{$target->{features}});
my $help = $target->{desc}; my $help = $target->{desc};
my $kernel = $target->{kernel}; my $kernel = $target->{kernel};
$kernel =~ tr/./_/; $kernel =~ tr/./_/;
   
chomp $features; chomp $features;
$features .= "\n"; $features .= "\n";
if ($help =~ /\w+/) { if ($help =~ /\w+/) {
$help =~ s/^\s*/\t /mg; $help =~ s/^\s*/\t /mg;
$help = "\thelp\n$help"; $help = "\thelp\n$help";
} else { } else {
undef $help; undef $help;
} }
print <<EOF print <<EOF
config LINUX_$target->{conf} config LINUX_$target->{conf}
bool "$target->{name}" bool "$target->{name}"
select $target->{arch} select $target->{arch}
select LINUX_$kernel select LINUX_$kernel
$features$help $features$help
   
EOF EOF
} }
   
print <<EOF; print <<EOF;
if DEVEL if DEVEL
   
config LINUX_2_6_ARM config LINUX_2_6_ARM
bool "UNSUPPORTED little-endian arm platform" bool "UNSUPPORTED little-endian arm platform"
depends BROKEN depends BROKEN
select LINUX_2_6 select LINUX_2_6
select arm select arm
   
config LINUX_2_6_CRIS config LINUX_2_6_CRIS
bool "UNSUPPORTED cris platform" bool "UNSUPPORTED cris platform"
depends BROKEN depends BROKEN
select LINUX_2_6 select LINUX_2_6
select cris select cris
   
config LINUX_2_6_M68K config LINUX_2_6_M68K
bool "UNSUPPORTED m68k platform" bool "UNSUPPORTED m68k platform"
depends BROKEN depends BROKEN
select LINUX_2_6 select LINUX_2_6
select m68k select m68k
   
config LINUX_2_6_SH3 config LINUX_2_6_SH3
bool "UNSUPPORTED little-endian sh3 platform" bool "UNSUPPORTED little-endian sh3 platform"
depends BROKEN depends BROKEN
select LINUX_2_6 select LINUX_2_6
select sh3 select sh3
   
config LINUX_2_6_SH3EB config LINUX_2_6_SH3EB
bool "UNSUPPORTED big-endian sh3 platform" bool "UNSUPPORTED big-endian sh3 platform"
depends BROKEN depends BROKEN
select LINUX_2_6 select LINUX_2_6
select sh3eb select sh3eb
   
config LINUX_2_6_SH4 config LINUX_2_6_SH4
bool "UNSUPPORTED little-endian sh4 platform" bool "UNSUPPORTED little-endian sh4 platform"
depends BROKEN depends BROKEN
select LINUX_2_6 select LINUX_2_6
select sh4 select sh4
   
config LINUX_2_6_SH4EB config LINUX_2_6_SH4EB
bool "UNSUPPORTED big-endian sh4 platform" bool "UNSUPPORTED big-endian sh4 platform"
depends BROKEN depends BROKEN
select LINUX_2_6 select LINUX_2_6
select sh4eb select sh4eb
   
config LINUX_2_6_SPARC config LINUX_2_6_SPARC
bool "UNSUPPORTED sparc platform" bool "UNSUPPORTED sparc platform"
depends BROKEN depends BROKEN
select LINUX_2_6 select LINUX_2_6
select sparc select sparc
   
endif endif
   
endchoice endchoice
   
choice choice
prompt "Target Profile" prompt "Target Profile"
   
EOF EOF
foreach my $target (@target) { foreach my $target (@target) {
my $profiles = $target->{profiles}; my $profiles = $target->{profiles};
foreach my $profile (@$profiles) { foreach my $profile (@$profiles) {
print <<EOF; print <<EOF;
config LINUX_$target->{conf}_$profile->{id} config LINUX_$target->{conf}_$profile->{id}
bool "$profile->{name}" bool "$profile->{name}"
depends LINUX_$target->{conf} depends LINUX_$target->{conf}
$profile->{config} $profile->{config}
EOF EOF
$profile->{kconfig} and print "\tselect PROFILE_KCONFIG\n"; $profile->{kconfig} and print "\tselect PROFILE_KCONFIG\n";
my @pkglist = merge_package_lists($target->{packages}, $profile->{packages}); my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
foreach my $pkg (@pkglist) { foreach my $pkg (@pkglist) {
print "\tselect DEFAULT_$pkg\n"; print "\tselect DEFAULT_$pkg\n";
} }
print "\n"; print "\n";
} }
} }
   
print "endchoice\n"; print "endchoice\n";
} }
   
   
sub find_package_dep($$) { sub find_package_dep($$) {
my $pkg = shift; my $pkg = shift;
my $name = shift; my $name = shift;
my $deps = ($pkg->{vdepends} or $pkg->{depends}); my $deps = ($pkg->{vdepends} or $pkg->{depends});
   
return 0 unless defined $deps; return 0 unless defined $deps;
foreach my $dep (@{$deps}) { foreach my $dep (@{$deps}) {
return 1 if $dep eq $name; return 1 if $dep eq $name;
return 1 if ($package{$dep} and (find_package_dep($package{$dep},$name) == 1)); return 1 if ($package{$dep} and (find_package_dep($package{$dep},$name) == 1));
} }
return 0; return 0;
} }
   
sub package_depends($$) { sub package_depends($$) {
my $a = shift; my $a = shift;
my $b = shift; my $b = shift;
my $ret; my $ret;
   
return 0 if ($a->{submenu} ne $b->{submenu}); return 0 if ($a->{submenu} ne $b->{submenu});
if (find_package_dep($a, $b->{name}) == 1) { if (find_package_dep($a, $b->{name}) == 1) {
$ret = 1; $ret = 1;
} elsif (find_package_dep($b, $a->{name}) == 1) { } elsif (find_package_dep($b, $a->{name}) == 1) {
$ret = -1; $ret = -1;
} else { } else {
return 0; return 0;
} }
return $ret; return $ret;
} }
   
sub mconf_depends($$) { sub mconf_depends($$) {
my $depends = shift; my $depends = shift;
my $only_dep = shift; my $only_dep = shift;
my $res; my $res;
   
$depends or return; $depends or return;
my @depends = @$depends; my @depends = @$depends;
foreach my $depend (@depends) { foreach my $depend (@depends) {
my $m = "depends"; my $m = "depends";
$depend =~ s/^([@\+]+)//; $depend =~ s/^([@\+]+)//;
my $flags = $1; my $flags = $1;
my $vdep; my $vdep;
if ($vdep = $package{$depend}->{vdepends}) { if ($vdep = $package{$depend}->{vdepends}) {
$depend = join("||", map { "PACKAGE_".$_ } @$vdep); $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
} else { } else {
$flags =~ /\+/ and do { $flags =~ /\+/ and do {
next if $only_dep; next if $only_dep;
$m = "select"; $m = "select";
   
# Menuconfig will not treat 'select FOO' as a real dependency # Menuconfig will not treat 'select FOO' as a real dependency
# thus if FOO depends on other config options, these dependencies # thus if FOO depends on other config options, these dependencies
# will not be checked. To fix this, we simply emit all of FOO's # will not be checked. To fix this, we simply emit all of FOO's
# depends here as well. # depends here as well.
$package{$depend} and $res .= mconf_depends($package{$depend}->{depends}, 1); $package{$depend} and $res .= mconf_depends($package{$depend}->{depends}, 1);
}; };
$flags =~ /@/ or $depend = "PACKAGE_$depend"; $flags =~ /@/ or $depend = "PACKAGE_$depend";
} }
$res .= "\t\t$m $depend\n"; $res .= "\t\t$m $depend\n";
} }
return $res; return $res;
} }
   
sub print_package_config_category($) { sub print_package_config_category($) {
my $cat = shift; my $cat = shift;
my %menus; my %menus;
my %menu_dep; my %menu_dep;
return unless $category{$cat}; return unless $category{$cat};
print "menu \"$cat\"\n\n"; print "menu \"$cat\"\n\n";
my %spkg = %{$category{$cat}}; my %spkg = %{$category{$cat}};
foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) { foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
foreach my $pkg (@{$spkg{$spkg}}) { foreach my $pkg (@{$spkg{$spkg}}) {
my $menu = $pkg->{submenu}; my $menu = $pkg->{submenu};
if ($menu) { if ($menu) {
$menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep}; $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
} else { } else {
$menu = 'undef'; $menu = 'undef';
} }
$menus{$menu} or $menus{$menu} = []; $menus{$menu} or $menus{$menu} = [];
push @{$menus{$menu}}, $pkg; push @{$menus{$menu}}, $pkg;
print "\tconfig DEFAULT_".$pkg->{name}."\n"; print "\tconfig DEFAULT_".$pkg->{name}."\n";
print "\t\tbool\n\n"; print "\t\tbool\n\n";
} }
} }
my @menus = sort { my @menus = sort {
($a eq 'undef' ? 1 : 0) or ($a eq 'undef' ? 1 : 0) or
($b eq 'undef' ? -1 : 0) or ($b eq 'undef' ? -1 : 0) or
($a cmp $b) ($a cmp $b)
} keys %menus; } keys %menus;
   
foreach my $menu (@menus) { foreach my $menu (@menus) {
my @pkgs = sort { my @pkgs = sort {
package_depends($a, $b) or package_depends($a, $b) or
($a->{name} cmp $b->{name}) ($a->{name} cmp $b->{name})
} @{$menus{$menu}}; } @{$menus{$menu}};
if ($menu ne 'undef') { if ($menu ne 'undef') {
$menu_dep{$menu} and print "if $menu_dep{$menu}\n"; $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
print "menu \"$menu\"\n"; print "menu \"$menu\"\n";
} }
foreach my $pkg (@pkgs) { foreach my $pkg (@pkgs) {
my $title = $pkg->{name}; my $title = $pkg->{name};
my $c = (72 - length($pkg->{name}) - length($pkg->{title})); my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
if ($c > 0) { if ($c > 0) {
$title .= ("." x $c). " ". $pkg->{title}; $title .= ("." x $c). " ". $pkg->{title};
} }
print "\t"; print "\t";
$pkg->{menu} and print "menu"; $pkg->{menu} and print "menu";
print "config PACKAGE_".$pkg->{name}."\n"; print "config PACKAGE_".$pkg->{name}."\n";
print "\t\ttristate \"$title\"\n"; print "\t\ttristate \"$title\"\n";
print "\t\tdefault y if DEFAULT_".$pkg->{name}."\n"; print "\t\tdefault y if DEFAULT_".$pkg->{name}."\n";
foreach my $default (split /\s*,\s*/, $pkg->{default}) { foreach my $default (split /\s*,\s*/, $pkg->{default}) {
print "\t\tdefault $default\n"; print "\t\tdefault $default\n";
} }
print mconf_depends($pkg->{depends}, 0); print mconf_depends($pkg->{depends}, 0);
print "\t\thelp\n"; print "\t\thelp\n";
print $pkg->{description}; print $pkg->{description};
print "\n"; print "\n";
   
$pkg->{config} and print $pkg->{config}."\n"; $pkg->{config} and print $pkg->{config}."\n";
} }
if ($menu ne 'undef') { if ($menu ne 'undef') {
print "endmenu\n"; print "endmenu\n";
$menu_dep{$menu} and print "endif\n"; $menu_dep{$menu} and print "endif\n";
} }
} }
print "endmenu\n\n"; print "endmenu\n\n";
undef $category{$cat}; undef $category{$cat};
} }
   
sub gen_package_config() { sub gen_package_config() {
parse_package_metadata(); parse_package_metadata();
print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n"; print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
foreach my $preconfig (keys %preconfig) { foreach my $preconfig (keys %preconfig) {
foreach my $cfg (@{$preconfig{$preconfig}}) { foreach my $cfg (@{$preconfig{$preconfig}}) {
my $conf = $cfg->{id}; my $conf = $cfg->{id};
$conf =~ tr/\.-/__/; $conf =~ tr/\.-/__/;
print <<EOF print <<EOF
config UCI_PRECONFIG_$conf config UCI_PRECONFIG_$conf
string "$cfg->{label}" if UCI_PRECONFIG string "$cfg->{label}" if UCI_PRECONFIG
depends PACKAGE_$preconfig depends PACKAGE_$preconfig
default "$cfg->{default}" default "$cfg->{default}"
   
EOF EOF
} }
} }
print_package_config_category 'Base system'; print_package_config_category 'Base system';
foreach my $cat (keys %category) { foreach my $cat (keys %category) {
print_package_config_category $cat; print_package_config_category $cat;
} }
} }
   
sub gen_package_mk() { sub gen_package_mk() {
my %conf; my %conf;
my %dep; my %dep;
my $line; my $line;
   
parse_package_metadata(); parse_package_metadata();
foreach my $name (sort {uc($a) cmp uc($b)} keys %package) { foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
my $config; my $config;
my $pkg = $package{$name}; my $pkg = $package{$name};
next if defined $pkg->{vdepends}; next if defined $pkg->{vdepends};
if ($ENV{SDK}) { if ($ENV{SDK}) {
$conf{$pkg->{src}} or do { $conf{$pkg->{src}} or do {
$config = 'm'; $config = 'm';
$conf{$pkg->{src}} = 1; $conf{$pkg->{src}} = 1;
}; };
} else { } else {
$config = "\$(CONFIG_PACKAGE_$name)" $config = "\$(CONFIG_PACKAGE_$name)"
} }
if ($config) { if ($config) {
print "package-$config += $pkg->{subdir}$pkg->{src}\n"; print "package-$config += $pkg->{subdir}$pkg->{src}\n";
$pkg->{prereq} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n"; $pkg->{prereq} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
} }
my $hasdeps = 0; my $hasdeps = 0;
my $depline = ""; my $depline = "";
foreach my $dep (@{$pkg->{depends}}, @{$pkg->{builddepends}}) { foreach my $dep (@{$pkg->{depends}}, @{$pkg->{builddepends}}) {
next if $dep =~ /@/; next if $dep =~ /@/;
$dep =~ s/\+//; $dep =~ s/\+//;
my $idx; my $idx;
my $pkg_dep = $package{$dep}; my $pkg_dep = $package{$dep};
next if defined $pkg_dep->{vdepends}; next if defined $pkg_dep->{vdepends};
   
if (defined $pkg_dep->{src}) { if (defined $pkg_dep->{src}) {
($pkg->{src} ne $pkg_dep->{src}) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src}; ($pkg->{src} ne $pkg_dep->{src}) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
} elsif (defined($srcpackage{$dep})) { } elsif (defined($srcpackage{$dep})) {
$idx = $subdir{$dep}.$dep; $idx = $subdir{$dep}.$dep;
} }
undef $idx if $idx =~ /^(kernel)|(base-files)$/; undef $idx if $idx =~ /^(kernel)|(base-files)$/;
if ($idx) { if ($idx) {
next if $dep{$pkg->{src}."->".$idx}; next if $dep{$pkg->{src}."->".$idx};
$depline .= " $idx\-compile"; $depline .= " \$(curdir)/$idx/compile";
$dep{$pkg->{src}."->".$idx} = 1; $dep{$pkg->{src}."->".$idx} = 1;
} }
} }
if ($depline) { if ($depline) {
$line .= $pkg->{subdir}."$pkg->{src}-compile: $depline\n"; $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/compile := $depline\n";
} }
} }
if ($line ne "") { if ($line ne "") {
print "\n$line"; print "\n$line";
} }
foreach my $preconfig (keys %preconfig) { foreach my $preconfig (keys %preconfig) {
my $cmds; my $cmds;
foreach my $cfg (@{$preconfig{$preconfig}}) { foreach my $cfg (@{$preconfig{$preconfig}}) {
my $conf = $cfg->{id}; my $conf = $cfg->{id};
$conf =~ tr/\.-/__/; $conf =~ tr/\.-/__/;
$cmds .= "\techo \"uci set '$cfg->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n"; $cmds .= "\techo \"uci set '$cfg->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
} }
next unless $cmds; next unless $cmds;
print <<EOF print <<EOF
   
\$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
( \\ ( \\
$cmds \\ $cmds \\
) > \$@ ) > \$@
ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),) ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),)
preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
endif endif
EOF EOF
} }
} }
   
   
sub parse_command() { sub parse_command() {
my $cmd = shift @ARGV; my $cmd = shift @ARGV;
for ($cmd) { for ($cmd) {
/^target_mk$/ and return gen_target_mk(); /^target_mk$/ and return gen_target_mk();
/^target_config$/ and return gen_target_config(); /^target_config$/ and return gen_target_config();
/^package_mk$/ and return gen_package_mk(); /^package_mk$/ and return gen_package_mk();
/^package_config$/ and return gen_package_config(); /^package_config$/ and return gen_package_config();
/^kconfig/ and return gen_kconfig_overrides(); /^kconfig/ and return gen_kconfig_overrides();
} }
print <<EOF print <<EOF
Available Commands: Available Commands:
$0 target_mk [file] Target metadata in makefile format $0 target_mk [file] Target metadata in makefile format
$0 target_config [file] Target metadata in Kconfig format $0 target_config [file] Target metadata in Kconfig format
$0 package_mk [file] Package metadata in makefile format $0 package_mk [file] Package metadata in makefile format
$0 package_config [file] Package metadata in Kconfig format $0 package_config [file] Package metadata in Kconfig format
$0 kconfig [file] [config] Kernel config overrides $0 kconfig [file] [config] Kernel config overrides
   
EOF EOF
} }
   
parse_command(); parse_command();
   
# #
# Copyright (C) 2007 OpenWrt.org # Copyright (C) 2007 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.
# #
# Main makefile for the toolchain # Main makefile for the toolchain
# #
curdir:=toolchain curdir:=toolchain
   
# subdirectories to descend into # subdirectories to descend into
$(curdir)/builddirs := kernel-headers $(if $(CONFIG_GDB),gdb) $(if $(CONFIG_NATIVE_TOOLCHAIN),,binutils gcc uClibc) $(curdir)/builddirs := kernel-headers $(if $(CONFIG_GDB),gdb) $(if $(CONFIG_NATIVE_TOOLCHAIN),,binutils gcc uClibc)
   
# builddir dependencies # builddir dependencies
$(curdir)/uClibc/prepare:=$(curdir)/kernel-headers/prepare $(curdir)/uClibc/prepare:=$(curdir)/kernel-headers/prepare
ifeq ($(CONFIG_NATIVE_TOOLCHAIN),) ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
$(curdir)/binutils/prepare:=$(curdir)/uClibc/prepare $(curdir)/binutils/prepare:=$(curdir)/uClibc/prepare
$(curdir)/gcc/prepare:=$(curdir)/binutils/install $(curdir)/gcc/prepare:=$(curdir)/binutils/install
$(curdir)/uClibc/compile:=$(curdir)/gcc/compile $(curdir)/uClibc/compile:=$(curdir)/gcc/compile
endif endif
$(curdir)/gcc/install:=$(curdir)/uClibc/install $(curdir)/gcc/install:=$(curdir)/uClibc/install
   
# prerequisites for the individual targets # prerequisites for the individual targets
$(curdir)/ := .config $(tools/stamp) $(curdir)/ := .config $(tools/stamp-install) prereq
$(curdir)//prepare = $(STAGING_DIR)/include-host/.done $(curdir)//prepare = $(STAGING_DIR)/include-host/.done
$(curdir)//compile = $(1)/prepare $(curdir)//compile = $(1)/prepare
$(curdir)//install = $(1)/compile $(curdir)//install = $(1)/compile
   
$(eval $(call stampfile,$(curdir),toolchain)) $(eval $(call stampfile,$(curdir),toolchain,install))
$(eval $(call subdir,$(curdir))) $(eval $(call subdir,$(curdir)))
   
   
# #
# Copyright (C) 2007 OpenWrt.org # Copyright (C) 2007 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.
# #
# Main makefile for the host tools # Main makefile for the host tools
# #
curdir:=tools curdir:=tools
   
# subdirectories to descend into # subdirectories to descend into
$(curdir)/builddirs := sed sstrip ipkg-utils ext2fs squashfs mtd-utils lzma mkimage firmware-utils patch-cmdline $(if $(CONFIG_CCACHE),ccache) $(curdir)/builddirs := sed sstrip ipkg-utils ext2fs squashfs mtd-utils lzma mkimage firmware-utils patch-cmdline $(if $(CONFIG_CCACHE),ccache)
   
# builddir dependencies # builddir dependencies
$(curdir)/squashfs/compile := $(curdir)/lzma/install $(curdir)/squashfs/compile := $(curdir)/lzma/install
   
# preparatory work # preparatory work
define copy_include define copy_include
$(STAGING_DIR)/include-host/.done: $(STAGING_DIR)/include-host/.done:
@mkdir -p $$$$(dirname $$@) @mkdir -p $$$$(dirname $$@)
@cp $(1)/include/*.h $$$$(dirname $$@)/ @cp $(1)/include/*.h $$$$(dirname $$@)/
@touch $$@ @touch $$@
$(curdir)//prepare = $(STAGING_DIR)/include-host/.done $(curdir)//prepare = $(STAGING_DIR)/include-host/.done
endef endef
$(eval $(call copy_include,$(curdir))) $(eval $(call copy_include,$(curdir)))
   
# prerequisites for the individual targets # prerequisites for the individual targets
$(curdir)/ := .config $(curdir)/ := .config prereq
$(curdir)//compile = $(1)/prepare $(curdir)//compile = $(1)/prepare
$(curdir)//install = $(1)/compile $(curdir)//install = $(1)/compile
   
$(eval $(call stampfile,$(curdir),tools)) $(eval $(call stampfile,$(curdir),tools,install))
$(eval $(call subdir,$(curdir))) $(eval $(call subdir,$(curdir)))
   
comments