source: trunk/debian/buildenv/debian.mk @ 308

Last change on this file since 308 was 308, checked in by amain, 11 years ago

debian/buildenv: fix search for qemu bin

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
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"
24QEMU_BIN=$(DEBIAN_BUILD_DIR)/usr/local/bin/qemu-$(TARGET_ARCH)
25QEMU_BIN_STATIC=$(QEMU_BIN)-static
26QEMU_INTERPRETER=$(shell cat /proc/sys/fs/binfmt_misc/qemu-$(TARGET_ARCH) 2>/dev/null | grep interpreter | awk '{print $$2}')
27
28sb2:
29        $(SB2)
30sb2e:
31        $(SB2E)
32sbef:
33        $(SB2EF)
34ch: chroot
35chu: chroot-user
36chroot:
37        $(CHROOT) bash -c "cd /usr/src; exec bash"
38chroot-user:
39        $(CHROOT_USER) bash -c "cd /usr/src; exec bash"
40
41#debian/buildenv/create: debian/buildenv/prepare debian/buildenv/qemu-build debian/buildenv/scratchbox-prepare
42debian/buildenv/create: debian/buildenv/prepare debian/buildenv/emdebian-prepare debian/buildenv/qemu-build
43        touch $@
44
45debian/buildenv/prepare:
46        mkdir -p $(DEBIAN_BUILD_DIR)
47        # Due to various bugs in debootstrap in combination with fakechroot it is not
48        # possible to create a fakechroot here - and therefore we need to use chroot
49        # with sudo
50        #fakeroot fakechroot debootstrap
51                                                #--variant=fakechroot
52        sudo debootstrap    --include=$(subst $(space),$(empty),$(CONFIG_DEBIAN_BUILDENV_INCLUDE_PACKAGES)) \
53                                            $(DEBIAN_BUILD_VERSION) \
54                                                $(DEBIAN_BUILD_DIR) \
55                                                $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
56        sudo bash -c "echo 127.0.0.1 `hostname -s` localhost >$(DEBIAN_BUILD_DIR)/etc/hosts"
57        sudo bash -c "echo debwrt-$(TARGET_ARCH)-$(DEBIAN_BUILD_VERSION) > $(DEBIAN_BUILD_DIR)/etc/debian_chroot"
58        sudo bash -c "echo syntax on >$(DEBIAN_BUILD_DIR)/etc/vimrc"
59        sudo bash -c "echo 0 > /proc/sys/vm/mmap_min_addr" # for ARM targets
60        sudo bash -c "echo \"deb $(call qstrip,$(CONFIG_DEBIAN_BUILDENV_REPOSITORY)) $(DEBIAN_BUILD_VERSION) main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
61        sudo bash -c "echo \"deb-src $(call qstrip,$(CONFIG_DEBIAN_BUILDENV_REPOSITORY)) $(DEBIAN_BUILD_VERSION) main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
62        sudo chown $(USER):$(GROUP) $(DEBIAN_BUILD_DIR)/usr/src
63        sudo chroot $(DEBIAN_BUILD_DIR) apt-get update
64        sudo chroot $(DEBIAN_BUILD_DIR) groupadd -g $(shell id -g) debwrt
65        sudo chroot $(DEBIAN_BUILD_DIR) useradd -g debwrt -s /bin/bash -m -u $(shell id -u) $$USER
66        sudo mkdir -p $(DEBIAN_BUILD_DIR)/etc/sudoers.d
67        sudo bash -c "echo \"$(USER) ALL=(ALL) NOPASSWD: ALL\" >$(DEBIAN_BUILD_DIR)/etc/sudoers.d/debwrt"
68        sudo chmod 0440 $(DEBIAN_BUILD_DIR)/etc/sudoers.d/debwrt
69        touch $@
70
71debian/buildenv/prepare-sb2:
72        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"
73        touch $@
74
75#
76# -- Emdebian sources.list entries
77#
78# deb http://www.emdebian.org/debian/ unstable main
79# deb http://www.emdebian.org/debian/ testing main
80# deb http://www.emdebian.org/debian/ lenny main
81#
82# Once you have that then install whichever version of the tools you want. e.g:
83# 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
84# will install the gcc-4.3 C and C++ toolchain for armel cross-compiling.
85#
86# Use emdebian stable/lenny cross compiler. Unstable seems to be broken now for a long time
87#EMDEBIAN_RELEASE:=$(DEBIAN_BUILD_VERSION)
88EMDEBIAN_RELEASE:=stable
89
90# note: to speed up setting up: do not install devscripts
91# note: a mailservers seems to be installed and started: bad - needs removal
92debian/buildenv/emdebian-prepare: debian/buildenv/prepare
93        sudo bash -c "echo \"deb $(call qstrip,$(CONFIG_EMDEBIAN_BUILDENV_REPOSITORY)) $(EMDEBIAN_RELEASE) main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
94        # Add lenny repo, just for apt-cross
95        sudo bash -c "echo \"deb $(call qstrip,$(CONFIG_DEBIAN_BUILDENV_REPOSITORY)) lenny main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
96        #sudo bash -c "echo -e \"Package: *\nPin: release a=lenny\nPin-Priority: 200\" > $(DEBIAN_BUILD_DIR)/etc/apt/preferences"
97        sudo chroot $(DEBIAN_BUILD_DIR) apt-get update
98        sudo chroot $(DEBIAN_BUILD_DIR) apt-get -y install apt-cross
99        sudo chroot $(DEBIAN_BUILD_DIR) apt-get -y install libmpfr1ldbl
100        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 openssh-client dpkg-cross vim pkg-config dpatch libncurses5-dev devscripts subversion automake gcc-multilib g++-multilib quilt"
101ifeq ($(TARGET_ARCH),arm)
102        sudo chroot $(DEBIAN_BUILD_DIR) bash -c "export LC_ALL=C; apt-get -y --force-yes install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi gcc-4.3-arm-linux-gnu g++-4.4-arm-linux-gnueabi linux-kernel-headers-armel-cross"
103else
104        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"
105endif
106        touch $@
107
108debian/buildenv/qemu: debian/buildenv/qemu-prepare debian/buildenv/qemu-build
109        touch $@
110
111debian/buildenv/qemu-clean:
112        rm -rf $(DEBIAN_BUILD_DIR)/usr/src/qemu
113        rm -f debian/buildenv/qemu-prepare
114        rm -f debian/buildenv/qemu-build
115
116debian/buildenv/qemu-prepare:
117        $(CHROOT) bash -c "export LC_ALL=C; apt-get -y install libglib2.0-dev"
118        mkdir -p $(DEBIAN_BUILD_DIR)/usr/src/qemu
119        wget -O $(DEBIAN_BUILD_DIR)/usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)).tar.gz http://download.savannah.gnu.org/releases/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)).tar.gz
120        tar xzf $(DEBIAN_BUILD_DIR)/usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)).tar.gz -C $(DEBIAN_BUILD_DIR)/usr/src/qemu
121        touch $@
122
123debian/buildenv/qemu-build: debian/buildenv/qemu-prepare
124        $(CHROOT_USER) bash -c "cd /usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)) && ./configure --static --target-list=$(TARGET_ARCH)-linux-user && make"
125        $(CHROOT) bash -c "cd /usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)) && make install"
126        $(CHROOT) cp /usr/local/bin/qemu-$(TARGET_ARCH) /usr/local/bin/qemu-$(TARGET_ARCH)-static
127        $(CHROOT_USER) bash -c "cd /usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)) && ./configure --target-list=$(TARGET_ARCH)-linux-user && make"
128        $(CHROOT) bash -c "cd /usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)) && make install"
129        touch $@
130
131debian/buildenv/scratchbox-prepare:
132        sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c "mkdir -p $(SB2_ARCH)-lenny"
133        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\""
134        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)"
135        sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c  "cd $(SB2_ARCH)-lenny && sb2 -eR ./debootstrap/debootstrap --second-stage"
136
137debian/buildenv/clean: debian/buildenv/qemu-clean
138        # sudo should not be needed if fakechroot would have worked
139        sudo rm -rf $(DEBIAN_BUILD_DIR)
140        rm -f debian/buildenv/prepare
141        rm -f debian/buildenv/qemu-prepare
142        rm -f debian/buildenv/qemu-build
143
144.PHONY: debian/buildenv/clean
145
Note: See TracBrowser for help on using the repository browser.