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

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

debian/package: convert package to new calling convention - major step in simplyfing and cleaning up package builds.

File size: 9.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"
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
41debian/buildenv/create: debian/buildenv/prepare debian/buildenv/emdebian-prepare debian/buildenv/qemu-build
42        touch $@
43
44debian/buildenv/prepare:
45        mkdir -p $(DEBIAN_BUILD_DIR)
46        # Due to various bugs in debootstrap in combination with fakechroot it is not
47        # possible to create a fakechroot here - and therefore we need to use chroot
48        # with sudo
49        #fakeroot fakechroot debootstrap
50                                                #--variant=fakechroot
51        sudo debootstrap    --include=$(subst $(space),$(empty),$(CONFIG_DEBIAN_BUILDENV_INCLUDE_PACKAGES)) \
52                                            $(DEBIAN_BUILD_VERSION) \
53                                                $(DEBIAN_BUILD_DIR) \
54                                                $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
55        sudo bash -c "echo 127.0.0.1 `hostname -s` localhost >$(DEBIAN_BUILD_DIR)/etc/hosts"
56        sudo bash -c "echo debwrt-$(TARGET_ARCH)-$(DEBIAN_BUILD_VERSION) > $(DEBIAN_BUILD_DIR)/etc/debian_chroot"
57        sudo bash -c "echo syntax on >$(DEBIAN_BUILD_DIR)/etc/vimrc"
58        sudo bash -c "echo 0 > /proc/sys/vm/mmap_min_addr" # for ARM targets
59        sudo bash -c "echo \"deb $(call qstrip,$(CONFIG_DEBIAN_BUILDENV_REPOSITORY)) $(DEBIAN_BUILD_VERSION) main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
60        sudo bash -c "echo \"deb-src $(call qstrip,$(CONFIG_DEBIAN_BUILDENV_REPOSITORY)) $(DEBIAN_BUILD_VERSION) main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
61        sudo chown $(USER):$(GROUP) $(DEBIAN_BUILD_DIR)/usr/src
62        sudo chroot $(DEBIAN_BUILD_DIR) apt-get update
63        sudo chroot $(DEBIAN_BUILD_DIR) groupadd -g $(shell id -g) debwrt
64        sudo chroot $(DEBIAN_BUILD_DIR) useradd -g debwrt -s /bin/bash -m -u $(shell id -u) $$USER
65        sudo mkdir -p $(DEBIAN_BUILD_DIR)/etc/sudoers.d
66        sudo bash -c "echo \"$(USER) ALL=(ALL) NOPASSWD: ALL\" >$(DEBIAN_BUILD_DIR)/etc/sudoers.d/debwrt"
67        sudo chmod 0440 $(DEBIAN_BUILD_DIR)/etc/sudoers.d/debwrt
68        touch $@
69
70debian/buildenv/prepare-sb2:
71        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"
72        touch $@
73
74#
75# -- Emdebian sources.list entries
76#
77# deb http://www.emdebian.org/debian/ unstable main
78# deb http://www.emdebian.org/debian/ testing main
79# deb http://www.emdebian.org/debian/ lenny main
80#
81# Once you have that then install whichever version of the tools you want. e.g:
82# 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
83# will install the gcc-4.3 C and C++ toolchain for armel cross-compiling.
84#
85# Use emdebian stable/lenny cross compiler. Unstable seems to be broken now for a long time
86#
87# Emdebian suggests to use squeeze, even if on wheezey or higher:
88# Currently, toolchains for Squeeze are preferred. If using Wheezy or unstable, add
89# a Squeeze source for your own architecture using your normal Debian mirror for
90# dependencies which are no longer in wheezy or unstable.
91#
92#EMDEBIAN_RELEASE:=$(DEBIAN_BUILD_VERSION)
93EMDEBIAN_RELEASE:=squeeze
94
95# Automatic installing of build dependencies
96#
97# <= Lenny = apt-cross
98# >  Lenny = xapt
99#
100# Squeeze needs some backorts to get xapt working, so from now on
101# DebWrt will only support wheezy and up.
102#
103# Link: https://wiki.debian.org/EmdebianToolchain
104
105# note: to speed up setting up: do not install devscripts
106# note: a mailservers seems to be installed and started: bad - needs removal
107
108debian/buildenv/emdebian-prepare: debian/buildenv/prepare
109        @echo "I: Adding squeeze source incase Emdebiand squeeze is missing packages in wheezy or higher..."
110        sudo bash -c "echo \"deb $(call qstrip,$(CONFIG_EMDEBIAN_BUILDENV_REPOSITORY)) $(EMDEBIAN_RELEASE) main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
111        sudo bash -c "echo \"deb $(call qstrip,$(CONFIG_DEBIAN_BUILDENV_REPOSITORY)) squeeze main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
112        sudo bash -c "echo \"deb-src $(call qstrip,$(CONFIG_DEBIAN_BUILDENV_REPOSITORY)) squeeze main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
113        # Add lenny repo, just for apt-cross
114        #sudo bash -c "echo \"deb  http://archive.debian.org/debian lenny main\" >> $(DEBIAN_BUILD_DIR)/etc/apt/sources.list"
115        #sudo bash -c "echo -e \"Package: *\nPin: release a=lenny\nPin-Priority: 200\" > $(DEBIAN_BUILD_DIR)/etc/apt/preferences"
116        sudo chroot $(DEBIAN_BUILD_DIR) apt-get update
117        #sudo chroot $(DEBIAN_BUILD_DIR) apt-get -y install apt-cross
118        #sudo chroot $(DEBIAN_BUILD_DIR) apt-get -y install libmpfr1ldbl
119        sudo chroot $(DEBIAN_BUILD_DIR) apt-get -y install emdebian-archive-keyring xapt dpkg-cross
120        sudo chroot $(DEBIAN_BUILD_DIR) bash -c "export LC_ALL=C; apt-get -y --force-yes install build-essential dh-make debootstrap fakeroot zlib1g-dev openssh-client vim pkg-config dpatch libncurses5-dev devscripts subversion automake gcc-multilib g++-multilib quilt"
121ifeq ($(TARGET_ARCH),arm)
122        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"
123else
124        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"
125endif
126        touch $@
127
128debian/buildenv/qemu: debian/buildenv/qemu-prepare debian/buildenv/qemu-build
129        touch $@
130
131debian/buildenv/qemu-clean:
132        rm -rf $(DEBIAN_BUILD_DIR)/usr/src/qemu
133        rm -f debian/buildenv/qemu-prepare
134        rm -f debian/buildenv/qemu-build
135
136debian/buildenv/qemu-prepare:
137        $(CHROOT) bash -c "export LC_ALL=C; apt-get -y install libglib2.0-dev"
138        mkdir -p $(DEBIAN_BUILD_DIR)/usr/src/qemu
139        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
140        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
141        touch $@
142
143debian/buildenv/qemu-build: debian/buildenv/qemu-prepare
144        $(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"
145        $(CHROOT) bash -c "cd /usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)) && make install"
146        $(CHROOT) cp /usr/local/bin/qemu-$(TARGET_ARCH) /usr/local/bin/qemu-$(TARGET_ARCH)-static
147        $(CHROOT_USER) bash -c "cd /usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)) && ./configure --target-list=$(TARGET_ARCH)-linux-user && make"
148        $(CHROOT) bash -c "cd /usr/src/qemu/qemu-$(call qstrip,$(CONFIG_DEBIAN_BUILDENV_QEMU_VERSION)) && make install"
149        touch $@
150
151debian/buildenv/scratchbox-prepare:
152        sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c "mkdir -p $(SB2_ARCH)-lenny"
153        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\""
154        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)"
155        sudo chroot $(DEBIAN_BUILD_DIR) su - $(USER) -c bash -c  "cd $(SB2_ARCH)-lenny && sb2 -eR ./debootstrap/debootstrap --second-stage"
156
157debian/buildenv/clean: debian/buildenv/qemu-clean
158        # sudo should not be needed if fakechroot would have worked
159        sudo rm -rf $(DEBIAN_BUILD_DIR)
160        rm -f debian/buildenv/prepare
161        rm -f debian/buildenv/qemu-prepare
162        rm -f debian/buildenv/qemu-build
163
164.PHONY: debian/buildenv/clean debian/buildenv
165
Note: See TracBrowser for help on using the repository browser.