source: trunk/debian/rootfs/debian.mk @ 310

Last change on this file since 310 was 310, checked in by amain, 8 years ago

debian/rootfs/clean: don't remove touch files for package creation ( otherwise packages keep recompiled every time )

File size: 7.2 KB
Line 
1# DebWrt - Debian on Embedded devices
2#
3# Copyright (C) 2010 Johan van Zoomeren <amain@debwrt.net>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18DEBIAN_ROOTFS_INCLUDE_PACKAGES:=$(call qstrip,$(CONFIG_DEBIAN_ROOTFS_INCLUDE_PACKAGES))
19DEBIAN_ROOTFS_QEMU_2ND_STAGE:=$(call qstrip, $(CONFIG_DEBIAN_ROOTFS_QEMU_2ND_STAGE))
20DEBWRT_EXTRA_ROOTFS_FILES_DIR:=$(TOPDIR)/debian/rootfs/files
21DEBWRT_MODULES_ARCHIVE=$(shell ls $(INSTALL_DIR)/debwrt-modules-*.tar.gz 2>/dev/null)
22MODULES_VERSION=$(shell echo `basename $(DEBWRT_MODULES_ARCHIVE) 2>/dev/null` | awk -F '-' '{print $$6}')
23
24chr: debian/rootfs/qemu-check
25        @sudo bash -c "echo "debwrt-$(TARGET_ARCH)" > $(ROOTFS_BUILD_DIR)/etc/debian_chroot"
26        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt
27        @sudo bash -c "cat /etc/resolv.conf | grep nameserver >$(ROOTFS_BUILD_DIR)/etc/resolv.conf"
28        @sudo chroot $(ROOTFS_BUILD_DIR)
29        @sudo rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
30        @sudo rm -f $(ROOTFS_BUILD_DIR)/debian_chroot
31        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt $(ROOTFS_BUILD_DIR)/etc/resolv.conf
32
33debian/rootfs/qemu-check:
34        @if [ ! -x $(QEMU_BIN_STATIC) ]; then echo "E: can't find qemu ($(QEMU_BIN_STATIC))"; fi
35        @if [ ! -e /proc/sys/fs/binfmt_misc/qemu-$(TARGET_ARCH) ]; then echo "E: can't find binfmt_misc qemu-$(TARGET_ARCH) ( /proc/sys/fs/binfmt_misc/qemu-$(TARGET_ARCH)).\nE: install qemu-user-static, or\nE: disable second stage with qemu with menuconfig (DEBIAN_ROOTFS_QEMU_2ND_STAGE)."; fi
36        @if [ ! -x $(QEMU_BIN_STATIC) -o ! -e /proc/sys/fs/binfmt_misc/qemu-$(TARGET_ARCH) ]; then echo "E: abort"; exit 1; fi
37        @sudo cp $(QEMU_BIN_STATIC) $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
38        @if ! sudo chroot $(ROOTFS_BUILD_DIR) /bin/ls >/dev/null; then echo "E: qemu can't execute binaries for $(TARGET_ARCH)"; echo "E: abort"; exit 1; fi
39
40debian/rootfs: debian/rootfs/bootstrap         \
41               debian/rootfs/unpack            \
42               debian/rootfs/files-install     \
43               debian/rootfs/debwrt-packages   \
44               debian/rootfs/modules-install   \
45               debian/rootfs/post-setup        \
46               debian/rootfs/second-stage-qemu
47        touch $@
48
49debian/rootfs/install: debian/rootfs
50        if [ -d /media/DEBWRT_ROOT ]; then \
51                sudo rm -rf /media/DEBWRT_ROOT/*; \
52                sudo bash -c "tar cf - -C $(ROOTFS_BUILD_DIR) . | tar xf - -C /media/DEBWRT_ROOT"; \
53        fi
54        #touch $@
55
56debian/rootfs/save:
57        if [ -d /media/DEBWRT_ROOT ]; then \
58                sudo bash -c "tar cjf debwrt-rootfs-$(TARGET_ARCH)-$(VERSION).tar.bz2 -C /media/DEBWRT_ROOT ."; \
59        fi
60
61debian/rootfs/files-install: debian/rootfs/bootstrap
62        if [ ! -f $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian -a -e $(ROOTFS_BUILD_DIR)/etc/init.d/rcS ]; then \
63                sudo mv -v $(ROOTFS_BUILD_DIR)/etc/init.d/rcS $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian; \
64        fi
65        if [ ! -p $(ROOTFS_BUILD_DIR)/dev/initctl ]; then  \
66                sudo mkdir -p $(ROOTFS_BUILD_DIR)/dev;         \
67                sudo mkfifo   $(ROOTFS_BUILD_DIR)/dev/initctl; \
68        fi
69        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_rsa_key
70        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_dsa_key
71        sudo bash -c "tar cf - --exclude=".svn" -C $(DEBWRT_EXTRA_ROOTFS_FILES_DIR) . | tar -xovf - -C $(ROOTFS_BUILD_DIR)"
72        sudo cat $(ROOTFS_BUILD_DIR)/etc/securetty \
73                $(TOPDIR)/debian/rootfs/securetty.tail \
74                >> $(TOPDIR)/securetty.temp
75        sudo mv $(TOPDIR)/securetty.temp $(ROOTFS_BUILD_DIR)/etc/securetty
76        touch $@
77
78debian/rootfs/modules-install: debian/rootfs/bootstrap
79ifneq ($(DEBWRT_MODULES_ARCHIVE),)
80        sudo tar xof $(DEBWRT_MODULES_ARCHIVE) -C $(ROOTFS_BUILD_DIR)
81        #sudo depmod -a -b $(ROOTFS_BUILD_DIR) $(MODULES_VERSION)
82endif
83        touch $@
84
85debian/rootfs/bootstrap: debian/rootfs/clean-rootfs-dir
86        sudo debootstrap --arch=$(TARGET_ARCH)\
87                     --foreign \
88                     --include=$(shell grep -v '^#' \
89                       $(DEBIAN_ROOTFS_INCLUDE_PACKAGES) \
90                         | tr '\n' , | sed -e 's/^/"/' -e 's/,$$/"/' ) \
91                     $(DEBIAN_BUILD_VERSION) \
92                     $(ROOTFS_BUILD_DIR) \
93                     $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
94        # complete ROOTFS/dev/ with additional device files
95        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v consoleonly"
96        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v sda"
97        touch $@
98
99debian/rootfs/unpack: debian/rootfs/bootstrap
100        find $(ROOTFS_BUILD_DIR) -name "*.deb" | while read deb; do \
101                n=`basename $$deb`; \
102                echo -n "I: Extracting $${n}..."; \
103                sudo bash -c "dpkg --extract "$$deb" $(ROOTFS_BUILD_DIR)" ; \
104                echo "done"; \
105        done
106        touch $@
107
108# install all available cross-compiled debwrt debian packages, except for the kernel-headers package and the cross packages
109debian/rootfs/debwrt-packages: debian/rootfs/bootstrap debian/package/rootfs
110        ls ${INSTALL_DIR_DEBIAN_PACKAGES}/*.deb | grep -v "debwrt-kernel-headers" | grep -v "cross" | while read package; do \
111                pfname=`basename $$package`; \
112                pname=`echo $$pfname | sed 's/_.*//'`; \
113                echo "Installing DebWrt package: $$pname"; \
114                sudo cp $$package $(ROOTFS_BUILD_DIR)/var/cache/apt/archives; \
115                sudo dpkg-deb -x $$package $(ROOTFS_BUILD_DIR); \
116                sudo bash -c "echo \"$$pname /var/cache/apt/archives/$$pfname\" >>$(ROOTFS_BUILD_DIR)/debootstrap/debpaths" ;\
117                sudo sed -i "s/$$/$$pname /" $(ROOTFS_BUILD_DIR)/debootstrap/base ;\
118        done
119        touch $@
120       
121debian/rootfs/clean-rootfs-dir:
122        mkdir -p $(BUILD_DIR_BASE)
123        sudo rm -rf $(ROOTFS_BUILD_DIR)
124        touch $@
125
126debian/rootfs/post-setup: debian/rootfs/bootstrap
127        sudo mkdir -p $(ROOTFS_BUILD_DIR)/etc/apt
128        # note: unfortunately /etc/apt/sources.list is cleaned after running second stage install
129        sudo bash -c "echo \"deb $(call qstrip,$(DEBIAN_BUILDENV_REPOSITORY)) $(DEBIAN_BUILD_VERSION) main\" > $(ROOTFS_BUILD_DIR)/etc/apt/sources.list"
130        sudo bash -c "echo \"$(DEBWRTVERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debwrt_version"
131        sudo bash -c "echo \"$(DEBIAN_BUILD_VERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debian_release"
132        touch $@
133
134ifeq ($(DEBIAN_ROOTFS_QEMU_2ND_STAGE),y)
135debian/rootfs/second-stage-qemu: debian/rootfs/bootstrap debian/buildenv/qemu-build debian/rootfs/qemu-check
136        sudo chroot $(ROOTFS_BUILD_DIR) /usr/sbin/PostInstall && sudo rm -f $(ROOTFS_BUILD_DIR)/usr/sbin/PostInstall
137        sudo rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
138else
139debian/rootfs/second-stage-qemu: debian/rootfs/bootstrap debian/buildenv/qemu-build
140        @echo "I: Qemu 2nd stage install disabled. Second stage needs now to be performend on the target device itself."
141        @echo "I: Qemu 2nd stage install can be enabled using menuconfig (DEBIAN_ROOTFS_QEMU_2ND_STAGE)."
142endif
143        touch $@
144
145debian/rootfs/clean: 
146        sudo rm -rf $(ROOTFS_BUILD_DIR)
147        rm -f debian/rootfs/debwrt-packages
148        rm -f debian/rootfs/bootstrap
149        rm -f debian/rootfs/install
150        rm -f debian/rootfs/files-install
151        rm -f debian/rootfs/modules-install
Note: See TracBrowser for help on using the repository browser.