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

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

debian/rootfs: debwrt-packages - wrong list inclusion fix

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