source: branches/contrib/debian/rootfs/debian.mk @ 707

Last change on this file since 707 was 707, checked in by ehem, 5 years ago

Drag in changes to trunk

Coordination is interesting to deal with. Drag in changes that were done
on trunk.

File size: 9.1 KB
Line 
1# DebWrt - Debian on Embedded devices
2#
3# Copyright (C) 2010,2015 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
18QEMU_BIN=/usr/bin/qemu-$(ROOTFS_DEBIAN_ARCH)
19QEMU_BIN_STATIC=$(QEMU_BIN)-static
20QEMU_INTERPRETER=$(shell cat /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) 2>/dev/null | grep interpreter | awk '{print $$2}')
21
22ROOTFS_DEBIAN_INCLUDE_PACKAGES:=$(call qstrip,$(CONFIG_ROOTFS_DEBIAN_INCLUDE_PACKAGES))
23ROOTFS_DEBIAN_QEMU_2ND_STAGE:=$(call qstrip, $(CONFIG_ROOTFS_DEBIAN_QEMU_2ND_STAGE))
24DEBWRT_EXTRA_ROOTFS_FILES_DIR:=$(TOPDIR)/debian/rootfs/files/all
25DEBWRT_EXTRA_ROOTFS_FILES_BOARD_DIR:=$(TOPDIR)/debian/rootfs/files/$(call qstrip, $(CONFIG_TARGET_BOARD))
26MODULES_VERSION=$(shell echo `basename $(DEBWRT_MODULES_ARCHIVE) 2>/dev/null` | awk -F '-' '{print $$6}')
27ROOTFS_DEBIAN_INCLUDE_PACKAGES_DEBIAN_VERSION:=$(wildcard debian/rootfs/include_packages.list.$(ROOTFS_DEBIAN_RELEASE))
28
29### temporary during work towards functioning fakeroot/fakechroot
30CHROOT:=$(SUROOT) chroot $(ROOTFS_BUILD_DIR)
31CHROOT_USER:=$(CHROOT) su - $(USER)
32### temporary during work towards functioning fakeroot/fakechroot
33
34define qemu-prepare
35        @if [ ! -x $(QEMU_BIN_STATIC) ]; then echo "E: can't find qemu ($(QEMU_BIN_STATIC))"; fi
36        @if [ ! -e /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) ]; then echo "E: can't find binfmt_misc qemu-$(ROOTFS_DEBIAN_ARCH) ( /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH)).\nE: install qemu-user-static, or\nE: disable second stage with qemu with menuconfig (ROOTFS_DEBIAN_QEMU_2ND_STAGE)."; fi
37        @if [ ! -x $(QEMU_BIN_STATIC) -o ! -e /proc/sys/fs/binfmt_misc/qemu-$(ROOTFS_DEBIAN_ARCH) ]; then echo "E: abort - qemu not available in chroot"; exit 1; fi
38        @if [ ! -e $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER) ]; then sudo cp $(QEMU_BIN_STATIC) $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER); fi
39        @if ! sudo chroot $(ROOTFS_BUILD_DIR) /bin/ls >/dev/null; then echo "E: qemu can't execute binaries for $(ROOTFS_DEBIAN_ARCH)"; echo "E: abort"; exit 1; fi
40        @if ! (mount | grep -q $(ROOTFS_BUILD_DIR)/proc); then sudo chroot $(ROOTFS_BUILD_DIR) mount -t proc none /proc; fi
41        @if ! (mount | grep -q $(ROOTFS_BUILD_DIR)/sys ); then sudo chroot $(ROOTFS_BUILD_DIR) mount -t sysfs none /sys; fi
42        @mount
43endef
44
45define qemu-cleanup
46        @if (mount | grep -q $(ROOTFS_BUILD_DIR)/proc); then $(SUROOT) umount $(ROOTFS_BUILD_DIR)/proc; fi
47        @if (mount | grep -q $(ROOTFS_BUILD_DIR)/sys ); then $(SUROOT) umount $(ROOTFS_BUILD_DIR)/sys ; fi
48        @$(SUROOT) rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
49endef
50
51define rootfs-package-list
52$(shell echo "$(DEBWRT_ROOTFS_PKGLST_DEPS)" \
53         | tr ' ' '\n' \
54         >$(TMP_DIR)/include_packages_list.debwrt-package-deps; \
55        grep -hv '^#' \
56                 $(ROOTFS_DEBIAN_INCLUDE_PACKAGES) \
57                 $(ROOTFS_DEBIAN_INCLUDE_PACKAGES_DEBIAN_VERSION) \
58                 $(TMP_DIR)/include_packages_list.debwrt-package-deps \
59          | sort -u | tr '\n' ',' | sed 's/,$$//')
60endef
61
62chr:
63        $(call qemu-prepare)
64        @sudo bash -c "echo "debwrt-$(ROOTFS_DEBIAN_ARCH)" > $(ROOTFS_BUILD_DIR)/etc/debian_chroot"
65        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt
66        @sudo bash -c "cat /etc/resolv.conf | grep nameserver >$(ROOTFS_BUILD_DIR)/etc/resolv.conf"
67        @sudo chroot $(ROOTFS_BUILD_DIR)
68        @sudo rm -f $(ROOTFS_BUILD_DIR)/etc/debian_chroot
69        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt $(ROOTFS_BUILD_DIR)/etc/resolv.conf
70        $(call qemu-cleanup)
71
72debian/rootfs: debian/rootfs/bootstrap            \
73               debian/rootfs/unpack               \
74               debian/rootfs/files-install        \
75               debian/rootfs/post-setup           \
76               debian/rootfs/second-stage         \
77               debian/rootfs/verify               \
78               debian/rootfs/save
79        @echo "I: Root filesystem $(ROOTFS_DEBIAN_RELEASE) $(ROOTFS_DEBIAN_ARCH) prepared in $(ROOTFS_BUILD_DIR) and archived in $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2)."
80        @echo "I:"
81        @echo "I: Install the image to USB-Disk/USB-Stick/SD-Card (make sure it is already mounted at /media/DEBWRT_ROOTFS)"
82        @echo "I: - make debian/rootfs/install"
83        @echo "I:"
84        @echo "I: Enter the change root(with qemu) and perform additional post install steps:"
85        @echo "I: - make chr"
86        @echo "I: - apt-get update # example statement ;-) - networking works!"
87        touch $@
88
89debian/rootfs/install: debian/rootfs
90        if [ -d /media/DEBWRT_ROOT ]; then \
91                $(SUROOT) rm -rf /media/DEBWRT_ROOT/*; \
92                $(SUROOT) bash -c "tar cf - -C $(ROOTFS_BUILD_DIR) . | tar xf - -C /media/DEBWRT_ROOT"; \
93        fi
94        #touch $@
95
96debian/rootfs/verify:
97        @if [ -f $(ROOTFS_BUILD_DIR)/debootstrap/debootstrap.log ]; then \
98                echo "E: Second stage install was not completed successfully" ;\
99                echo "E: Please check debootstrap.log to inspect the situation:" ;\
100                echo "E:    make chr" ;\
101                echo "E:    vi /debootstrap/debootstrap.log" ;\
102                exit 1 ;\
103        fi
104        touch $@
105
106debian/rootfs/save:
107        mkdir -p $(ROOTFS_INSTALL_DIR)
108        sudo bash -c "tar cjf $(ROOTFS_INSTALL_DIR)/$(ROOTFS_TAR_BZ2) -C $(ROOTFS_BUILD_DIR) ."
109#ifeq ($(ROOTFS_DEBIAN_QEMU_2ND_STAGE),y)
110#else
111#       if [ -d /media/DEBWRT_ROOT ]; then \
112#               sudo bash -c "tar cjf $(ROOTFS_TAR_BZ2) -C /media/DEBWRT_ROOT ."; \
113#       fi
114#endif
115
116debian/rootfs/files-install: debian/rootfs/bootstrap
117        if [ ! -f $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian -a -e $(ROOTFS_BUILD_DIR)/etc/init.d/rcS ]; then \
118                $(SUROOT) mv -v $(ROOTFS_BUILD_DIR)/etc/init.d/rcS $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian; \
119        fi
120        if [ ! -p $(ROOTFS_BUILD_DIR)/dev/initctl ]; then  \
121                $(SUROOT) mkdir -p $(ROOTFS_BUILD_DIR)/dev;         \
122                $(SUROOT) mkfifo   $(ROOTFS_BUILD_DIR)/dev/initctl; \
123        fi
124        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_rsa_key
125        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_dsa_key
126        sudo bash -c "tar cf - --exclude=".svn" -C $(DEBWRT_EXTRA_ROOTFS_FILES_DIR) . | tar -xovf - -C $(ROOTFS_BUILD_DIR)"
127        sudo bash -c "if [ -d $(DEBWRT_EXTRA_ROOTFS_FILES_BOARD_DIR) ]; then tar cf - --exclude=".svn" -C $(DEBWRT_EXTRA_ROOTFS_FILES_BOARD_DIR) . | tar -xovf - -C $(ROOTFS_BUILD_DIR); fi"
128        sudo cat $(ROOTFS_BUILD_DIR)/etc/securetty \
129                $(TOPDIR)/debian/rootfs/securetty.tail \
130                >> $(TOPDIR)/securetty.temp
131        $(SUROOT) mv    $(TOPDIR)/securetty.temp $(ROOTFS_BUILD_DIR)/etc/securetty
132        touch $@
133
134# Fow now: Include debwrt-packages dependencies staticly. This
135#          list(DEBWRT_ROOTFS_PKGLST_DEPS) is managed in debian/package-host/debian.mk.
136debian/rootfs/bootstrap: debian/rootfs/clean-rootfs-dir
137        mkdir -p $(ROOTFS_BUILD_DIR)
138        sudo debootstrap --arch=$(ROOTFS_DEBIAN_ARCH)\
139                     --foreign \
140                     --include=$(call rootfs-package-list) \
141                     $(ROOTFS_DEBIAN_RELEASE) \
142                     $(ROOTFS_BUILD_DIR) \
143                     $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
144        # complete ROOTFS/dev/ with additional device files
145        $(SUROOT) bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v consoleonly"
146        $(SUROOT) bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v sda"
147        touch $@
148
149debian/rootfs/unpack: debian/rootfs/bootstrap
150        find $(ROOTFS_BUILD_DIR) -name "*.deb" | while read deb; do \
151                n=`basename $$deb`; \
152                echo -n "I: Extracting $${n}..."; \
153                $(SUROOT) bash -c "dpkg --extract "$$deb" $(ROOTFS_BUILD_DIR)" ; \
154                echo "done"; \
155        done
156        touch $@
157
158# install all available cross-compiled debwrt debian packages, except for the kernel-headers package and the cross packages
159
160debian/rootfs/clean-rootfs-dir:
161        mkdir -p $(BUILD_DIR_BASE)
162        $(SUROOT) rm -rf $(ROOTFS_BUILD_DIR)
163        touch $@
164
165debian/rootfs/post-setup: debian/rootfs/bootstrap
166        $(SUROOT) mkdir -p $(ROOTFS_BUILD_DIR)/etc/apt
167        # note: unfortunately /etc/apt/sources.list is cleaned after running second stage install
168        sudo bash -c "echo \"deb http://ftp.debian.org/debian $(ROOTFS_DEBIAN_RELEASE) main\" > $(ROOTFS_BUILD_DIR)/etc/apt/sources.list"
169        sudo bash -c "echo \"$(DEBWRTVERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debwrt_version"
170        sudo bash -c "echo \"$(ROOTFS_DEBIAN_RELEASE)\" >$(ROOTFS_BUILD_DIR)/etc/debian_release"
171        touch $@
172
173ifeq ($(ROOTFS_DEBIAN_QEMU_2ND_STAGE),y)
174debian/rootfs/second-stage: debian/rootfs/bootstrap debian/buildenv/qemu
175        $(call qemu-prepare)
176        $(CHROOT) /usr/sbin/PostInstall && $(SUROOT) rm -f $(ROOTFS_BUILD_DIR)/usr/sbin/PostInstall
177        $(call qemu-cleanup)
178else
179debian/rootfs/second-stage: debian/rootfs/bootstrap
180        @echo "I: Qemu 2nd stage install disabled. Second stage needs now to be performend on the target device itself."
181        @echo "I: Qemu 2nd stage install can be enabled using menuconfig (ROOTFS_DEBIAN_QEMU_2ND_STAGE)."
182endif
183        touch $@
184
185debian/rootfs/clean:
186        $(SUROOT) rm -rf $(ROOTFS_BUILD_DIR)
187        rm -f debian/rootfs/bootstrap
188        rm -f debian/rootfs/install
189        rm -f debian/rootfs/files-install
190
Note: See TracBrowser for help on using the repository browser.