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

Last change on this file since 545 was 545, checked in by amain, 6 years ago

rootfs: backport r544 to trunk

File size: 8.3 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}')
23DEBIAN_ROOTFS_INCLUDE_PACKAGES_DEBIAN_VERSION:=$(wildcard debian/rootfs/include_packages.list.$(DEBIAN_BUILD_VERSION))
24
25define qemu-prepare-enter
26        @if [ ! -x $(QEMU_BIN_STATIC) ]; then echo "E: can't find qemu ($(QEMU_BIN_STATIC))"; fi
27        @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
28        @if [ ! -x $(QEMU_BIN_STATIC) -o ! -e /proc/sys/fs/binfmt_misc/qemu-$(TARGET_ARCH) ]; then echo "E: abort"; exit 1; fi
29        @sudo cp $(QEMU_BIN_STATIC) $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
30        @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
31endef
32
33chr:
34        $(call qemu-prepare-enter)
35        @sudo bash -c "echo "debwrt-$(TARGET_ARCH)" > $(ROOTFS_BUILD_DIR)/etc/debian_chroot"
36        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt
37        @sudo bash -c "cat /etc/resolv.conf | grep nameserver >$(ROOTFS_BUILD_DIR)/etc/resolv.conf"
38        @sudo chroot $(ROOTFS_BUILD_DIR)
39        @sudo rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
40        @sudo rm -f $(ROOTFS_BUILD_DIR)/etc/debian_chroot
41        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt $(ROOTFS_BUILD_DIR)/etc/resolv.conf
42
43debian/rootfs: debian/rootfs/bootstrap         \
44               debian/rootfs/unpack            \
45               debian/rootfs/files-install     \
46               debian/rootfs/debwrt-packages   \
47               debian/rootfs/modules-install   \
48               debian/rootfs/post-setup        \
49               debian/rootfs/second-stage-qemu \
50               debian/rootfs/save
51        @echo "I: root filesystem $(DEBIAN_BUILD_VERSION) $(TARGET_ARCH) prepared in $(ROOTFS_BUILD_DIR)"
52        @echo "I: if the DebWrt kernel wasn't build, then no kernel modules have been installed, install them by:"
53        @echo "I: - make openwrt/all"
54        @echo "I: - make debian/rootfs/modules-install"
55        @echo "I: - or: install manually from alternative source"
56        @echo "I:"
57        @echo "I: install the image to USB-Disk/USB-Stick/SD-Card (make sure it is already mounted at /media/DEBWRT_ROOTFS)"
58        @echo "I: - make debian/rootfs/install"
59        @echo "I:"
60        @echo "I: enter the change root(with qemu) and perform additional post install steps:"
61        @echo "I: - make chr"
62        @echo "I: - apt-get update # example statement ;-) - networking works!"
63        touch $@
64
65debian/rootfs/install: debian/rootfs
66        if [ -d /media/DEBWRT_ROOT ]; then \
67                sudo rm -rf /media/DEBWRT_ROOT/*; \
68                sudo bash -c "tar cf - -C $(ROOTFS_BUILD_DIR) . | tar xf - -C /media/DEBWRT_ROOT"; \
69        fi
70        #touch $@
71
72debian/rootfs/save:
73ifeq ($(DEBIAN_ROOTFS_QEMU_2ND_STAGE),y)
74        sudo bash -c "tar cjf $(INSTALL_DIR)/$(ROOTFS_TAR_BZ2) -C $(ROOTFS_BUILD_DIR) ."
75else
76        if [ -d /media/DEBWRT_ROOT ]; then \
77                sudo bash -c "tar cjf $(ROOTFS_TAR_BZ2) -C /media/DEBWRT_ROOT ."; \
78        fi
79endif
80
81debian/rootfs/files-install: debian/rootfs/bootstrap
82        if [ ! -f $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian -a -e $(ROOTFS_BUILD_DIR)/etc/init.d/rcS ]; then \
83                sudo mv -v $(ROOTFS_BUILD_DIR)/etc/init.d/rcS $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian; \
84        fi
85        if [ ! -p $(ROOTFS_BUILD_DIR)/dev/initctl ]; then  \
86                sudo mkdir -p $(ROOTFS_BUILD_DIR)/dev;         \
87                sudo mkfifo   $(ROOTFS_BUILD_DIR)/dev/initctl; \
88        fi
89        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_rsa_key
90        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_dsa_key
91        sudo bash -c "tar cf - --exclude=".svn" -C $(DEBWRT_EXTRA_ROOTFS_FILES_DIR) . | tar -xovf - -C $(ROOTFS_BUILD_DIR)"
92        sudo cat $(ROOTFS_BUILD_DIR)/etc/securetty \
93                $(TOPDIR)/debian/rootfs/securetty.tail \
94                >> $(TOPDIR)/securetty.temp
95        sudo mv $(TOPDIR)/securetty.temp $(ROOTFS_BUILD_DIR)/etc/securetty
96        touch $@
97
98debian/rootfs/modules-install: debian/rootfs/bootstrap
99ifneq ($(DEBWRT_MODULES_ARCHIVE),)
100        sudo tar xof $(DEBWRT_MODULES_ARCHIVE) -C $(ROOTFS_BUILD_DIR)
101        #sudo depmod -a -b $(ROOTFS_BUILD_DIR) $(MODULES_VERSION)
102else
103        @echo "W: Can't install kernel module to the change root. Kernel modules archive missing. ($(DEBWRT_MODULES_ARCHIVE))"
104endif
105        touch $@
106
107debian/rootfs/bootstrap: debian/rootfs/clean-rootfs-dir
108        sudo debootstrap --arch=$(TARGET_ARCH)\
109                     --foreign \
110                     --include=$(shell grep -hv '^#' \
111                       $(DEBIAN_ROOTFS_INCLUDE_PACKAGES) $(DEBIAN_ROOTFS_INCLUDE_PACKAGES_DEBIAN_VERSION) \
112                         | sort -u | tr '\n' , | sed -e 's/^/"/' -e 's/,$$/"/' ) \
113                     $(DEBIAN_BUILD_VERSION) \
114                     $(ROOTFS_BUILD_DIR) \
115                     $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
116        # complete ROOTFS/dev/ with additional device files
117        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v consoleonly"
118        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v sda"
119        touch $@
120
121debian/rootfs/unpack: debian/rootfs/bootstrap
122        find $(ROOTFS_BUILD_DIR) -name "*.deb" | while read deb; do \
123                n=`basename $$deb`; \
124                echo -n "I: Extracting $${n}..."; \
125                sudo bash -c "dpkg --extract "$$deb" $(ROOTFS_BUILD_DIR)" ; \
126                echo "done"; \
127        done
128        touch $@
129
130# install all available cross-compiled debwrt debian packages, except for the kernel-headers package and the cross packages
131debian/rootfs/debwrt-packages: debian/rootfs/bootstrap debian/package/rootfs
132        ls ${INSTALL_DIR_DEBIAN_PACKAGES}/*.deb | grep -v "debwrt-kernel-headers" | grep -v "cross" | while read package; do \
133                pfname=`basename $$package`; \
134                pname=`echo $$pfname | sed 's/_.*//'`; \
135                echo "Installing DebWrt package: $$pname"; \
136                sudo cp $$package $(ROOTFS_BUILD_DIR)/var/cache/apt/archives; \
137                sudo dpkg-deb -x $$package $(ROOTFS_BUILD_DIR); \
138                sudo bash -c "echo \"$$pname /var/cache/apt/archives/$$pfname\" >>$(ROOTFS_BUILD_DIR)/debootstrap/debpaths" ;\
139                sudo sed -i "s/$$/$$pname /" $(ROOTFS_BUILD_DIR)/debootstrap/base ;\
140        done
141        touch $@
142       
143debian/rootfs/clean-rootfs-dir:
144        mkdir -p $(BUILD_DIR_BASE)
145        sudo rm -rf $(ROOTFS_BUILD_DIR)
146        touch $@
147
148debian/rootfs/post-setup: debian/rootfs/bootstrap
149        sudo mkdir -p $(ROOTFS_BUILD_DIR)/etc/apt
150        # note: unfortunately /etc/apt/sources.list is cleaned after running second stage install
151        sudo bash -c "echo \"deb http://ftp.debian.org/debian $(DEBIAN_BUILD_VERSION) main\" > $(ROOTFS_BUILD_DIR)/etc/apt/sources.list"
152        sudo bash -c "echo \"$(DEBWRTVERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debwrt_version"
153        sudo bash -c "echo \"$(DEBIAN_BUILD_VERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debian_release"
154        touch $@
155
156ifeq ($(DEBIAN_ROOTFS_QEMU_2ND_STAGE),y)
157debian/rootfs/second-stage-qemu: debian/rootfs/bootstrap debian/buildenv/qemu-build
158        $(call qemu-prepare-enter)
159        sudo chroot $(ROOTFS_BUILD_DIR) /usr/sbin/PostInstall && sudo rm -f $(ROOTFS_BUILD_DIR)/usr/sbin/PostInstall
160        sudo rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
161else
162debian/rootfs/second-stage-qemu: debian/rootfs/bootstrap
163        @echo "I: Qemu 2nd stage install disabled. Second stage needs now to be performend on the target device itself."
164        @echo "I: Qemu 2nd stage install can be enabled using menuconfig (DEBIAN_ROOTFS_QEMU_2ND_STAGE)."
165endif
166        touch $@
167
168debian/rootfs/clean:
169        sudo rm -rf $(ROOTFS_BUILD_DIR)
170        rm -f debian/rootfs/debwrt-packages
171        rm -f debian/rootfs/bootstrap
172        rm -f debian/rootfs/install
173        rm -f debian/rootfs/files-install
174        rm -f debian/rootfs/modules-install
175
Note: See TracBrowser for help on using the repository browser.