source: debwrt/trunk/debian/buildenv/debian.mk @ 61

Last change on this file since 61 was 61, checked in by amain, 9 years ago

Start implementing create of debian rootfs

File size: 6.1 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
18SB2_ARCH:=$(call qstrip,$(CONFIG_ARCH))
19CHROOT:=sudo chroot $(DEBIAN_BUILD_DIR)
20CHROOT_USER:=$(CHROOT) su - $(USER)
21SB2:=sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c "export LC_ALL=C; cd $(SB2_ARCH)-lenny && sb2"
22SB2E:=sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c "export LC_ALL=C; cd $(SB2_ARCH)-lenny && sb2 -e"
23SB2EF:=sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c "export LC_ALL=C; cd $(SB2_ARCH)-lenny && sb2 -eR"
24
25sb2:
26        $(SB2)
27sb2e:
28        $(SB2E)
29sbef:
30        $(SB2EF)
31ch: chroot
32chu: chroot-user
33chroot:
34        $(CHROOT) bash -c "cd /usr/src; exec bash"
35chroot-user:
36        $(CHROOT_USER) bash -c "cd /usr/src; exec bash"
37
38#debian/buildenv/create: debian/buildenv/prepare debian/buildenv/qemu-build debian/buildenv/scratchbox-prepare
39debian/buildenv/create: debian/buildenv/prepare debian/buildenv/emdebian-prepare
40        touch $@
41
42debian/buildenv/prepare:
43        mkdir -p $(DEBIAN_BUILD_DIR)
44        # Due to various bugs in debootstrap in combination with fakechroot it is not
45        # possible to create a fakechroot here - and therefore we need to use chroot
46        # with sudo
47        #fakeroot fakechroot debootstrap
48                                                #--variant=fakechroot
49        sudo debootstrap    --include=$(subst $(space),$(empty),$(CONFIG_DEBIAN_BUILDENV_INCLUDE_PACKAGES)) \
50                                            $(DEBIAN_BUILD_VERSION) \
51                                                $(DEBIAN_BUILD_DIR) \
52                                                $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
53        sudo bash -c "echo 127.0.0.1 `hostname -s` >$(DEBIAN_BUILD_DIR)/etc/hosts"
54        sudo bash -c "echo \"$(USER) ALL=(ALL) NOPASSWD: ALL\" >$(DEBIAN_BUILD_DIR)/etc/sudoers"
55        sudo bash -c "echo debwrt-$(call qstrip,$(CONFIG_ARCH))-$(DEBIAN_BUILD_VERSION) > $(DEBIAN_BUILD_DIR)/etc/debian_chroot"
56        sudo bash -c "echo syntax on >$(DEBIAN_BUILD_DIR)/etc/vimrc"
57        sudo bash -c "echo 0 > /proc/sys/vm/mmap_min_addr" # for ARM targets
58        sudo bash -c "echo \"deb $(call qstrip,$(CONFIG_DEBIAN_BUILDENV_REPOSITORY)) $(DEBIAN_BUILD_VERSION) main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
59        sudo chown $(USER):$(GROUP) $(DEBIAN_BUILD_DIR)/usr/src
60        sudo chroot $(DEBIAN_BUILD_DIR) apt-get update
61        sudo chroot $(DEBIAN_BUILD_DIR) groupadd -g $(shell id -g) debwrt
62        sudo chroot $(DEBIAN_BUILD_DIR) useradd -g debwrt -s /bin/bash -m -u $(shell id -u) $$USER
63        touch $@
64
65debian/buildenv/prepare-sb2:
66        sudo chroot $(DEBIAN_BUILD_DIR) bash -c "export LC_ALL=C; apt-get -y --force-yes install g++-4.3-$(SB2_ARCH)-linux-gnu libc6-dev-$(SB2_ARCH)-cross build-essential debootstrap fakeroot zlib1g-dev qemu-user scratchbox2 dh-make"
67        touch $@
68
69#
70# -- Emdebian sources.list entries
71#
72# deb http://www.emdebian.org/debian/ unstable main
73# deb http://www.emdebian.org/debian/ testing main
74# deb http://www.emdebian.org/debian/ lenny main
75#
76# Once you have that then install whichever version of the tools you want. e.g:
77# apt-get install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi gcc-4.3-arm-linux-gnueabi g++-4.3-arm-linux-gnueabi
78# will install the gcc-4.3 C and C++ toolchain for armel cross-compiling.
79#
80# Use emdebian stable/lenny cross compiler. Unstable seems to be broken now for a long time
81#EMDEBIAN_RELEASE:=$(DEBIAN_BUILD_VERSION)
82EMDEBIAN_RELEASE:=stable
83
84# note: to speed up setting up: do not install devscripts
85# note: a mailservers seems to be installed and started: bad - needs removal
86debian/buildenv/emdebian-prepare: debian/buildenv/prepare
87        sudo bash -c "echo \"deb $(call qstrip,$(CONFIG_EMDEBIAN_BUILDENV_REPOSITORY)) $(EMDEBIAN_RELEASE) main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
88        sudo chroot $(DEBIAN_BUILD_DIR) apt-get update
89        sudo chroot $(DEBIAN_BUILD_DIR) bash -c "export LC_ALL=C; apt-get -y --force-yes install build-essential debootstrap fakeroot zlib1g-dev dh-make sudo openssh-client dpkg-cross apt-cross vim pkg-config dpatch libncurses5-dev devscripts"
90        sudo chroot $(DEBIAN_BUILD_DIR) bash -c "export LC_ALL=C; apt-get -y --force-yes install libc6-$(TARGET_ARCH)-cross libc6-dev-$(TARGET_ARCH)-cross binutils-$(TARGET_ARCH)-linux-gnu gcc-4.3-$(TARGET_ARCH)-linux-gnu g++-4.3-$(TARGET_ARCH)-linux-gnu linux-kernel-headers-$(TARGET_ARCH)-cross"
91        touch $@
92
93debian/buildenv/qemu-prepare:
94        sudo chroot $(DEBIAN_BUILD_DIR) bash -c "cd /usr/src && wget http://download.savannah.gnu.org/releases/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)).tar.gz && tar xzf qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)).tar.gz"
95        touch $@
96
97debian/buildenv/qemu-build: debian/buildenv/qemu-prepare
98        sudo chroot $(DEBIAN_BUILD_DIR) bash -c "cd /usr/src/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)) && ./configure --target-list=$(SB2_ARCH)-linux-user && make && make install"
99        touch $@
100
101debian/buildenv/scratchbox-prepare:
102        sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c "mkdir -p $(SB2_ARCH)-lenny"
103        sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c "cd $(SB2_ARCH)-lenny && sb2-init -c /usr/local/bin/qemu-$(SB2_ARCH) MIPS \"$(SB2_ARCH)-linux-gnu-gcc\""
104        sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c "fakeroot /usr/sbin/debootstrap --include=file,iputils-ping,netbase,strace,vim,wget,tcpdump --variant=scratchbox --foreign --arch $(SB2_ARCH) lenny $(SB2_ARCH)-lenny/ $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)"
105        sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c  "cd $(SB2_ARCH)-lenny && sb2 -eR ./debootstrap/debootstrap --second-stage"
106
107debian/buildenv/clean:
108        # sudo should not be needed if fakechroot would have worked
109        sudo rm -rf $(DEBIAN_BUILD_DIR)
110        rm -f debian/buildenv/prepare
111        rm -f debian/buildenv/qemu-prepare
112        rm -f debian/buildenv/qemu-build
113
114.PHONY: debian/clean
115
Note: See TracBrowser for help on using the repository browser.