From b44c8b273badeef71bd53f8214a9de8c95e127bd Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 18 Jul 2006 20:01:03 +0000 Subject: [PATCH] add buildroot-ng support to the whiterussian sdk SVN-Revision: 4157 --- openwrt/package/rules.mk | 7 + openwrt/package/sdk/Makefile | 6 +- openwrt/package/sdk/files/Makefile | 69 + openwrt/package/sdk/files/Makefile.sdk | 42 - .../package/sdk/files/include/host-build.mk | 120 ++ openwrt/package/sdk/files/include/image.mk | 85 ++ .../package/sdk/files/include/netfilter.mk | 122 ++ openwrt/package/sdk/files/include/package.mk | 320 +++++ openwrt/package/sdk/files/include/target.mk | 30 + openwrt/package/sdk/files/include/verbose.mk | 37 + openwrt/package/sdk/files/package/Makefile | 45 + .../package/sdk/files/{ => package}/depend.mk | 0 openwrt/package/sdk/files/rules.mk | 118 ++ .../package/sdk/files/scripts/configtest.pl | 35 + openwrt/package/sdk/files/scripts/download.pl | 106 ++ openwrt/package/sdk/files/scripts/flash.sh | 66 + .../sdk/files/scripts/gen_busybox_config.pl | 29 + openwrt/package/sdk/files/scripts/gen_deps.pl | 78 ++ .../sdk/files/scripts/gen_menuconfig.pl | 121 ++ openwrt/package/sdk/files/scripts/ipkg | 1189 +++++++++++++++++ .../sdk/files/scripts/make-ipkg-dir.sh | 21 + .../package/sdk/files/scripts/patch-kernel.sh | 54 + openwrt/package/sdk/files/scripts/rstrip.sh | 35 + .../package/sdk/files/scripts/timestamp.pl | 62 + 24 files changed, 2751 insertions(+), 46 deletions(-) create mode 100644 openwrt/package/sdk/files/Makefile delete mode 100644 openwrt/package/sdk/files/Makefile.sdk create mode 100644 openwrt/package/sdk/files/include/host-build.mk create mode 100644 openwrt/package/sdk/files/include/image.mk create mode 100644 openwrt/package/sdk/files/include/netfilter.mk create mode 100644 openwrt/package/sdk/files/include/package.mk create mode 100644 openwrt/package/sdk/files/include/target.mk create mode 100644 openwrt/package/sdk/files/include/verbose.mk create mode 100644 openwrt/package/sdk/files/package/Makefile rename openwrt/package/sdk/files/{ => package}/depend.mk (100%) create mode 100644 openwrt/package/sdk/files/rules.mk create mode 100755 openwrt/package/sdk/files/scripts/configtest.pl create mode 100755 openwrt/package/sdk/files/scripts/download.pl create mode 100644 openwrt/package/sdk/files/scripts/flash.sh create mode 100755 openwrt/package/sdk/files/scripts/gen_busybox_config.pl create mode 100755 openwrt/package/sdk/files/scripts/gen_deps.pl create mode 100755 openwrt/package/sdk/files/scripts/gen_menuconfig.pl create mode 100755 openwrt/package/sdk/files/scripts/ipkg create mode 100755 openwrt/package/sdk/files/scripts/make-ipkg-dir.sh create mode 100755 openwrt/package/sdk/files/scripts/patch-kernel.sh create mode 100755 openwrt/package/sdk/files/scripts/rstrip.sh create mode 100755 openwrt/package/sdk/files/scripts/timestamp.pl diff --git a/openwrt/package/rules.mk b/openwrt/package/rules.mk index 267b599a6b..b3f4cdbea9 100644 --- a/openwrt/package/rules.mk +++ b/openwrt/package/rules.mk @@ -2,6 +2,11 @@ IPKG := IPKG_INSTROOT=$(TARGET_DIR) IPKG_CONF_DIR=$(IPKG_CONF) $(SCRIPT_DIR)/ipkg -force-defaults -force-depends IPKG_STATE_DIR := $(TARGET_DIR)/usr/lib/ipkg +ifneq ($(DUMP),) +dump: +.PHONY: dump +endif + define PKG_template IPKG_$(1):=$(PACKAGE_DIR)/$(2)_$(3)_$(4).ipk IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(2) @@ -36,6 +41,7 @@ $(2)-clean: clean-targets: $(2)-clean endef +ifeq ($(DUMP),) ifneq ($(strip $(PKG_SOURCE)),) $(DL_DIR)/$(PKG_SOURCE): $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL) @@ -80,3 +86,4 @@ clean: clean-targets rm -rf $(PKG_BUILD_DIR) .PHONY: all source prepare compile install clean +endif diff --git a/openwrt/package/sdk/Makefile b/openwrt/package/sdk/Makefile index 144a24aca4..384b696b7a 100644 --- a/openwrt/package/sdk/Makefile +++ b/openwrt/package/sdk/Makefile @@ -23,12 +23,10 @@ $(BIN_DIR)/$(SDK_NAME).tar.bz2: mkdir -p $(SDK_BUILD_DIR)/dl $(SDK_BUILD_DIR)/examples $(SDK_BUILD_DIR)/package cp -a $(STAGING_DIR) $(SCRIPT_DIR) $(TOPDIR)/docs $(SDK_BUILD_DIR)/ cp -a $(TOPDIR)/package/strace $(TOPDIR)/package/iproute2 $(SDK_BUILD_DIR)/examples - cp $(TOPDIR)/rules.mk $(SDK_BUILD_DIR)/ - cp ./files/Makefile.sdk $(SDK_BUILD_DIR)/Makefile - cp ./files/README.SDK $(SDK_BUILD_DIR)/ - cp ./files/depend.mk $(SDK_BUILD_DIR)/package/ cp $(TOPDIR)/package/rules.mk $(SDK_BUILD_DIR)/package/ + -cp -a ./files/* $(SDK_BUILD_DIR)/ egrep '^BR2_(ARCH|WGET|STAGING|JLEVEL|LARGEFILE|TARGET_OPT)' $(TOPDIR)/.config > $(SDK_BUILD_DIR)/.config + egrep '^BR2_(ARCH|WGET|STAGING|JLEVEL|LARGEFILE|TARGET_OPT)' $(TOPDIR)/.config | sed -e s,BR2_,CONFIG_,g >> $(SDK_BUILD_DIR)/.config find $(SDK_BUILD_DIR) -name .svn | xargs rm -rf find $(SDK_BUILD_DIR) -name CVS | xargs rm -rf (cd $(BUILD_DIR); \ diff --git a/openwrt/package/sdk/files/Makefile b/openwrt/package/sdk/files/Makefile new file mode 100644 index 0000000000..ba488e380c --- /dev/null +++ b/openwrt/package/sdk/files/Makefile @@ -0,0 +1,69 @@ +# Makefile for OpenWrt +# +# Copyright (C) 2006 by Felix Fietkau +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +RELEASE:=Kamikaze +#VERSION:=2.0 # uncomment for final release + +#-------------------------------------------------------------- +# Just run 'make menuconfig', configure stuff, then run 'make'. +# You shouldn't need to mess with anything beyond this point... +#-------------------------------------------------------------- +TOPDIR=${shell pwd} +export TOPDIR + +DEVELOPER=1 +export DEVELOPER + +all: world + +.pkginfo: FORCE +ifneq ($(shell ./scripts/timestamp.pl -p .pkginfo package Makefile),.pkginfo) + @echo Collecting package info... + @-for dir in package/*/; do \ + echo Source-Makefile: $${dir}Makefile; \ + $(MAKE) --no-print-dir DUMP=1 -C $$dir 2>&- || true; \ + done > $@ +endif + +pkginfo-clean: FORCE + -rm -f .pkginfo .config.in + +package/%: .pkginfo FORCE + $(MAKE) -C package $(patsubst package/%,%,$@) SDK=1 + +download: FORCE + $(MAKE) package/download + +world: FORCE + $(MAKE) package/compile + -( \ + cd package; \ + find . -maxdepth 2 -name Config.in | \ + sed -e 's,/Config.in,,g' | \ + xargs -r -n1 make compile -C; \ + ) + +clean: FORCE + rm -rf build_* bin + +distclean: clean + rm -rf dl .pkg* + +.PHONY: FORCE +FORCE: diff --git a/openwrt/package/sdk/files/Makefile.sdk b/openwrt/package/sdk/files/Makefile.sdk deleted file mode 100644 index 6d5f61ad11..0000000000 --- a/openwrt/package/sdk/files/Makefile.sdk +++ /dev/null @@ -1,42 +0,0 @@ -# OpenWrt SDK Makefile -TOPDIR:=${shell pwd} -export TOPDIR -DEVELOPER:=1 -export DEVELOPER - -include $(TOPDIR)/rules.mk -include $(TOPDIR)/package/depend.mk - -PACKAGES:=$(filter-out %.mk,$(shell ls $(TOPDIR)/package)) -PACKAGES_PREPARE:=$(foreach package,$(PACKAGES),$(package)-prepare) -PACKAGES_COMPILE:=$(foreach package,$(PACKAGES),$(package)-compile) -PACKAGES_CLEAN:=$(foreach package,$(PACKAGES),$(package)-clean) - -all: compile package_index -compile: $(PACKAGES_COMPILE) -clean: $(PACKAGES_CLEAN) - rm -rf $(BUILD_DIR) - rm -rf bin - -distclean: clean - rm -rf $(DL_DIR) - -%-prepare: $(BUILD_DIR) - @$(MAKE) -C package/$(patsubst %-prepare,%,$@) prepare - -%-compile: %-prepare - @$(MAKE) -C package/$(patsubst %-compile,%,$@) compile - -%-clean: - @$(MAKE) -C package/$(patsubst %-clean,%,$@) clean - - -$(BUILD_DIR): - mkdir -p $@ - mkdir -p $(DL_DIR) - -package_index: - (cd $(PACKAGE_DIR); \ - $(STAGING_DIR)/usr/bin/ipkg-make-index . > Packages \ - ) - diff --git a/openwrt/package/sdk/files/include/host-build.mk b/openwrt/package/sdk/files/include/host-build.mk new file mode 100644 index 0000000000..43c83142df --- /dev/null +++ b/openwrt/package/sdk/files/include/host-build.mk @@ -0,0 +1,120 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +ifneq ($(strip $(PKG_CAT)),) + ifeq ($(PKG_CAT),unzip) + UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) + else + UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - + endif + define Build/Prepare/Default + $(UNPACK) + @if [ -d ./patches ]; then \ + $(PATCH) $(PKG_BUILD_DIR) ./patches; \ + fi + endef +endif + +define Build/Prepare + $(call Build/Prepare/Default) +endef + +define Build/Configure/Default + @(cd $(PKG_BUILD_DIR)/$(3); \ + [ -x configure ] && \ + $(2) \ + CPPFLAGS="-I$(STAGING_DIR)/host/include" \ + LDFLAGS="-L$(STAGING_DIR)/host/lib" \ + ./configure \ + --target=$(GNU_TARGET_NAME) \ + --host=$(GNU_TARGET_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 \ + $(DISABLE_NLS) \ + $(1); \ + true; \ + ) +endef + +define Build/Configure + $(call Build/Configure/Default) +endef + +define Build/Compile/Default + $(MAKE) -C $(PKG_BUILD_DIR) $(1) +endef + +define Build/Compile + $(call Build/Compile/Default) +endef + + +ifneq ($(strip $(PKG_SOURCE)),) + source: $(DL_DIR)/$(PKG_SOURCE) + + $(DL_DIR)/$(PKG_SOURCE): + mkdir -p $(DL_DIR) + $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL) + + $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE) +endif + +define HostBuild + $(PKG_BUILD_DIR)/.prepared: + @-rm -rf $(PKG_BUILD_DIR) + @mkdir -p $(PKG_BUILD_DIR) + $(call Build/Prepare) + touch $$@ + + $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared + $(call Build/Configure) + touch $$@ + + $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured + $(call Build/Compile) + touch $$@ + + $(STAGING_DIR)/stampfiles/.host_$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built + $(call Build/Install) + touch $$@ + + ifdef Build/Install + install-targets: $(STAGING_DIR)/stampfiles/.host_$(PKG_NAME)-installed + endif + + package-clean: FORCE + $(call Build/Clean) + $(call Build/Uninstall) + rm -f $(STAGING_DIR)/stampfiles/.host_$(PKG_NAME)-installed + + source: + prepare: $(PKG_BUILD_DIR)/.prepared + configure: $(PKG_BUILD_DIR)/.configured + + compile-targets: $(PKG_BUILD_DIR)/.built + compile: compile-targets + + install-targets: + install: install-targets + + clean-targets: + clean: FORCE + @$(MAKE) clean-targets + $(call Build/Clean) + rm -rf $(PKG_BUILD_DIR) + +endef diff --git a/openwrt/package/sdk/files/include/image.mk b/openwrt/package/sdk/files/include/image.mk new file mode 100644 index 0000000000..95accd6e1d --- /dev/null +++ b/openwrt/package/sdk/files/include/image.mk @@ -0,0 +1,85 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +KDIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD) + +ifneq ($(CONFIG_BIG_ENDIAN),y) +JFFS2OPTS := --pad --little-endian --squash +SQUASHFS_OPTS := -le +else +JFFS2OPTS := --pad --big-endian --squash +SQUASHFS_OPTS := -be +endif + +ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) + ifeq ($(CONFIG_TARGET_ROOTFS_JFFS2),y) + define Image/mkfs/jffs2 + rm -rf $(BUILD_DIR)/root/jffs + + $(STAGING_DIR)/bin/mkfs.jffs2 $(JFFS2OPTS) -e 0x10000 -o $(KDIR)/root.jffs2-64k -d $(BUILD_DIR)/root + $(STAGING_DIR)/bin/mkfs.jffs2 $(JFFS2OPTS) -e 0x20000 -o $(KDIR)/root.jffs2-128k -d $(BUILD_DIR)/root + + # add End-of-Filesystem markers + echo -ne '\xde\xad\xc0\xde' >> $(KDIR)/root.jffs2-64k + echo -ne '\xde\xad\xc0\xde' >> $(KDIR)/root.jffs2-128k + + $(call Image/Build,jffs2-64k) + $(call Image/Build,jffs2-128k) + 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) + $(call Image/Build,squashfs) + endef + endif + + ifeq ($(CONFIG_TARGET_ROOTFS_TGZ),y) + define Image/mkfs/tgz + tar -zcf $(BIN_DIR)/openwrt-rootfs.tgz --owner=root --group=root -C $(BUILD_DIR)/root/ . + endef + endif +endif + +define Image/mkfs/prepare/default + find $(BUILD_DIR)/root -type f -not -perm +0100 | 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 +endef + +define Image/mkfs/prepare + $(call Image/mkfs/prepare/default) +endef + +define BuildImage +compile: + $(call Build/Compile) + +install: + $(call Image/Prepare) + $(call Image/mkfs/prepare) + $(call Image/BuildKernel) + $(call Image/mkfs/jffs2) + $(call Image/mkfs/squashfs) + $(call Image/mkfs/tgz) + +clean: + $(call Build/Clean) +endef + +compile-targets: +install-targets: +clean-targets: + +source: +prepare: +compile: compile-targets +install: compile install-targets +clean: clean-targets diff --git a/openwrt/package/sdk/files/include/netfilter.mk b/openwrt/package/sdk/files/include/netfilter.mk new file mode 100644 index 0000000000..236d4b2429 --- /dev/null +++ b/openwrt/package/sdk/files/include/netfilter.mk @@ -0,0 +1,122 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +# $Id: netfilter.mk 2411 2005-11-11 03:41:43Z nico $ + +ifeq ($(NF_2_6),1) +P_V4:=ipv4/netfilter/ +P_XT:=netfilter/ +else +P_V4:= +P_XT:= +endif + +IPT_CONNTRACK-m := +IPT_CONNTRACK-$(CONFIG_IP_NF_MATCH_CONNMARK) += $(P_V4)ipt_connmark +IPT_CONNTRACK-$(CONFIG_IP_NF_TARGET_CONNMARK) += $(P_V4)ipt_CONNMARK +IPT_CONNTRACK-$(CONFIG_IP_NF_MATCH_CONNTRACK) += $(P_V4)ipt_conntrack +IPT_CONNTRACK-$(CONFIG_IP_NF_MATCH_HELPER) += $(P_V4)ipt_helper +IPT_CONNTRACK-$(CONFIG_IP_NF_MATCH_STATE) += $(P_V4)ipt_state +IPT_CONNTRACK-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += $(P_XT)xt_conntrack +IPT_CONNTRACK-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += $(P_XT)xt_helper +IPT_CONNTRACK-$(CONFIG_NETFILTER_XT_MATCH_STATE) += $(P_XT)xt_state + + +IPT_EXTRA-m := +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_CONDITION) += $(P_V4)ipt_condition +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_CONNBYTES) += $(P_V4)ipt_connbytes +IPT_EXTRA-$(CONFIG_NETFILTER_XT_MATCH_CONNBYTES) += $(P_XT)xt_connbytes +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_LIMIT) += $(P_V4)ipt_limit +IPT_EXTRA-$(CONFIG_NETFILTER_XT_MATCH_LIMIT) += $(P_XT)xt_limit +IPT_EXTRA-$(CONFIG_IP_NF_TARGET_LOG) += $(P_V4)ipt_LOG +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_MULTIPORT) += $(P_XT)xt_multiport +IPT_EXTRA-$(CONFIG_NETFILTER_XT_MATCH_MULTIPORT) += $(P_XT)xt_multiport +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_OWNER) += $(P_V4)ipt_owner +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_PHYSDEV) += $(P_V4)ipt_physdev +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_PKTTYPE) += $(P_V4)ipt_pkttype +IPT_EXTRA-$(CONFIG_NETFILTER_XT_MATCH_PKTTYPE) += $(P_XT)xt_pkttype +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_QUOTA) += $(P_V4)ipt_quota +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_RECENT) += $(P_V4)ipt_recent +IPT_EXTRA-$(CONFIG_IP_NF_TARGET_REJECT) += $(P_V4)ipt_REJECT +IPT_EXTRA-$(CONFIG_IP_NF_MATCH_STRING) += $(P_V4)ipt_string +IPT_EXTRA-$(CONFIG_NETFILTER_XT_MATCH_STRING) += $(P_XT)xt_string + +IPT_FILTER-m := +IPT_FILTER-$(CONFIG_IP_NF_MATCH_IPP2P) += $(P_V4)ipt_ipp2p +IPT_FILTER-$(CONFIG_IP_NF_MATCH_LAYER7) += $(P_V4)ipt_layer7 + +IPT_IMQ-m := +IPT_IMQ-$(CONFIG_IP_NF_TARGET_IMQ) += $(P_V4)ipt_IMQ + +IPT_IPOPT-m := +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_DSCP) += $(P_V4)ipt_dscp +IPT_IPOPT-$(CONFIG_IP_NF_TARGET_DSCP) += $(P_V4)ipt_DSCP +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_ECN) += $(P_V4)ipt_ecn +IPT_IPOPT-$(CONFIG_IP_NF_TARGET_ECN) += $(P_V4)ipt_ECN +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_LENGTH) += $(P_V4)ipt_length +IPT_IPOPT-$(CONFIG_NETFILTER_XT_MATCH_LENGTH) += $(P_XT)xt_length +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_MAC) += $(P_V4)ipt_mac +IPT_IPOPT-$(CONFIG_NETFILTER_XT_MATCH_MAC) += $(P_XT)xt_mac +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_MARK) += $(P_V4)ipt_mark +IPT_IPOPT-$(CONFIG_NETFILTER_XT_MATCH_MARK) += $(P_XT)xt_mark +IPT_IPOPT-$(CONFIG_IP_NF_TARGET_MARK) += $(P_V4)ipt_MARK +IPT_IPOPT-$(CONFIG_NETFILTER_XT_TARGET_MARK) += $(P_XT)xt_MARK +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_TCPMSS) += $(P_V4)ipt_tcpmss +IPT_IPOPT-$(CONFIG_NETFILTER_XT_MATCH_TCPMSS) += $(P_XT)xt_tcpmss +IPT_IPOPT-$(CONFIG_IP_NF_TARGET_TCPMSS) += $(P_V4)ipt_TCPMSS +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_TOS) += $(P_V4)ipt_tos +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_TIME) += $(P_V4)ipt_time +IPT_IPOPT-$(CONFIG_IP_NF_TARGET_TOS) += $(P_V4)ipt_TOS +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_TTL) += $(P_V4)ipt_ttl +IPT_IPOPT-$(CONFIG_IP_NF_TARGET_TTL) += $(P_V4)ipt_TTL +IPT_IPOPT-$(CONFIG_IP_NF_MATCH_UNCLEAN) += $(P_V4)ipt_unclean + +IPT_IPSEC-m := +IPT_IPSEC-$(CONFIG_IP_NF_MATCH_AH_ESP) += $(P_V4)ipt_ah $(P_V4)ipt_esp +IPT_IPSEC-$(CONFIG_IP_NF_MATCH_AH) += $(P_V4)ipt_ah +IPT_IPSEC-$(CONFIG_NETFILTER_XT_MATCH_ESP) += $(P_XT)xt_esp + +IPT_NAT-m := +IPT_NAT-$(CONFIG_IP_NF_NAT) += $(P_V4)ipt_SNAT $(P_V4)ipt_DNAT +IPT_NAT-$(CONFIG_IP_NF_TARGET_MASQUERADE) += $(P_V4)ipt_MASQUERADE +IPT_NAT-$(CONFIG_IP_NF_TARGET_MIRROR) += $(P_V4)ipt_MIRROR +IPT_NAT-$(CONFIG_IP_NF_TARGET_REDIRECT) += $(P_V4)ipt_REDIRECT + +IPT_NAT_EXTRA-m := +IPT_NAT_EXTRA-$(CONFIG_IP_NF_AMANDA) += $(P_V4)ip_conntrack_amanda +IPT_NAT_EXTRA-$(CONFIG_IP_NF_CT_PROTO_GRE) += $(P_V4)ip_conntrack_proto_gre +IPT_NAT_EXTRA-$(CONFIG_IP_NF_NAT_PROTO_GRE) += $(P_V4)ip_nat_proto_gre +IPT_NAT_EXTRA-$(CONFIG_IP_NF_H323) += $(P_V4)ip_conntrack_h323 +IPT_NAT_EXTRA-$(CONFIG_IP_NF_NAT_H323) += $(P_V4)ip_nat_h323 +IPT_NAT_EXTRA-$(CONFIG_IP_NF_MMS) += $(P_V4)ip_conntrack_mms +IPT_NAT_EXTRA-$(CONFIG_IP_NF_NAT_MMS) += $(P_V4)ip_nat_mms +IPT_NAT_EXTRA-$(CONFIG_IP_NF_RTSP) += $(P_V4)ip_conntrack_rtsp +IPT_NAT_EXTRA-$(CONFIG_IP_NF_NAT_RTSP) += $(P_V4)ip_nat_rtsp +IPT_NAT_EXTRA-$(CONFIG_IP_NF_PPTP) += $(P_V4)ip_conntrack_pptp +IPT_NAT_EXTRA-$(CONFIG_IP_NF_SIP) += $(P_V4)ip_conntrack_sip +IPT_NAT_EXTRA-$(CONFIG_IP_NF_NAT_PPTP) += $(P_V4)ip_nat_pptp +IPT_NAT_EXTRA-$(CONFIG_IP_NF_NAT_SIP) += $(P_V4)ip_nat_sip +IPT_NAT_EXTRA-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += $(P_V4)ip_nat_snmp_basic +IPT_NAT_EXTRA-$(CONFIG_IP_NF_SIP) += $(P_V4)ip_conntrack_sip +IPT_NAT_EXTRA-$(CONFIG_IP_NF_NAT_SIP) += $(P_V4)ip_nat_sip +IPT_NAT_EXTRA-$(CONFIG_IP_NF_TFTP) += $(P_V4)ip_conntrack_tftp + +IPT_QUEUE-m := +IPT_QUEUE-$(CONFIG_IP_NF_QUEUE) += $(P_V4)ip_queue + +IPT_ULOG-m := +IPT_ULOG-$(CONFIG_IP_NF_TARGET_ULOG) += $(P_V4)ipt_ULOG + +IPT_BUILTIN := $(P_V4)ipt_standard +IPT_BUILTIN += $(P_V4)ipt_icmp $(P_V4)ipt_tcp $(P_V4)ipt_udp +IPT_BUILTIN += $(IPT_CONNTRACK-y) +IPT_BUILTIN += $(IPT_EXTRA-y) +IPT_BUILTIN += $(IPT_FILTER-y) +IPT_BUILTIN += $(IPT_IMQ-y) +IPT_BUILTIN += $(IPT_IPOPT-y) +IPT_BUILTIN += $(IPT_IPSEC-y) +IPT_BUILTIN += $(IPT_NAT-y) +IPT_BUILTIN += $(IPT_ULOG-y) diff --git a/openwrt/package/sdk/files/include/package.mk b/openwrt/package/sdk/files/include/package.mk new file mode 100644 index 0000000000..2784cc8881 --- /dev/null +++ b/openwrt/package/sdk/files/include/package.mk @@ -0,0 +1,320 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +ifneq ($(DUMP),) + all: dumpinfo +else + all: compile +endif + +define Build/DefaultTargets + ifeq ($(DUMP),) + ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR)) + ifeq ($(CONFIG_AUTOREBUILD),y) + $(PKG_BUILD_DIR)/.prepared: package-clean + endif + endif + + ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg $(IPKG_$(1)) $(PKG_BUILD_DIR)),$(IPKG_$(1))) + ifeq ($(CONFIG_AUTOREBUILD),y) + $(PKG_BUILD_DIR)/.built: package-rebuild + endif + endif + endif + + + $(PKG_BUILD_DIR)/.prepared: + @-rm -rf $(PKG_BUILD_DIR) + @mkdir -p $(PKG_BUILD_DIR) + $(call Build/Prepare) + touch $$@ + + $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared + $(call Build/Configure) + touch $$@ + + $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured + $(call Build/Compile) + touch $$@ + + $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built + $(call Build/InstallDev) + touch $$@ + + ifdef Build/InstallDev + compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed + endif + + package-clean: FORCE + $(call Build/Clean) + $(call Build/UninstallDev) + rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed + + package-rebuild: FORCE + @-rm -f $(PKG_BUILD_DIR)/.built + + define Build/DefaultTargets + endef +endef + +define Package/Default + CONFIGFILE:= + SECTION:=opt + CATEGORY:=Extra packages + DEPENDS:= + EXTRA_DEPENDS:= + MAINTAINER:=OpenWrt Developers Team + SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd}) + ifneq ($(PKG_VERSION),) + ifneq ($(PKG_RELEASE),) + VERSION:=$(PKG_VERSION)-$(PKG_RELEASE) + else + VERSION:=$(PKG_VERSION) + endif + else + VERSION:=$(PKG_RELEASE) + endif + PKGARCH:=$(ARCH) + PRIORITY:=optional + DEFAULT:= + MENU:= + SUBMENU:= + TITLE:= + DESCRIPTION:= +endef + +define BuildIPKGVariable +pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2)) +export pkg_$(subst .,_,$(subst -,_,$(1))_$(2)) +$(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi; +endef + +define BuildPackage + $(eval $(call Package/Default)) + $(eval $(call Package/$(1))) + + $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION, + ifeq ($($(FIELD)),) + $$(error Package/$(1) is missing the $(FIELD) field) + endif + ) + + ifeq ($(PKGARCH),) + PKGARCH:=$(ARCH) + endif + + ifeq ($(DESCRIPTION),) + $(eval DESCRIPTION:=$(TITLE)) + endif + + IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk + IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1) + INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list + + ifdef Package/$(1)/install + ifeq ($(CONFIG_PACKAGE_$(1)),y) + install-targets: $$(INFO_$(1)) + endif + + ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),) + compile-targets: $$(IPKG_$(1)) + endif + endif + + ifeq ($(FORCEREBUILD),y) + $$(IPKG_$(1)): FORCE + endif + + IDEPEND_$(1):=$$(strip $$(DEPENDS)) + + DUMPINFO += \ + echo "Package: $(1)"; + + ifneq ($(MENU),) + DUMPINFO += \ + echo "Menu: $(MENU)"; + endif + + ifneq ($(SUBMENU),) + DUMPINFO += \ + echo "Submenu: $(SUBMENU)"; + endif + + ifneq ($(DEFAULT),) + DUMPINFO += \ + echo "Default: $(DEFAULT)"; + endif + + DUMPINFO += \ + echo "Version: $(VERSION)"; \ + echo "Depends: $$(IDEPEND_$(1))"; \ + echo "Build-Depends: $(PKG_BUILDDEP)"; \ + echo "Category: $(CATEGORY)"; \ + echo "Title: $(TITLE)"; \ + echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g'; + + ifneq ($(URL),) + DUMPINFO += \ + echo; \ + echo "$(URL)"; + endif + + DUMPINFO += \ + echo "@@"; + + ifneq ($(CONFIG),) + DUMPINFO += \ + echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \ + echo "@@"; + endif + + $(eval $(call BuildIPKGVariable,$(1),conffiles)) + $(eval $(call BuildIPKGVariable,$(1),preinst)) + $(eval $(call BuildIPKGVariable,$(1),postinst)) + $(eval $(call BuildIPKGVariable,$(1),prerm)) + $(eval $(call BuildIPKGVariable,$(1),postrm)) + $$(IDIR_$(1))/CONTROL/control: Makefile $(PKG_BUILD_DIR)/.prepared + mkdir -p $$(IDIR_$(1))/CONTROL + echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control + echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control + ( \ + DEPENDS=; \ + for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \ + DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \ + done; \ + echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \ + ) + echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control + echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control + echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control + echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control + echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control + echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control + chmod 644 $$(IDIR_$(1))/CONTROL/control + (cd $$(IDIR_$(1))/CONTROL; \ + $($(1)_COMMANDS) \ + ) + + $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built + $(call Package/$(1)/install,$$(IDIR_$(1))) + mkdir -p $(PACKAGE_DIR) + -find $$(IDIR_$(1)) -name CVS | xargs rm -rf + -find $$(IDIR_$(1)) -name .svn | xargs rm -rf + -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f + $(RSTRIP) $$(IDIR_$(1)) + $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR) + + $$(INFO_$(1)): $$(IPKG_$(1)) + $(IPKG) install $$(IPKG_$(1)) + + $(1)-clean: + rm -f $(PACKAGE_DIR)/$(1)_* + + clean: $(1)-clean + + $$(eval $$(call Build/DefaultTargets,$(1))) + +endef + +ifneq ($(strip $(PKG_CAT)),) + ifeq ($(PKG_CAT),unzip) + UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) + else + UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - + endif + define Build/Prepare/Default + $(UNPACK) + @if [ -d ./patches ]; then \ + $(PATCH) $(PKG_BUILD_DIR) ./patches; \ + fi + endef +endif + +define Build/Prepare + $(call Build/Prepare/Default) +endef + +define Build/Configure/Default + @(cd $(PKG_BUILD_DIR)/$(3); \ + [ -x configure ] && \ + $(2) \ + $(TARGET_CONFIGURE_OPTS) \ + CFLAGS="$(TARGET_CFLAGS)" \ + CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \ + LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \ + ./configure \ + --target=$(GNU_TARGET_NAME) \ + --host=$(GNU_TARGET_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 \ + $(DISABLE_NLS) \ + $(1); \ + true; \ + ) +endef + +define Build/Configure + $(call Build/Configure/Default,) +endef + +define Build/Compile/Default + $(MAKE) -C $(PKG_BUILD_DIR) \ + $(TARGET_CONFIGURE_OPTS) \ + CC=$(TARGET_CC) \ + CROSS="$(TARGET_CROSS)" \ + EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include" \ + ARCH="$(ARCH)" \ + $(1); +endef + +define Build/Compile + $(call Build/Compile/Default,) +endef + +ifneq ($(DUMP),) + dumpinfo: FORCE + @$(DUMPINFO) +else + $(PACKAGE_DIR): + mkdir -p $@ + + ifneq ($(strip $(PKG_SOURCE)),) + source: $(DL_DIR)/$(PKG_SOURCE) + + $(DL_DIR)/$(PKG_SOURCE): + mkdir -p $(DL_DIR) + $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL) + + $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE) + endif + + source: + prepare: $(PKG_BUILD_DIR)/.prepared + configure: $(PKG_BUILD_DIR)/.configured + + compile-targets: + compile: compile-targets + + install-targets: + install: install-targets + + clean-targets: + clean: FORCE + @$(MAKE) clean-targets + $(call Build/Clean) + rm -rf $(PKG_BUILD_DIR) +endif diff --git a/openwrt/package/sdk/files/include/target.mk b/openwrt/package/sdk/files/include/target.mk new file mode 100644 index 0000000000..44ff11128a --- /dev/null +++ b/openwrt/package/sdk/files/include/target.mk @@ -0,0 +1,30 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +define kernel_template +ifeq ($(CONFIG_LINUX_$(3)),y) +KERNEL:=$(1) +BOARD:=$(2) +endif +endef + +$(eval $(call kernel_template,2.4,brcm,2_4_BRCM)) +$(eval $(call kernel_template,2.4,ar7,2_4_AR7)) +$(eval $(call kernel_template,2.4,x86,2_4_X86)) +$(eval $(call kernel_template,2.6,brcm,2_6_BRCM)) +$(eval $(call kernel_template,2.6,brcm63xx,2_6_BRCM63XX)) +$(eval $(call kernel_template,2.6,rb532,2_6_RB532)) +$(eval $(call kernel_template,2.6,x86,2_6_X86)) +$(eval $(call kernel_template,2.4,ar531x,2_4_AR531X)) +$(eval $(call kernel_template,2.6,aruba,2_6_ARUBA)) +$(eval $(call kernel_template,2.6,au1000,2_6_AU1000)) +$(eval $(call kernel_template,2.6,xscale,2_6_XSCALE)) +$(eval $(call kernel_template,2.6,sibyte,2_6_SIBYTE)) + +export BOARD +export KERNEL + + diff --git a/openwrt/package/sdk/files/include/verbose.mk b/openwrt/package/sdk/files/include/verbose.mk new file mode 100644 index 0000000000..da2a21974a --- /dev/null +++ b/openwrt/package/sdk/files/include/verbose.mk @@ -0,0 +1,37 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +# $Id:$ + +NO_TRACE_MAKE:=$(MAKE) V=99 + +ifndef KBUILD_VERBOSE + KBUILD_VERBOSE=0 + ifeq ("$(origin V)", "command line") + KBUILD_VERBOSE=$(V) + endif +endif + +ifneq ($(KBUILD_VERBOSE),99) + ifeq ($(QUIET),1) + $(MAKECMDGOALS): trace + trace: FORCE + @[ -f "$(MAKECMDGOALS)" ] || { \ + [ -z "$${PWD##$$TOPDIR}" ] || DIR=" -C $${PWD##$$TOPDIR/}"; \ + echo -e "\33[33mmake[$$(($(MAKELEVEL)+1))]$$DIR $(MAKECMDGOALS)\33[m" >&3; \ + } + else + export QUIET:=1 + ifeq ($(KBUILD_VERBOSE),0) + MAKE:=&>/dev/null $(MAKE) + endif + MAKE:=cmd() { $(MAKE) $$* || { echo "Build failed. Please re-run make with V=99 to see what's going on"; /bin/false; } } 3>&1 4>&2; cmd + endif + + .SILENT: $(MAKECMDGOALS) +else + NO_TRACE_MAKE:=$(MAKE) +endif diff --git a/openwrt/package/sdk/files/package/Makefile b/openwrt/package/sdk/files/package/Makefile new file mode 100644 index 0000000000..4b924a390c --- /dev/null +++ b/openwrt/package/sdk/files/package/Makefile @@ -0,0 +1,45 @@ +# Main makefile for the packages +include $(TOPDIR)/rules.mk +include $(TOPDIR)/.config +include $(TOPDIR)/.pkgdeps + +SOURCE_PACKAGES:=$(patsubst %,%-source,$(package-y) $(package-m)) +COMPILE_PACKAGES:=$(patsubst %,%-compile,$(package-y) $(package-m)) +INSTALL_PACKAGES:=$(patsubst %,%-install,$(package-y)) + +$(STAMP_DIR) $(TARGET_DIR): + mkdir -p $@ + +%-source: $(STAMP_DIR) $(TARGET_DIR) + $(MAKE) -C $(patsubst %-source,%,$@) source MAKEFLAGS="$(BUILD_MAKEFLAGS)" + +%-prepare: $(STAMP_DIR) $(TARGET_DIR) + $(MAKE) -C $(patsubst %-prepare,%,$@) prepare MAKEFLAGS="$(BUILD_MAKEFLAGS)" + +%-compile: $(STAMP_DIR) $(TARGET_DIR) + $(MAKE) -C $(patsubst %-compile,%,$@) compile MAKEFLAGS="$(BUILD_MAKEFLAGS)" + +%-install: $(STAMP_DIR) $(TARGET_DIR) + $(MAKE) -C $(patsubst %-install,%,$@) install MAKEFLAGS="$(BUILD_MAKEFLAGS)" + +%-clean: $(STAMP_DIR) $(TARGET_DIR) + $(MAKE) -C $(patsubst %-clean,%,$@) clean MAKEFLAGS="$(BUILD_MAKEFLAGS)" + +ifeq ($(SDK),1) +GENDEP_OPTS := -s +endif + +$(TOPDIR)/.pkgdeps: $(TOPDIR)/.pkginfo + @$(TOPDIR)/scripts/gen_deps.pl $(GENDEP_OPTS) < $< > $@ || rm -f $@ + +all: compile +clean: $(patsubst %,%-clean,$(package-) $(package-y) $(package-m)) +download: $(SOURCE_PACKAGES) +compile-targets: $(COMPILE_PACKAGES) +compile: + $(MAKE) -j$(CONFIG_JLEVEL) compile-targets +install-targets: base-files-install $(INSTALL_PACKAGES) +install: + rm -rf $(BUILD_DIR)/root + $(MAKE) install-targets + diff --git a/openwrt/package/sdk/files/depend.mk b/openwrt/package/sdk/files/package/depend.mk similarity index 100% rename from openwrt/package/sdk/files/depend.mk rename to openwrt/package/sdk/files/package/depend.mk diff --git a/openwrt/package/sdk/files/rules.mk b/openwrt/package/sdk/files/rules.mk new file mode 100644 index 0000000000..533bdc35c3 --- /dev/null +++ b/openwrt/package/sdk/files/rules.mk @@ -0,0 +1,118 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +-include $(TOPDIR)/.config +include $(TOPDIR)/include/verbose.mk + +export SHELL=/bin/bash + +ARCH:=$(strip $(subst ",, $(CONFIG_ARCH))) +TARGET_OPTIMIZATION:=$(strip $(subst ",, $(CONFIG_TARGET_OPTIMIZATION))) +WGET:=$(strip $(subst ",, $(CONFIG_WGET))) +#"))"))")) # fix vim's broken syntax highlighting + +OPTIMIZE_FOR_CPU:=$(ARCH) + +# DIRECTORIES # + +DL_DIR:=$(TOPDIR)/dl +INCLUDE_DIR:=$(TOPDIR)/include +SCRIPT_DIR:=$(TOPDIR)/scripts +TOOL_BUILD_DIR:=$(TOPDIR)/toolchain_build_$(ARCH) +STAGING_DIR:=$(TOPDIR)/staging_dir_$(ARCH) +BIN_DIR:=$(TOPDIR)/bin +PACKAGE_DIR:=$(BIN_DIR)/packages +IPKG_TARGET_DIR:=$(PACKAGE_DIR) +BUILD_DIR:=$(TOPDIR)/build_$(ARCH) +STAMP_DIR:=$(BUILD_DIR)/stamp +TARGET_DIR:=$(BUILD_DIR)/root +IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/ipkg + +REAL_GNU_TARGET_NAME=$(OPTIMIZE_FOR_CPU)-linux-uclibc +GNU_TARGET_NAME=$(OPTIMIZE_FOR_CPU)-linux +KERNEL_CROSS:=$(STAGING_DIR)/bin/$(OPTIMIZE_FOR_CPU)-linux-uclibc- +TARGET_CROSS:=$(STAGING_DIR)/bin/$(OPTIMIZE_FOR_CPU)-linux-uclibc- +IMAGE:=$(BUILD_DIR)/root_fs_$(ARCH) + +TARGET_PATH:=$(STAGING_DIR)/usr/bin:$(STAGING_DIR)/bin:/bin:/sbin:/usr/bin:/usr/sbin +TARGET_CFLAGS:=$(TARGET_OPTIMIZATION) + +LINUX_DIR:=$(BUILD_DIR)/linux +LINUX_HEADERS_DIR:=$(TOOL_BUILD_DIR)/linux + +# APPLICATIONS # +HOSTCC:=gcc +TARGET_CC:=$(TARGET_CROSS)gcc +STRIP:=$(STAGING_DIR)/bin/sstrip +PATCH:=$(SCRIPT_DIR)/patch-kernel.sh +SED:=$(STAGING_DIR)/bin/sed -i -e +CP:=cp -fpR + +HOST_ARCH:=$(shell $(HOSTCC) -dumpmachine | sed -e s'/-.*//' \ + -e 's/sparc.*/sparc/' \ + -e 's/arm.*/arm/' \ + -e 's/m68k.*/m68k/' \ + -e 's/ppc/powerpc/' \ + -e 's/v850.*/v850/' \ + -e 's/sh[234]/sh/' \ + -e 's/mips-.*/mips/' \ + -e 's/mipsel-.*/mipsel/' \ + -e 's/cris.*/cris/' \ + -e 's/i[3-9]86/i386/' \ + ) + +GNU_HOST_NAME:=$(HOST_ARCH)-pc-linux-gnu + +TARGET_CONFIGURE_OPTS:= \ + PATH=$(TARGET_PATH) \ + AR=$(TARGET_CROSS)ar \ + AS=$(TARGET_CROSS)as \ + LD=$(TARGET_CROSS)ld \ + NM=$(TARGET_CROSS)nm \ + CC=$(TARGET_CROSS)gcc \ + GCC=$(TARGET_CROSS)gcc \ + CXX=$(TARGET_CROSS)g++ \ + RANLIB=$(TARGET_CROSS)ranlib \ + STRIP=$(TARGET_CROSS)strip + +# strip an entire directory +RSTRIP:= \ + STRIP="$(STRIP)" \ + STRIP_KMOD="$(TARGET_CROSS)strip --strip-unneeded --remove-section=.comment" \ + $(SCRIPT_DIR)/rstrip.sh + +# where to build (and put) .ipk packages +IPKG:= \ + IPKG_TMP=$(BUILD_DIR)/tmp \ + IPKG_INSTROOT=$(TARGET_DIR) \ + IPKG_CONF_DIR=$(STAGING_DIR)/etc \ + IPKG_OFFLINE_ROOT=$(BUILD_DIR)/root \ + $(SCRIPT_DIR)/ipkg -force-defaults -force-depends + +# invoke ipkg-build with some default options +IPKG_BUILD:= \ + PATH="$(TARGET_PATH)" ipkg-build -c -o root -g root + +ifeq ($(CONFIG_ENABLE_LOCALE),true) + DISABLE_NLS:= +else + DISABLE_NLS:=--disable-nls +endif + +ifneq ($(CONFIG_LARGEFILE),y) + DISABLE_LARGEFILE= --disable-largefile +endif + +ifeq ($(CONFIG_TAR_VERBOSITY),y) + TAR_OPTIONS=-xvf +else + TAR_OPTIONS=-xf +endif + +all: +FORCE: ; +.PHONY: FORCE diff --git a/openwrt/package/sdk/files/scripts/configtest.pl b/openwrt/package/sdk/files/scripts/configtest.pl new file mode 100755 index 0000000000..289b2fecc0 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/configtest.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +my %change = ( + '^BUSYBOX' => 'make package/busybox-clean', + 'OPENVPN_' => 'make package/openvpn-clean', + 'SYSCONF_' => 'make package/base-files-clean target_clean', + '' => 'make target_clean' +); + +my @configfiles = ( +# ['package/linux/linux.config', 'build_mipsel/linux/.config' => +# 'make -C package linux-clean'] +); + + + +foreach my $change (keys %change) { + my $v1 = `grep '$change' .config.test`; + my $v2 = `grep '$change' .config`; + $v1 eq $v2 or system($change{$change}); +} + +foreach my $file (@configfiles) { + if ((-f $file->[0]) and (-f $file->[1])) { + my @s1 = stat $file->[0]; + my @s2 = stat $file->[1]; + $s1[9] > $s2[9] and system($file->[2]); + } +} diff --git a/openwrt/package/sdk/files/scripts/download.pl b/openwrt/package/sdk/files/scripts/download.pl new file mode 100755 index 0000000000..40b8d212a5 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/download.pl @@ -0,0 +1,106 @@ +#!/usr/bin/perl +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +use strict; +use warnings; + +my $target = shift @ARGV; +my $filename = shift @ARGV; +my $md5sum = shift @ARGV; +my @mirrors; + +my $ok; + +@ARGV > 0 or die "Syntax: $0 [ ...]\n"; + +sub download +{ + my $mirror = shift; + + open WGET, "wget -t1 --timeout=20 -O- \"$mirror/$filename\" |" or die "Cannot launch wget.\n"; + open MD5SUM, "| md5sum > \"$target/$filename.md5sum\"" or die "Cannot launch md5sum.\n"; + open OUTPUT, "> $target/$filename.dl" or die "Cannot create file $target/$filename.dl: $!\n"; + my $buffer; + while (read WGET, $buffer, 1048576) { + print MD5SUM $buffer; + print OUTPUT $buffer; + } + close MD5SUM; + close WGET; + close OUTPUT; + + if (($? >> 8) != 0 ) { + print STDERR "Download failed.\n"; + cleanup(); + return; + } + + my $sum = `cat "$target/$filename.md5sum"`; + $sum =~ /^(\w+)\s+/ or die "Could not generate md5sum\n"; + $sum = $1; + + if (($md5sum =~ /\w{32}/) and ($sum ne $md5sum)) { + print STDERR "MD5 sum of the downloaded file does not match - deleting download.\n"; + cleanup(); + return; + } + + unlink "$target/$filename"; + system("mv \"$target/$filename.dl\" \"$target/$filename\""); + cleanup(); +} + +sub cleanup +{ + unlink "$target/$filename.dl"; + unlink "$target/$filename.md5sum"; +} + +foreach my $mirror (@ARGV) { + if ($mirror =~ /^\@SF\/(.+)$/) { + my $sfpath = $1; + open SF, "wget -t1 -q -O- 'http://prdownloads.sourceforge.net/$sfpath/$filename' |"; + while () { + /RADIO NAME=use_default VALUE=(\w+) OnClick="form\.submit\(\)">/ or + /type="radio" name="use_default" value="(\w+)" onclick="form\.submit\(\)"\/>/ and do { + push @mirrors, "http://$1.dl.sourceforge.net/sourceforge/$sfpath"; + }; + /Download/ and do { + push @mirrors, "http://$1.dl.sourceforge.net/sourceforge/$sfpath"; + }; + } + push @mirrors, "http://dl.sourceforge.net/sourceforge/$sfpath"; + close SF; + } elsif ($mirror =~ /^\@GNU\/(.+)$/) { + my $gnupath = $1; + push @mirrors, "ftp://ftp.gnu.org/gnu/$gnupath"; + push @mirrors, "ftp://ftp.belnet.be/mirror/ftp.gnu.org/gnu/$gnupath"; + push @mirrors, "ftp://ftp.mirror.nl/pub/mirror/gnu/$gnupath"; + push @mirrors, "http://mirror.switch.ch/ftp/mirror/gnu/$gnupath"; + push @mirrors, "ftp://ftp.uu.net/archive/systems/gnu/$gnupath"; + push @mirrors, "ftp://ftp.eu.uu.net/pub/gnu/$gnupath"; + push @mirrors, "ftp://ftp.leo.org/pub/comp/os/unix/gnu/$gnupath"; + push @mirrors, "ftp://ftp.digex.net/pub/gnu/$gnupath"; + } else { + push @mirrors, $mirror; + } +} + +push @mirrors, 'http://mirror1.openwrt.org/'; +push @mirrors, 'http://downloads.openwrt.org/sources/'; + +while (!$ok) { + my $mirror = shift @mirrors; + $mirror or die "No more mirrors to try - giving up.\n"; + + download($mirror); + -f "$target/$filename" and $ok = 1; +} + +$SIG{INT} = \&cleanup; + diff --git a/openwrt/package/sdk/files/scripts/flash.sh b/openwrt/package/sdk/files/scripts/flash.sh new file mode 100644 index 0000000000..8841c35684 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/flash.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# +# tftp flash script for wireless routers +# +# Copyright (C) 2004 by Oleg I. Vdovikin +# Copyright (C) 2005 by Waldemar Brodkorb +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +if [ -z "$1" ] || [ ! -f $1 ] || [ -z $2 ]; then + echo Usage: $0 firmware vendor +cat << EOF +IMPORTANT: +Notes for Linksys / Asus WL500gx router: + be sure you have set boot_wait to yes. Power on your router + after executing this script. + +Notes for Asus WL500g router: + be sure POWER led is flashing (If this is not the case + poweroff the device, push the reset button & power on + it again, then release button) + +1) connect your pc to the LAN port +2) be sure your link is up and has an address in the + 192.168.1.0/24 address range (and not the 192.168.1.1) + +Notes for Toshiba router: + boot_wait is enabled by default on these units. + +1) connect your pc to any of the four LAN ports +2) be sure your link is up and has an address in the + 192.168.10.1/24 address range (and not the 192.168.10.1) +3) run this script (unit will only accept .trx images) +4) Turn unit power on. + +EOF + exit 0 +fi +if [ "$2" == "asus" ]; then +echo Confirming IP address setting... +echo -en "get ASUSSPACELINK\x01\x01\xa8\xc0 /dev/null\nquit\n" | tftp 192.168.1.1 +echo Flashing 192.168.1.1 using $1... +echo -en "binary\nput $1 ASUSSPACELINK\nquit\n" | tftp 192.168.1.1 +echo Please wait until leds stops flashing. +elif [ "$2" == "linksys" ]; then +echo Flashing 192.168.1.1 using $1... +echo -en "rexmt 1\ntrace\nbinary\nput $1\nquit\n" | tftp 192.168.1.1 +echo Please wait until power led stops flashing. Do not poweroff! Then you can login via telnet 192.168.1.1. +elif [ "$2" == "toshiba" ]; then +echo Flashing 192.168.10.1 using $1... +echo -en "rexmt 1\ntrace\nbinary\nput $1\nquit\n" | tftp 192.168.10.1 +echo Unit will automatically reboot within 5 minutes. Do not power off. Then you can login via telnet 192.168.10.1. +fi diff --git a/openwrt/package/sdk/files/scripts/gen_busybox_config.pl b/openwrt/package/sdk/files/scripts/gen_busybox_config.pl new file mode 100755 index 0000000000..9360052d29 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/gen_busybox_config.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +use strict; + +my $line; +my $l1 = ''; +my $l2 = '=y'; +while (<>) { + chomp; + /^(# )CONFIG_LARGEFILE(.+)$/ and do { + $l1 = $1; + $l2 = $2; + }; + /^(# )?CONFIG_BUSYBOX_(.+)/ and do { + my $p1 = $1; + my $p2 = $2; + $p2 =~ /(CONFIG_LFS|FDISK_SUPPORT_LARGE_DISKS)/ and do { + $p1 = $l1; + $p2 = "$1$l2"; + }; + print "$p1$p2\n"; + } +} diff --git a/openwrt/package/sdk/files/scripts/gen_deps.pl b/openwrt/package/sdk/files/scripts/gen_deps.pl new file mode 100755 index 0000000000..0cdcc97a14 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/gen_deps.pl @@ -0,0 +1,78 @@ +#!/usr/bin/perl +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +use strict; + +my $name; +my $src; +my $makefile; +my %conf; +my %pkg; +my %dep; +my %options; +my $opt; + +while ($opt = shift @ARGV) { + $opt =~ /^-s/ and $options{SDK} = 1; +} + +my $line; +while ($line = <>) { + chomp $line; + $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do { + $makefile = $1; + $src = $2; + }; + $line =~ /^Package: \s*(.+)\s*$/ and do { + $name = $1; + defined $pkg{$name} or $pkg{$name} = {}; + $pkg{$name}->{src} = $src; + }; + $line =~ /^(Build-)?Depends: \s*(.+)\s*$/ and do { + $pkg{$name}->{depends} ||= []; + foreach my $v (split /\s+/, $2) { + next if $v =~ /^[\+]?@/; + $v =~ s/^\+//; + push @{$pkg{$name}->{depends}}, $v; + } + }; +} + +$line=""; + +foreach $name (sort {uc($a) cmp uc($b)} keys %pkg) { + if ($options{SDK}) { + $conf{$pkg{$name}->{src}} or print "package-m += $pkg{$name}->{src}\n"; + $conf{$pkg{$name}->{src}} = 1; + } else { + print "package-\$(CONFIG_PACKAGE_$name) += $pkg{$name}->{src}\n"; + } + + my $hasdeps = 0; + my $depline = ""; + foreach my $dep (@{$pkg{$name}->{depends}}) { + my $idx; + if (defined $pkg{$dep}->{src}) { + ($pkg{$name}->{src} ne $pkg{$dep}->{src}) and $idx = $pkg{$dep}->{src}; + } elsif (defined($pkg{$dep}) && !$options{SDK}) { + $idx = $dep; + } + if ($idx) { + next if $dep{$pkg{$name}->{src}."->".$idx}; + $depline .= " $idx\-compile"; + $dep{$pkg{$name}->{src}."->".$idx} = 1; + } + } + if ($depline ne "") { + $line .= "$pkg{$name}->{src}-compile: $depline\n"; + } +} + +if ($line ne "") { + print "\n$line"; +} diff --git a/openwrt/package/sdk/files/scripts/gen_menuconfig.pl b/openwrt/package/sdk/files/scripts/gen_menuconfig.pl new file mode 100755 index 0000000000..e62363e630 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/gen_menuconfig.pl @@ -0,0 +1,121 @@ +#!/usr/bin/perl +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +use strict; + +my $src; +my $makefile; +my $pkg; +my %category; +my $cur_menu; + +sub print_category($) { + my $cat = shift; + + return unless $category{$cat}; + + print "menu \"$cat\"\n\n"; + my %spkg = %{$category{$cat}}; + foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) { + foreach my $pkg (@{$spkg{$spkg}}) { + if ($cur_menu ne $pkg->{submenu}) { + if ($cur_menu) { + print "endmenu\n"; + undef $cur_menu; + } + if ($pkg->{submenu}) { + $cur_menu = $pkg->{submenu}; + print "menu \"$cur_menu\"\n"; + } + } + my $title = $pkg->{name}; + my $c = (72 - length($pkg->{name}) - length($pkg->{title})); + if ($c > 0) { + $title .= ("." x $c). " ". $pkg->{title}; + } + print "\t"; + $pkg->{menu} and print "menu"; + print "config PACKAGE_".$pkg->{name}."\n"; + print "\t\ttristate \"$title\"\n"; + foreach my $default (split /\s*,\s*/, $pkg->{default}) { + print "\t\tdefault $default\n"; + } + foreach my $depend (@{$pkg->{depends}}) { + my $m = "depends"; + $depend =~ s/^([@\+]+)//; + my $flags = $1; + $flags =~ /@/ or $depend = "PACKAGE_$depend"; + $flags =~ /\+/ and $m = "select"; + print "\t\t$m $depend\n"; + } + print "\t\thelp\n"; + print $pkg->{description}; + print "\n"; + + $pkg->{config} and print $pkg->{config}."\n"; + } + } + print "endmenu\n\n"; + + undef $category{$cat}; +} + +my $line; +while ($line = <>) { + chomp $line; + $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do { + $makefile = $1; + $src = $2; + undef $pkg; + }; + $line =~ /^Package: \s*(.+)\s*$/ and do { + $pkg = {}; + $pkg->{src} = $src; + $pkg->{makefile} = $makefile; + $pkg->{name} = $1; + $pkg->{default} = "m if ALL"; + }; + $line =~ /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1; + $line =~ /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1; + $line =~ /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1; + $line =~ /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1; + $line =~ /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1; + $line =~ /^Depends: \s*(.+)\s*$/ and do { + my @dep = split /\s+/, $1; + $pkg->{depends} = \@dep; + }; + $line =~ /^Category: \s*(.+)\s*$/ and do { + $pkg->{category} = $1; + defined $category{$1} or $category{$1} = {}; + defined $category{$1}->{$src} or $category{$1}->{$src} = []; + push @{$category{$1}->{$src}}, $pkg; + }; + $line =~ /^Description: \s*(.*)\s*$/ and do { + my $desc = "\t\t$1\n\n"; + my $line; + while ($line = <>) { + last if $line =~ /^@@/; + $desc .= "\t\t$line"; + } + $pkg->{description} = $desc; + }; + $line =~ /^Config: \s*(.*)\s*$/ and do { + my $conf = "$1\n"; + my $line; + while ($line = <>) { + last if $line =~ /^@@/; + $conf .= "$line"; + } + $pkg->{config} = $conf; + } +} + +print_category 'Base system'; +foreach my $cat (keys %category) { + print_category $cat; +} diff --git a/openwrt/package/sdk/files/scripts/ipkg b/openwrt/package/sdk/files/scripts/ipkg new file mode 100755 index 0000000000..4d3ad85065 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/ipkg @@ -0,0 +1,1189 @@ +#!/bin/sh +# ipkg - the itsy package management system +# +# Copyright (C) 2001 Carl D. Worth +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +set -e + +# By default do not do globbing. Any command wanting globbing should +# explicitly enable it first and disable it afterwards. +set -o noglob + +ipkg_is_upgrade () { + local A B a b + A=$(echo $1 | sed -r "s/([0-9]+)[^[:alnum:]]*/ \1 /g"). + B=$(echo $2 | sed -r "s/([0-9]+)[^[:alnum:]]*/ \1 /g"). + while [ \! -z "$A" ] && [ \! -z "$B" ]; do { + set $A; a=$1; shift; A=$* + set $B; b=$1; shift; B=$* + [ "$a" -lt "$b" ] 2>&- && return 1 + { [ "$a" -gt "$b" ] 2>&- || [ "$a" ">" "$b" ]; } && return + }; done + return 1 +} + +ipkg_srcs() { + local srcre="$1" + sed -ne "s/^src[[:space:]]\+$srcre[[:space:]]\+//p" < $IPKG_CONF +} + +ipkg_src_names() { + sed -ne "s/^src[[:space:]]\+\([^[:space:]]\+\).*/\1/p" < $IPKG_CONF +} + +ipkg_src_byname() { + local src="$1" + ipkg_srcs $src | head -n 1 +} + +ipkg_dests() { + local destre="`echo $1 | ipkg_protect_slashes`" + sed -ne "/^dest[[:space:]]\+$destre/{ +s/^dest[[:space:]]\+[^[:space:]]\+[[:space:]]\+// +s/^/`echo $IPKG_OFFLINE_ROOT | ipkg_protect_slashes`/ +p +}" < $IPKG_CONF +} + +ipkg_dest_names() { + sed -ne "s/^dest[[:space:]]\+\([^[:space:]]\+\).*/\1/p" < $IPKG_CONF +} + +ipkg_dests_all() { + ipkg_dests '.*' +} + +ipkg_state_dirs() { + ipkg_dests_all | sed "s|\$|/$IPKG_DIR_PREFIX|" +} + +ipkg_dest_default() { + ipkg_dests_all | head -n 1 +} + +ipkg_dest_default_name() { + ipkg_dest_names | head -n 1 +} + +ipkg_dest_byname() { + local dest="$1" + ipkg_dests $dest | head -n 1 +} + +ipkg_option() { + local option="$1" + sed -ne "s/^option[[:space:]]\+$option[[:space:]]\+//p" < $IPKG_CONF +} + +ipkg_load_configuration() { + if [ -z "$IPKG_CONF_DIR" ]; then + IPKG_CONF_DIR=/etc + fi + + IPKG_CONF="$IPKG_CONF_DIR/ipkg.conf" + + if [ -z "$IPKG_OFFLINE_ROOT" ]; then + IPKG_OFFLINE_ROOT="`ipkg_option offline_root`" + fi + # Export IPKG_OFFLINE_ROOT for use by update-alternatives + export IPKG_OFFLINE_ROOT + if [ -n "$DEST_NAME" ]; then + IPKG_ROOT="`ipkg_dest_byname $DEST_NAME`" + if [ -z "$IPKG_ROOT" ]; then + if [ -d "$IPKG_OFFLINE_ROOT$DEST_NAME" ]; then + IPKG_ROOT="$IPKG_OFFLINE_ROOT$DEST_NAME"; + else + echo "ipkg: invalid destination specification: $DEST_NAME +Valid destinations are directories or one of the dest names from $IPKG_CONF:" >&2 + ipkg_dest_names >&2 + return 1 + fi + fi + else + IPKG_ROOT="`ipkg_dest_default`" + fi + + # Global ipkg state directories + IPKG_DIR_PREFIX=usr/lib/ipkg + IPKG_LISTS_DIR=$IPKG_OFFLINE_ROOT/$IPKG_DIR_PREFIX/lists + IPKG_PENDING_DIR=$IPKG_OFFLINE_ROOT/$IPKG_DIR_PREFIX/pending + if [ -z "$IPKG_TMP" ]; then + IPKG_TMP=$IPKG_ROOT/tmp/ipkg + fi + + [ -e "$IPKG_TMP" ] || mkdir -p $IPKG_TMP + + # Destination specific ipkg meta-data directory + IPKG_STATE_DIR=$IPKG_ROOT/$IPKG_DIR_PREFIX + + # Proxy Support + IPKG_PROXY_USERNAME="`ipkg_option proxy_username`" + IPKG_PROXY_PASSWORD="`ipkg_option proxy_password`" + IPKG_HTTP_PROXY="`ipkg_option http_proxy`" + IPKG_FTP_PROXY="`ipkg_option ftp_proxy`" + IPKG_NO_PROXY="`ipkg_option no_proxy`" + if [ -n "$IPKG_HTTP_PROXY" ]; then + export http_proxy="$IPKG_HTTP_PROXY" + fi + + if [ -n "$IPKG_FTP_PROXY" ]; then + export ftp_proxy="$IPKG_FTP_PROXY" + fi + + if [ -n "$IPKG_NO_PROXY" ]; then + export no_proxy="$IPKG_NO_PROXY" + fi + + IPKG_STATUS_FIELDS='\(Package\|Status\|Essential\|Version\|Conffiles\|Root\)' +} + +ipkg_usage() { + [ $# -gt 0 ] && echo "ipkg: $*" + echo " +usage: ipkg [options...] sub-command [arguments...] +where sub-command is one of: + +Package Manipulation: + update Update list of available packages + upgrade Upgrade all installed packages to latest version + install Download and install (and dependencies) + install Install package + install Install package + remove Remove package + +Informational Commands: + list List available packages and descriptions + files List all files belonging to + search Search for a packaging providing + info [pkg []] Display all/some info fields for or all + status [pkg []] Display all/some status fields for or all + depends Print uninstalled package dependencies for + +Options: + -d Use as the the root directory for + -dest package installation, removal, upgrading. + should be a defined dest name from the + configuration file, (but can also be a directory + name in a pinch). + -o Use as the root for offline installation. + -offline + +Force Options (use when ipkg is too smart for its own good): + -force-depends Make dependency checks warnings instead of errors + -force-defaults Use default options for questions asked by ipkg. + (no prompts). Note that this will not prevent + package installation scripts from prompting. +" >&2 + exit 1 +} + +ipkg_dir_part() { + local dir="`echo $1 | sed -ne 's/\(.*\/\).*/\1/p'`" + if [ -z "$dir" ]; then + dir="./" + fi + echo $dir +} + +ipkg_file_part() { + echo $1 | sed 's/.*\///' +} + +ipkg_protect_slashes() { + sed -e 's/\//\\\//g' +} + +ipkg_download() { + local src="$1" + local dest="$2" + + local src_file="`ipkg_file_part $src`" + local dest_dir="`ipkg_dir_part $dest`" + if [ -z "$dest_dir" ]; then + dest_dir="$IPKG_TMP" + fi + + local dest_file="`ipkg_file_part $dest`" + if [ -z "$dest_file" ]; then + dest_file="$src_file" + fi + + # Proxy support + local proxyuser="" + local proxypassword="" + local proxyoption="" + + if [ -n "$IPKG_PROXY_USERNAME" ]; then + proxyuser="--proxy-user=\"$IPKG_PROXY_USERNAME\"" + proxypassword="--proxy-passwd=\"$IPKG_PROXY_PASSWORD\"" + fi + + if [ -n "$IPKG_PROXY_HTTP" -o -n "$IPKG_PROXY_FTP" ]; then + proxyoption="--proxy=on" + fi + + echo "Downloading $src ..." + rm -f $IPKG_TMP/$src_file + case "$src" in + http://* | ftp://*) + if ! wget --passive-ftp $proxyoption $proxyuser $proxypassword -P $IPKG_TMP $src; then + echo "ipkg_download: ERROR: Failed to retrieve $src, returning $err" + return 1 + fi + mv $IPKG_TMP/$src_file $dest_dir/$dest_file 2>/dev/null + ;; + file:/* ) + ln -s `echo $src | sed 's/^file://'` $dest_dir/$dest_file 2>/dev/null + ;; + *) + echo "DEBUG: $src" + ;; + esac + + echo "Done." + return 0 +} + +ipkg_update() { + if [ ! -e "$IPKG_LISTS_DIR" ]; then + mkdir -p $IPKG_LISTS_DIR + fi + + local err= + for src_name in `ipkg_src_names`; do + local src="`ipkg_src_byname $src_name`" + if ! ipkg_download $src/Packages $IPKG_LISTS_DIR/$src_name; then + echo "ipkg_update: Error downloading $src/Packages to $IPKG_LISTS_DIR/$src_name" >&2 + err=t + else + echo "Updated list of available packages in $IPKG_LISTS_DIR/$src_name" + fi + done + + [ -n "$err" ] && return 1 + + return 0 +} + +ipkg_list() { + for src in `ipkg_src_names`; do + if ipkg_require_list $src; then +# black magic... +sed -ne " +/^Package:/{ +s/^Package:[[:space:]]*\<\([a-z0-9.+-]*$1[a-z0-9.+-]*\).*/\1/ +h +} +/^Description:/{ +s/^Description:[[:space:]]*\(.*\)/\1/ +H +g +s/\\ +/ - / +p +} +" $IPKG_LISTS_DIR/$src + fi + done +} + +ipkg_extract_paragraph() { + local pkg="$1" + sed -ne "/Package:[[:space:]]*$pkg[[:space:]]*\$/,/^\$/p" +} + +ipkg_extract_field() { + local field="$1" +# blacker magic... + sed -ne " +: TOP +/^$field:/{ +p +n +b FIELD +} +d +: FIELD +/^$/b TOP +/^[^[:space:]]/b TOP +p +n +b FIELD +" +} + +ipkg_extract_value() { + sed -e "s/^[^:]*:[[:space:]]*//" +} + +ipkg_require_list() { + [ $# -lt 1 ] && return 1 + local src="$1" + if [ ! -f "$IPKG_LISTS_DIR/$src" ]; then + echo "ERROR: File not found: $IPKG_LISTS_DIR/$src" >&2 + echo " You probably want to run \`ipkg update'" >&2 + return 1 + fi + return 0 +} + +ipkg_info() { + for src in `ipkg_src_names`; do + if ipkg_require_list $src; then + case $# in + 0) + cat $IPKG_LISTS_DIR/$src + ;; + 1) + ipkg_extract_paragraph $1 < $IPKG_LISTS_DIR/$src + ;; + *) + ipkg_extract_paragraph $1 < $IPKG_LISTS_DIR/$src | ipkg_extract_field $2 + ;; + esac + fi + done +} + +ipkg_status_sd() { + [ $# -lt 1 ] && return 0 + sd="$1" + shift + if [ -f $sd/status ]; then + case $# in + 0) + cat $sd/status + ;; + 1) + ipkg_extract_paragraph $1 < $sd/status + ;; + *) + ipkg_extract_paragraph $1 < $sd/status | ipkg_extract_field $2 + ;; + esac + fi + return 0 +} + +ipkg_status_all() { + for sd in `ipkg_state_dirs`; do + ipkg_status_sd $sd $* + done +} + +ipkg_status() { + if [ -n "$DEST_NAME" ]; then + ipkg_status_sd $IPKG_STATE_DIR $* + else + ipkg_status_all $* + fi +} + +ipkg_status_matching_sd() { + local sd="$1" + local re="$2" + if [ -f $sd/status ]; then + sed -ne " +: TOP +/^Package:/{ +s/^Package:[[:space:]]*// +s/[[:space:]]*$// +h +} +/$re/{ +g +p +b NEXT +} +d +: NEXT +/^$/b TOP +n +b NEXT +" < $sd/status + fi + return 0 +} + +ipkg_status_matching_all() { + for sd in `ipkg_state_dirs`; do + ipkg_status_matching_sd $sd $* + done +} + +ipkg_status_matching() { + if [ -n "$DEST_NAME" ]; then + ipkg_status_matching_sd $IPKG_STATE_DIR $* + else + ipkg_status_matching_all $* + fi +} + +ipkg_status_installed_sd() { + local sd="$1" + local pkg="$2" + ipkg_status_sd $sd $pkg Status | grep -q "Status: install ok installed" +} + +ipkg_status_installed_all() { + local ret=1 + for sd in `ipkg_state_dirs`; do + if `ipkg_status_installed_sd $sd $*`; then + ret=0 + fi + done + return $ret +} + +ipkg_status_mentioned_sd() { + local sd="$1" + local pkg="$2" + [ -n "`ipkg_status_sd $sd $pkg Status`" ] +} + +ipkg_files() { + local pkg="$1" + if [ -n "$DEST_NAME" ]; then + dests=$IPKG_ROOT + else + dests="`ipkg_dests_all`" + fi + for dest in $dests; do + if [ -f $dest/$IPKG_DIR_PREFIX/info/$pkg.list ]; then + dest_sed="`echo $dest | ipkg_protect_slashes`" + sed -e "s/^/$dest_sed/" < $dest/$IPKG_DIR_PREFIX/info/$pkg.list + fi + done +} + +ipkg_search() { + local pattern="$1" + + for dest_name in `ipkg_dest_names`; do + dest="`ipkg_dest_byname $dest_name`" + dest_sed="`echo $dest | ipkg_protect_slashes`" + + set +o noglob + local list_files="`ls -1 $dest/$IPKG_DIR_PREFIX/info/*.list 2>/dev/null`" + set -o noglob + for file in $list_files; do + if sed "s/^/$dest_sed/" $file | grep -q $pattern; then + local pkg="`echo $file | sed "s/^.*\/\(.*\)\.list/\1/"`" + [ "$dest_name" != `ipkg_dest_default_name` ] && pkg="$pkg ($dest_name)" + sed "s/^/$dest_sed/" $file | grep $pattern | sed "s/^/$pkg: /" + fi + done + done +} + +ipkg_status_remove_sd() { + local sd="$1" + local pkg="$2" + + if [ ! -f $sd/status ]; then + mkdir -p $sd + touch $sd/status + fi + sed -ne "/Package:[[:space:]]*$pkg[[:space:]]*\$/,/^\$/!p" < $sd/status > $sd/status.new + mv $sd/status.new $sd/status +} + +ipkg_status_remove_all() { + for sd in `ipkg_state_dirs`; do + ipkg_status_remove_sd $sd $* + done +} + +ipkg_status_remove() { + if [ -n "$DEST_NAME" ]; then + ipkg_status_remove_sd $IPKG_STATE_DIR $* + else + ipkg_status_remove_all $* + fi +} + +ipkg_status_update_sd() { + local sd="$1" + local pkg="$2" + + ipkg_status_remove_sd $sd $pkg + ipkg_extract_field "$IPKG_STATUS_FIELDS" >> $sd/status + echo "" >> $sd/status +} + +ipkg_status_update() { + ipkg_status_update_sd $IPKG_STATE_DIR $* +} + +ipkg_unsatisfied_dependences() { + local pkg=$1 + local deps="`ipkg_get_depends $pkg`" + local remaining_deps= + for dep in $deps; do + local installed="`ipkg_get_installed $dep`" + if [ "$installed" != "installed" ] ; then + remaining_deps="$remaining_deps $dep" + fi + done + ## echo "ipkg_unsatisfied_dependences pkg=$pkg $remaining_deps" > /dev/console + echo $remaining_deps +} + +ipkg_safe_pkg_name() { + local pkg=$1 + local spkg="`echo pkg_$pkg | sed -e y/-+./___/`" + echo $spkg +} + +ipkg_set_depends() { + local pkg=$1; shift + local new_deps="$*" + pkg="`ipkg_safe_pkg_name $pkg`" + ## setvar ${pkg}_depends "$new_deps" + echo $new_deps > $IPKG_TMP/${pkg}.depends +} + +ipkg_get_depends() { + local pkg=$1 + pkg="`ipkg_safe_pkg_name $pkg`" + cat $IPKG_TMP/${pkg}.depends + ## eval "echo \$${pkg}_depends" +} + +ipkg_set_installed() { + local pkg=$1 + pkg="`ipkg_safe_pkg_name $pkg`" + echo installed > $IPKG_TMP/${pkg}.installed + ## setvar ${pkg}_installed "installed" +} + +ipkg_set_uninstalled() { + local pkg=$1 + pkg="`ipkg_safe_pkg_name $pkg`" + ### echo ipkg_set_uninstalled $pkg > /dev/console + echo uninstalled > $IPKG_TMP/${pkg}.installed + ## setvar ${pkg}_installed "uninstalled" +} + +ipkg_get_installed() { + local pkg=$1 + pkg="`ipkg_safe_pkg_name $pkg`" + if [ -f $IPKG_TMP/${pkg}.installed ]; then + cat $IPKG_TMP/${pkg}.installed + fi + ## eval "echo \$${pkg}_installed" +} + +ipkg_depends() { + local new_pkgs="$*" + local all_deps= + local installed_pkgs="`ipkg_status_matching_all 'Status:.*[[:space:]]installed'`" + for pkg in $installed_pkgs; do + ipkg_set_installed $pkg + done + while [ -n "$new_pkgs" ]; do + all_deps="$all_deps $new_pkgs" + local new_deps= + for pkg in $new_pkgs; do + if echo $pkg | grep -q '[^a-z0-9.+-]'; then + echo "ipkg_depends: ERROR: Package name $pkg contains illegal characters (should be [a-z0-9.+-])" >&2 + return 1 + fi + # TODO: Fix this. For now I am ignoring versions and alternations in dependencies. + new_deps="$new_deps "`ipkg_info $pkg '\(Pre-\)\?Depends' | ipkg_extract_value | sed -e 's/([^)]*)//g +s/\(|[[:space:]]*[a-z0-9.+-]\+[[:space:]]*\)\+//g +s/,/ /g +s/ \+/ /g'` + ipkg_set_depends $pkg $new_deps + done + + new_deps=`echo $new_deps | sed -e 's/[[:space:]]\+/\n/g' | sort | uniq` + + local maybe_new_pkgs= + for pkg in $new_deps; do + if ! echo $installed_pkgs | grep -q "\<$pkg\>"; then + maybe_new_pkgs="$maybe_new_pkgs $pkg" + fi + done + + new_pkgs= + for pkg in $maybe_new_pkgs; do + if ! echo $all_deps | grep -q "\<$pkg\>"; then + if [ -z "`ipkg_info $pkg`" ]; then + echo "ipkg_depends: Warning: $pkg mentioned in dependency but no package found in $IPKG_LISTS_DIR" >&2 + ipkg_set_installed $pkg + else + new_pkgs="$new_pkgs $pkg" + ipkg_set_uninstalled $pkg + fi + else + ipkg_set_uninstalled $pkg + fi + done + done + + echo $all_deps +} + +ipkg_get_install_dest() { + local dest="$1" + shift + local sd=$dest/$IPKG_DIR_PREFIX + local info_dir=$sd/info + + local requested_pkgs="$*" + local pkgs="`ipkg_depends $*`" + + mkdir -p $info_dir + for pkg in $pkgs; do + if ! ipkg_status_mentioned_sd $sd $pkg; then + echo "Package: $pkg +Status: install ok not-installed" | ipkg_status_update_sd $sd $pkg + fi + done + ## mark the packages that we were directly requested to install as uninstalled + for pkg in $requested_pkgs; do ipkg_set_uninstalled $pkg; done + + local new_pkgs= + local pkgs_installed=0 + while [ -n "pkgs" ]; do + curcheck=0 + ## echo "pkgs to install: {$pkgs}" > /dev/console + for pkg in $pkgs; do + curcheck="`expr $curcheck + 1`" + local is_installed="`ipkg_get_installed $pkg`" + if [ "$is_installed" = "installed" ]; then + echo "$pkg is installed" > /dev/console + continue + fi + + local remaining_deps="`ipkg_unsatisfied_dependences $pkg`" + if [ -n "$remaining_deps" ]; then + new_pkgs="$new_pkgs $pkg" + ### echo "Dependences not satisfied for $pkg: $remaining_deps" + if [ $curcheck -ne `echo $pkgs|wc -w` ]; then + continue + fi + fi + + local filename= + for src in `ipkg_src_names`; do + if ipkg_require_list $src; then + filename="`ipkg_extract_paragraph $pkg < $IPKG_LISTS_DIR/$src | ipkg_extract_field Filename | ipkg_extract_value`" + [ -n "$filename" ] && break + fi + done + + if [ -z "$filename" ]; then + echo "ipkg_get_install: ERROR: Cannot find package $pkg in $IPKG_LISTS_DIR" + echo "ipkg_get_install: Check the spelling and maybe run \`ipkg update'." + ipkg_status_remove_sd $sd $pkg + return 1; + fi + + echo "" + local tmp_pkg_file="$IPKG_TMP/"`ipkg_file_part $filename` + if ! ipkg_download `ipkg_src_byname $src`/$filename $tmp_pkg_file; then + echo "ipkg_get_install: Perhaps you need to run \`ipkg update'?" + return 1 + fi + + if ! ipkg_install_file_dest $dest $tmp_pkg_file; then + echo "ipkg_get_install: ERROR: Failed to install $tmp_pkg_file" + echo "ipkg_get_install: I'll leave it there for you to try a manual installation" + return 1 + fi + + ipkg_set_installed $pkg + pkgs_installed="`expr $pkgs_installed + 1`" + rm $tmp_pkg_file + done + ### echo "Installed $pkgs_installed package(s) this round" + if [ $pkgs_installed -eq 0 ]; then + if [ -z "$new_pkgs" ]; then + break + fi + fi + pkgs_installed=0 + pkgs="$new_pkgs" + new_pkgs= + curcheck=0 + done +} + +ipkg_get_install() { + ipkg_get_install_dest $IPKG_ROOT $* +} + +ipkg_install_file_dest() { + local dest="$1" + local filename="$2" + local sd=$dest/$IPKG_DIR_PREFIX + local info_dir=$sd/info + + if [ ! -f "$filename" ]; then + echo "ipkg_install_file: ERROR: File $filename not found" + return 1 + fi + + local pkg="`ipkg_file_part $filename | sed 's/\([a-z0-9.+-]\+\)_.*/\1/'`" + local ext="`echo $filename | sed 's/.*\.//'`" + local pkg_extract_stdout + if [ "$ext" = "ipk" ]; then + pkg_extract_stdout="tar -xzOf" + elif [ "$ext" = "deb" ]; then + pkg_extract_stdout="ar p" + else + echo "ipkg_install_file: ERROR: File $filename has unknown extension $ext (not .ipk or .deb)" + return 1 + fi + + # Check dependencies + local depends="`ipkg_depends $pkg | sed -e "s/\<$pkg\>//"`" + + # Don't worry about deps that are scheduled for installation + local missing_deps= + for dep in $depends; do + if ! ipkg_status_all $dep | grep -q 'Status:[[:space:]]install'; then + missing_deps="$missing_deps $dep" + fi + done + + if [ ! -z "$missing_deps" ]; then + if [ -n "$FORCE_DEPENDS" ]; then + echo "ipkg_install_file: Warning: $pkg depends on the following uninstalled programs: $missing_deps" + else + echo "ipkg_install_file: ERROR: $pkg depends on the following uninstalled programs: + $missing_deps" + echo "ipkg_install_file: You may want to use \`ipkg install' to install these." + return 1 + fi + fi + + mkdir -p $IPKG_TMP/$pkg/control + mkdir -p $IPKG_TMP/$pkg/data + mkdir -p $info_dir + + if ! $pkg_extract_stdout $filename ./control.tar.gz | (cd $IPKG_TMP/$pkg/control; tar -xzf - ) ; then + echo "ipkg_install_file: ERROR unpacking control.tar.gz from $filename" + return 1 + fi + + if [ -n "$IPKG_OFFLINE_ROOT" ]; then + if grep -q '^InstallsOffline:[[:space:]]*no' $IPKG_TMP/$pkg/control/control; then + echo "*** Warning: Package $pkg may not be installed in offline mode" + echo "*** Warning: Scheduling $filename for pending installation (installing into $IPKG_PENDING_DIR)" + echo "Package: $pkg +Status: install ok pending" | ipkg_status_update_sd $sd $pkg + mkdir -p $IPKG_PENDING_DIR + cp -f $filename $IPKG_PENDING_DIR + rm -r $IPKG_TMP/$pkg/control + rm -r $IPKG_TMP/$pkg/data + rmdir $IPKG_TMP/$pkg + return 0 + fi + fi + + + echo -n "Unpacking $pkg..." + set +o noglob + for file in $IPKG_TMP/$pkg/control/*; do + local base_file="`ipkg_file_part $file`" + mv $file $info_dir/$pkg.$base_file + done + set -o noglob + rm -r $IPKG_TMP/$pkg/control + + if ! $pkg_extract_stdout $filename ./data.tar.gz | (cd $IPKG_TMP/$pkg/data; tar -xzf - ) ; then + echo "ipkg_install_file: ERROR unpacking data.tar.gz from $filename" + return 1 + fi + echo "Done." + + echo -n "Configuring $pkg..." + export PKG_ROOT=$dest + if [ -x "$info_dir/$pkg.preinst" ]; then + if ! $info_dir/$pkg.preinst install; then + echo "$info_dir/$pkg.preinst failed. Aborting installation of $pkg" + rm -rf $IPKG_TMP/$pkg/data + rmdir $IPKG_TMP/$pkg + return 1 + fi + fi + + local old_conffiles="`ipkg_status_sd $sd $pkg Conffiles | ipkg_extract_value`" + local new_conffiles= + if [ -f "$info_dir/$pkg.conffiles" ]; then + for conffile in `cat $info_dir/$pkg.conffiles`; do + if [ -f "$dest/$conffile" ] && ! echo " $old_conffiles " | grep -q " $conffile "`md5sum $dest/$conffile | sed 's/ .*//'`; then + local use_maintainers_conffile= + if [ -z "$FORCE_DEFAULTS" ]; then + while true; do + echo -n "Configuration file \`$conffile' + ==> File on system created by you or by a script. + ==> File also in package provided by package maintainer. + What would you like to do about it ? Your options are: + Y or I : install the package maintainer's version + N or O : keep your currently-installed version + D : show the differences between the versions (if diff is installed) + The default action is to keep your current version. +*** `ipkg_file_part $conffile` (Y/I/N/O/D) [default=N] ? " + read response + case "$response" in + [YyIi] | [Yy][Ee][Ss]) + use_maintainers_conffile=t + break + ;; + [Dd]) + echo " +diff -u $dest/$conffile $IPKG_TMP/$pkg/data/$conffile" + diff -u $dest/$conffile $IPKG_TMP/$pkg/data/$conffile || true + echo "[Press ENTER to continue]" + read junk + ;; + *) + break + ;; + esac + done + fi + if [ -n "$use_maintainers_conffile" ]; then + local md5sum="`md5sum $IPKG_TMP/$pkg/data/$conffile | sed 's/ .*//'`" + new_conffiles="$new_conffiles $conffile $md5sum" + else + new_conffiles="$new_conffiles $conffile " + rm $IPKG_TMP/$pkg/data/$conffile + fi + else + md5sum="`md5sum $IPKG_TMP/$pkg/data/$conffile | sed 's/ .*//'`" + new_conffiles="$new_conffiles $conffile $md5sum" + fi + done + fi + + local owd="`pwd`" + (cd $IPKG_TMP/$pkg/data/; tar cf - . | (cd $owd; cd $dest; tar xf -)) + rm -rf $IPKG_TMP/$pkg/data + rmdir $IPKG_TMP/$pkg + rm -f $info_dir/$pkg.list + $pkg_extract_stdout $filename ./data.tar.gz | tar tzf - | sed -e 's/^\.//' > $info_dir/$pkg.list + + if [ -x "$info_dir/$pkg.postinst" ]; then + $info_dir/$pkg.postinst configure + fi + + if [ -n "$new_conffiles" ]; then + new_conffiles='Conffiles: '`echo $new_conffiles | ipkg_protect_slashes` + fi + local sed_safe_offline_root="`echo ${IPKG_OFFLINE_ROOT} | ipkg_protect_slashes`" + local sed_safe_root="`echo $dest | sed -e "s/^${sed_safe_offline_root}//" | ipkg_protect_slashes`" + sed -e "s/\(Package:.*\)/\1\\ +Status: install ok installed\\ +Root: ${sed_safe_root}\\ +${new_conffiles}/" $info_dir/$pkg.control | ipkg_status_update_sd $sd $pkg + + rm -f $info_dir/$pkg.control + rm -f $info_dir/$pkg.conffiles + rm -f $info_dir/$pkg.preinst + rm -f $info_dir/$pkg.postinst + + echo "Done." +} + +ipkg_install_file() { + ipkg_install_file_dest $IPKG_ROOT $* +} + +ipkg_install() { + + while [ $# -gt 0 ]; do + local pkg="$1" + shift + + case "$pkg" in + http://* | ftp://*) + local tmp_pkg_file="$IPKG_TMP/"`ipkg_file_part $pkg` + if ipkg_download $pkg $tmp_pkg_file; then + ipkg_install_file $tmp_pkg_file + rm $tmp_pkg_file + fi + ;; + file:/*.ipk | file://*.deb) + local ipkg_filename="`echo $pkg|sed 's/^file://'`" + ipkg_install_file $ipkg_filename + ;; + *.ipk | *.deb) + if [ -f "$pkg" ]; then + ipkg_install_file $pkg + else + echo "File not found $pkg" >&2 + fi + ;; + *) + ipkg_get_install $pkg || true + ;; + esac + done +} + +ipkg_install_pending() { + [ -n "$IPKG_OFFLINE_ROOT" ] && return 0 + + if [ -d "$IPKG_PENDING_DIR" ]; then + set +o noglob + local pending="`ls -1d $IPKG_PENDING_DIR/*.ipk 2> /dev/null`" || true + set -o noglob + if [ -n "$pending" ]; then + echo "The following packages in $IPKG_PENDING_DIR will now be installed:" + echo $pending + for filename in $pending; do + if ipkg_install_file $filename; then + rm $filename + fi + done + fi + fi + return 0 +} + +ipkg_install_wanted() { + local wanted="`ipkg_status_matching 'Status:[[:space:]]*install.*not-installed'`" + + if [ -n "$wanted" ]; then + echo "The following package were previously requested but have not been installed:" + echo $wanted + + if [ -n "$FORCE_DEFAULTS" ]; then + echo "Installing them now." + else + echo -n "Install them now [Y/n] ? " + read response + case "$response" in + [Nn] | [Nn][Oo]) + return 0 + ;; + esac + fi + + ipkg_install $wanted + fi + + return 0 +} + +ipkg_upgrade_pkg() { + local pkg="$1" + local avail_ver="`ipkg_info $pkg Version | ipkg_extract_value | head -n 1`" + + is_installed= + for dest_name in `ipkg_dest_names`; do + local dest="`ipkg_dest_byname $dest_name`" + local sd=$dest/$IPKG_DIR_PREFIX + local inst_ver="`ipkg_status_sd $sd $pkg Version | ipkg_extract_value`" + if [ -n "$inst_ver" ]; then + is_installed=t + + if [ -z "$avail_ver" ]; then + echo "Assuming locally installed package $pkg ($inst_ver) is up to date" + return 0 + fi + + if [ "$avail_ver" = "$inst_ver" ]; then + echo "Package $pkg ($inst_ver) installed in $dest_name is up to date" + elif ipkg_is_upgrade "$avail_ver" "$inst_ver"; then + echo "Upgrading $pkg ($dest_name) from $inst_ver to $avail_ver" + ipkg_get_install_dest $dest $pkg + else + echo "Not downgrading package $pkg from $inst_ver to $avail_ver" + fi + fi + done + + if [ -z "$is_installed" ]; then + echo "Package $pkg does not appear to be installed" + return 0 + fi + +} + +ipkg_upgrade() { + if [ $# -lt 1 ]; then + local pkgs="`ipkg_status_matching 'Status:.*[[:space:]]installed'`" + else + pkgs="$*" + fi + + for pkg in $pkgs; do + ipkg_upgrade_pkg $pkg + done +} + +ipkg_remove_pkg_dest() { + local dest="$1" + local pkg="$2" + local sd=$dest/$IPKG_DIR_PREFIX + local info_dir=$sd/info + + if ! ipkg_status_installed_sd $sd $pkg; then + echo "ipkg_remove: Package $pkg does not appear to be installed in $dest" + if ipkg_status_mentioned_sd $sd $pkg; then + echo "Purging mention of $pkg from the ipkg database" + ipkg_status_remove_sd $sd $pkg + fi + return 1 + fi + + echo "ipkg_remove: Removing $pkg... " + + local files="`cat $info_dir/$pkg.list`" + + export PKG_ROOT=$dest + if [ -x "$info_dir/$pkg.prerm" ]; then + $info_dir/$pkg.prerm remove + fi + + local conffiles="`ipkg_status_sd $sd $pkg Conffiles | ipkg_extract_value`" + + local dirs_to_remove= + for file in $files; do + if [ -d "$dest/$file" ]; then + dirs_to_remove="$dirs_to_remove $dest/$file" + else + if echo " $conffiles " | grep -q " $file "; then + if echo " $conffiles " | grep -q " $file "`md5sum $dest/$file | sed 's/ .*//'`; then + rm -f $dest/$file + fi + else + rm -f $dest/$file + fi + fi + done + + local removed_a_dir=t + while [ -n "$removed_a_dir" ]; do + removed_a_dir= + local new_dirs_to_remove= + for dir in $dirs_to_remove; do + if rmdir $dir >/dev/null 2>&1; then + removed_a_dir=t + else + new_dirs_to_remove="$new_dirs_to_remove $dir" + fi + done + dirs_to_remove="$new_dirs_to_remove" + done + + if [ -n "$dirs_to_remove" ]; then + echo "ipkg_remove: Warning: Not removing the following directories since they are not empty:" >&2 + echo "$dirs_to_remove" | sed -e 's/\/[/]\+/\//g' >&2 + fi + + if [ -x "$info_dir/$pkg.postrm" ]; then + $info_dir/$pkg.postrm remove + fi + + ipkg_status_remove_sd $sd $pkg + set +o noglob + rm -f $info_dir/$pkg.* + set -o noglob + + echo "Done." +} + +ipkg_remove_pkg() { + local pkg="$1" + for dest in `ipkg_dests_all`; do + local sd=$dest/$IPKG_DIR_PREFIX + if ipkg_status_mentioned_sd $sd $pkg; then + ipkg_remove_pkg_dest $dest $pkg + fi + done +} + +ipkg_remove() { + while [ $# -gt 0 ]; do + local pkg="$1" + shift + if [ -n "$DEST_NAME" ]; then + ipkg_remove_pkg_dest $IPKG_ROOT $pkg + else + ipkg_remove_pkg $pkg + fi + done +} + +########### +# ipkg main +########### + +# Parse options +while [ $# -gt 0 ]; do + arg="$1" + case $arg in + -d | -dest) + [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument" + DEST_NAME="$2" + shift + ;; + -o | -offline) + [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument" + IPKG_OFFLINE_ROOT="$2" + shift + ;; + -force-depends) + FORCE_DEPENDS=t + ;; + -force-defaults) + FORCE_DEFAULTS=t + ;; + -*) + ipkg_usage "unknown option $arg" + ;; + *) + break + ;; + esac + shift +done + +[ $# -lt 1 ] && ipkg_usage "ipkg must have one sub-command argument" +cmd="$1" +shift + +ipkg_load_configuration +mkdir -p /tmp/ipkg + +case "$cmd" in +update|upgrade|list|info|status|install_pending) + ;; +install|depends|remove|files|search) + [ $# -lt 1 ] && ipkg_usage "ERROR: the \`\`$cmd'' command requires an argument" + ;; +*) + echo "ERROR: unknown sub-command \`$cmd'" + ipkg_usage + ;; +esac + +# Only install pending if we have an interactive sub-command +case "$cmd" in +upgrade|install) + ipkg_install_pending + ipkg_install_wanted + ;; +esac + +ipkg_$cmd $* +for a in `ls $IPKG_TMP`; do + rm -rf $IPKG_TMP/$a +done diff --git a/openwrt/package/sdk/files/scripts/make-ipkg-dir.sh b/openwrt/package/sdk/files/scripts/make-ipkg-dir.sh new file mode 100755 index 0000000000..236cb6feb4 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/make-ipkg-dir.sh @@ -0,0 +1,21 @@ +#!/bin/bash +BASE=http://svn.openwrt.org/openwrt/trunk/openwrt +TARGET=$1 +CONTROL=$2 +VERSION=$3 +ARCH=$4 + +WD=$(pwd) + +mkdir -p "$TARGET/CONTROL" +grep '^[^(Version|Architecture)]' "$CONTROL" > "$TARGET/CONTROL/control" +grep '^Maintainer' "$CONTROL" 2>&1 >/dev/null || \ + echo "Maintainer: OpenWrt Developers Team " >> "$TARGET/CONTROL/control" +grep '^Source' "$CONTROL" 2>&1 >/dev/null || { + pkgbase=$(echo "$WD" | sed -e "s|^$TOPDIR/||g") + [ "$pkgbase" = "$WD" ] && src="N/A" || src="$BASE/$pkgbase" + echo "Source: $src" >> "$TARGET/CONTROL/control" +} +echo "Version: $VERSION" >> "$TARGET/CONTROL/control" +echo "Architecture: $ARCH" >> "$TARGET/CONTROL/control" +chmod 644 "$TARGET/CONTROL/control" diff --git a/openwrt/package/sdk/files/scripts/patch-kernel.sh b/openwrt/package/sdk/files/scripts/patch-kernel.sh new file mode 100755 index 0000000000..5455a0cf8d --- /dev/null +++ b/openwrt/package/sdk/files/scripts/patch-kernel.sh @@ -0,0 +1,54 @@ +#! /bin/sh +# A little script I whipped up to make it easy to +# patch source trees and have sane error handling +# -Erik +# +# (c) 2002 Erik Andersen + +# Set directories from arguments, or use defaults. +targetdir=${1-.} +patchdir=${2-../kernel-patches} +patchpattern=${3-*} + +if [ ! -d "${targetdir}" ] ; then + echo "Aborting. '${targetdir}' is not a directory." + exit 1 +fi +if [ ! -d "${patchdir}" ] ; then + echo "Aborting. '${patchdir}' is not a directory." + exit 1 +fi + +for i in ${patchdir}/${patchpattern} ; do + case "$i" in + *.gz) + type="gzip"; uncomp="gunzip -dc"; ;; + *.bz) + type="bzip"; uncomp="bunzip -dc"; ;; + *.bz2) + type="bzip2"; uncomp="bunzip2 -dc"; ;; + *.zip) + type="zip"; uncomp="unzip -d"; ;; + *.Z) + type="compress"; uncomp="uncompress -c"; ;; + *) + type="plaintext"; uncomp="cat"; ;; + esac + [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue + echo "" + echo "Applying ${i} using ${type}: " + ${uncomp} ${i} | patch -p1 -E -d ${targetdir} + if [ $? != 0 ] ; then + echo "Patch failed! Please fix $i!" + exit 1 + fi +done + +# Check for rejects... +if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then + echo "Aborting. Reject files found." + exit 1 +fi + +# Remove backup files +find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \; diff --git a/openwrt/package/sdk/files/scripts/rstrip.sh b/openwrt/package/sdk/files/scripts/rstrip.sh new file mode 100755 index 0000000000..e63ccf0895 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/rstrip.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + + +SELF=${0##*/} + +[ -z "$STRIP" ] && { + echo "$SELF: strip command not defined (STRIP variable not set)" + exit 1 +} + +TARGETS=$* + +[ -z "$TARGETS" ] && { + echo "$SELF: no directories / files specified" + echo "usage: $SELF [PATH...]" + exit 1 +} + +find $TARGETS -type f -a -exec file {} \; | \ + sed -n -e 's/^\(.*\):.*ELF.*\(executable\|relocatable\|shared object\).*,.* stripped/\1:\2/p' | \ +( + IFS=":" + while read F S; do + echo "$SELF: $F:$S" + [ "${F##*\.}" = "o" -o "${F##*\.}" = "ko" ] && \ + eval "$STRIP_KMOD $F" || \ + eval "$STRIP $F" + done +) diff --git a/openwrt/package/sdk/files/scripts/timestamp.pl b/openwrt/package/sdk/files/scripts/timestamp.pl new file mode 100755 index 0000000000..093ced9935 --- /dev/null +++ b/openwrt/package/sdk/files/scripts/timestamp.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +use strict; + +sub get_ts($$) { + my $path = shift; + my $options = shift; + my $ts = 0; + my $fn = ""; + open FIND, "find $path -not -path \\*.svn\\* -and -not -path \\*CVS\\* $options 2>/dev/null |"; + while () { + chomp; + my $file = $_; + open FILE, "<$file"; + my @stat = stat FILE; + close FILE; + if ($stat[9] > $ts) { + $ts = $stat[9]; + $fn = $file; + } + } + close FIND; + return ($ts, $fn); +} + +(@ARGV > 0) or push @ARGV, "."; +my $ts = 0; +my $n = "."; +my %options; +while (@ARGV > 0) { + my $path = shift @ARGV; + if ($path =~ /^-x/) { + my $str = shift @ARGV; + $options{"-x"} .= " -and -not -path \\*".$str."\\*" + } elsif ($path =~ /^-/) { + $options{$path} = 1; + } else { + my ($tmp, $fname) = get_ts($path, $options{"-x"}); + if ($tmp > $ts) { + if ($options{'-f'}) { + $n = $fname; + } else { + $n = $path; + } + $ts = $tmp; + } + } +} + +if ($options{"-p"}) { + print "$n\n"; +} elsif ($options{"-t"}) { + print "$ts\n"; +} else { + print "$n\t$ts\n"; +} -- 2.30.2