1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | # # Copyright 2017 Ingo Hornberger <ingo_@gmx.net> # # This software is licensed under the MIT License # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to the following # conditions: # # The above copyright notice and this permission notice shall be included in all copies # or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE # OR OTHER DEALINGS IN THE SOFTWARE. ################################################################################ SHELL=/bin/bash PATH := $(PATH):/sbin:/usr/sbin SUDO=$(shell PATH=${PATH}:/sbin:/usr/sbin which sudo) FAKEROOT=$(shell PATH=${PATH}:/sbin:/usr/sbin which fakeroot) FAKECHROOT=$(shell PATH=${PATH}:/sbin:/usr/sbin which fakechroot) DBOOTSTRAP=$(shell PATH=${PATH}:/sbin:/usr/sbin which qemu-debootstrap) DBOOTSTRAP2=$(shell PATH=${PATH}:/sbin:/usr/sbin which debootstrap) KPARTX=$(shell PATH=${PATH}:/sbin:/usr/sbin which kpartx) PACKAGES=locales systemd dbus MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) CWD := $(dir $(MAKEFILE_PATH)) # extend path to sbin binaries export PATH := /usr/sbin:${PATH} ifeq (${SUDO},) $(error sudo not found. On debian, you may install the package sudo first) endif #ifeq (${FAKEROOT},) #$(error fakeroot not found. On debian, you may install the package fakeroot first) #endif #ifeq (${FAKECHROOT},) #$(error fakechroot not found. On debian, you may install the package fakechroot first) #endif ifeq (${DBOOTSTRAP},) $(error qemu-debootstrap not found. On debian, you may install the package qemu-user-static first) endif ifeq (${DBOOTSTRAP2},) $(error debootstrap not found. On debian, you may install the package debootstrap first) endif ifeq (${KPARTX},) $(error kpartx not found. On debian, you may install the package kpartx first) endif .PHONY: test test: echo ${FAKEROOT} # # Set version specific system variables for the toolchain # debian_armhf_%.tar: gcc_postfix=-arm-none-eabi debian_armhf_%.tar: libc_postfix=-armhf-cross debian_armel_%.tar: gcc_postfix=-arm-none-eabi debian_armel_%.tar: libc_postfix=-armhf-cross debian_arm64_%.tar: gcc_postfix=-aarch64-linux-gnu debian_arm64_%.tar: libc_postfix=-arm64-cross # stretch changed doesn't support ARM non-eabi anymore, but has more specific ones debian_armhf_stretch.tar: gcc_postfix=-arm-linux-gnueabihf debian_armel_stretch.tar: gcc_postfix=-arm-linux-gnueabi # since stretch, ARM supports g++ debian_armhf_stretch.tar: additional_arch_packages+=g++-arm-linux-gnueabihf debian_armel_stretch.tar: additional_arch_packages+=g++-arm-linux-gnueabi debian_amd64_stretch.tar: additional_arch_packages+=g++ # # Debian / ARM Hardfloat # .PHONY: debian_armhf_%.tar debian_armhf_%.tar: -mkdir ./$$(basename $@ .tar) ${SUDO} ${DBOOTSTRAP} --arch=armhf --variant=minbase --include="${PACKAGES}" $* ./$$(basename $@ .tar) http://ftp.debian.org/debian/ (echo "deb http://ftp.debian.org/debian $* main"; \ echo "deb-src http://ftp.debian.org/debian $* main") | ${SUDO} tee ./$$(basename $@ .tar)/etc/apt/sources.list cd $$(basename $@ .tar); ${SUDO} tar -cf "../$@" . ${SUDO} rm -R ./$$(basename $@ .tar) echo DEBIAN_VERSION=$* > debian_version.mk echo GCC_POSTFIX=${gcc_postfix} >> debian_version.mk echo LIBC_POSTFIX=${libc_postfix} >> debian_version.mk echo ADDITIONAL_ARCH_PACKAGES=${additional_arch_packages} >> debian_version.mk # # Debian / ARM EABI # .PHONY: debian_armel_%.tar debian_armel_%.tar: -mkdir ./$$(basename $@ .tar) ${SUDO} ${DBOOTSTRAP} --arch=armel --variant=minbase --include="${PACKAGES}" $* ./$$(basename $@ .tar) http://ftp.debian.org/debian/ (echo "deb http://ftp.debian.org/debian $* main"; \ echo "deb-src http://ftp.debian.org/debian $* main") | ${SUDO} tee ./$$(basename $@ .tar)/etc/apt/sources.list cd $$(basename $@ .tar); ${SUDO} tar -cf "../$@" . ${SUDO} rm -R ./$$(basename $@ .tar) echo DEBIAN_VERSION=$* > debian_version.mk echo GCC_POSTFIX=${gcc_postfix} >> debian_version.mk echo LIBC_POSTFIX=${libc_postfix} >> debian_version.mk echo ADDITIONAL_ARCH_PACKAGES=${additional_arch_packages} >> debian_version.mk # # Debian / ARM64 # .PHONY: debian_arm64_%.tar debian_arm64_%.tar: -mkdir ./$$(basename $@ .tar) ${SUDO} ${DBOOTSTRAP} --arch=arm64 --variant=minbase --include="${PACKAGES}" $* ./$$(basename $@ .tar) http://ftp.debian.org/debian/ (echo "deb http://ftp.debian.org/debian $* main"; \ echo "deb-src http://ftp.debian.org/debian $* main") | ${SUDO} tee ./$$(basename $@ .tar)/etc/apt/sources.list cd $$(basename $@ .tar); ${SUDO} tar -cf "../$@" . ${SUDO} rm -R ./$$(basename $@ .tar) echo DEBIAN_VERSION=$* > debian_version.mk echo GCC_POSTFIX=${gcc_postfix} >> debian_version.mk echo LIBC_POSTFIX=${libc_postfix} >> debian_version.mk echo ADDITIONAL_ARCH_PACKAGES=${additional_arch_packages} >> debian_version.mk # # Debian x86/amd64... # extended for debian_{amd64,i386}_{deb_version}.tar # or old format "debian_{deb_version}.tar" .PHONY: debian_%.tar debian_%.tar: $(eval ARCH:=$(if $(word 3,$(subst _, ,$@)),$(word 2,$(subst _, ,$@)),"i386")) $(eval VERSION:=$(if $(word 3,$(subst _, ,$@)),$(basename $(word 3,$(subst _, ,$@))),$(basename $(word 2,$(subst _, ,$@))))) -mkdir ./$$(basename $@ .tar) ${SUDO} ${DBOOTSTRAP} --arch=${ARCH} --variant=minbase --include="${PACKAGES}" ${VERSION} ./$$(basename $@ .tar) http://ftp.debian.org/debian/ (echo "deb http://ftp.debian.org/debian ${VERSION} main"; \ echo "deb-src http://ftp.debian.org/debian ${VERSION} main") | ${SUDO} tee ./$$(basename $@ .tar)/etc/apt/sources.list cd $$(basename $@ .tar); ${SUDO} tar -cf "../$@" . ${SUDO} rm -R ./$$(basename $@ .tar) echo DEBIAN_VERSION=${VERSION} > debian_version.mk echo GCC_POSTFIX=${gcc_postfix} >> debian_version.mk echo LIBC_POSTFIX=${libc_postfix} >> debian_version.mk echo ADDITIONAL_ARCH_PACKAGES=${additional_arch_packages} >> debian_version.mk -include debian_version.mk # # Debian Cross-Toolchain # debian_toolchain.tar: ${MAKE} make_toolchain # note, this is only a sub-taget, so that we build in a subprocess, and debian_version.mk is included .PHONY: make_toolchain make_toolchain: -mkdir ./debian_toolchain ${SUDO} ${DBOOTSTRAP} --arch=amd64 --variant=minbase --include="${ADDITIONAL_TOOLCHAIN_PACKAGES} gcc${GCC_POSTFIX} libc6-dev${LIBC_POSTFIX} ${ADDITIONAL_ARCH_PACKAGES}" ${DEBIAN_VERSION} ./debian_toolchain http://ftp.debian.org/debian/ ${SUDO} chroot ./debian_toolchain ldconfig cd debian_toolchain && ${SUDO} tar -cf "../debian_toolchain.tar" . ${SUDO} rm -R ./debian_toolchain # # Export environment shell script for the toolchain # define ENV_SH TC_PATH=$$(dirname $$_) SYSROOT=$${TC_PATH}/target INCLUDEDIR=$${TC_PATH}/host/usr/arm-linux-gnueabihf/include/ LIBRARYDIR=$${TC_PATH}/target/usr/lib/arm-linux-gnueabihf/ COMPILE_PREFIX=$${TC_PATH}/host/usr/bin/arm-none-eabi- PLUGINDIR=$$(dirname $$(readlink -f $${TC_PATH}/host/usr/lib/gcc/arm-none-eabi/*/liblto_plugin.so)) HOSTLIBDIR=$${TC_PATH}/host/usr/lib/i386-linux-gnu/:$${TC_PATH}/host/usr/lib/:$${TC_PATH}/host/lib LD_LIBRARY_PATH=$${HOSTLIBDIR} CC=$${COMPILE_PREFIX}gcc CXX=$${COMPILE_PREFIX}g++ LD=$${COMPILE_PREFIX}ld AS=$${COMPILE_PREFIX}as AR=$${COMPILE_PREFIX}ar NM=$${COMPILE_PREFIX}nm GCOV=$${COMPILE_PREFIX}gcov OBJDUMP=$${COMPILE_PREFIX}objdump CFLAGS= LDFLAGS= # common C/LD Flags CFLAGS="$${CFLAGS} --sysroot=$${SYSROOT}" CFLAGS="$${CFLAGS} -B$${PLUGINDIR} -mfloat-abi=hard" LDFLAGS="$${CFLAGS}" # CFLAGS CFLAGS="$${CFLAGS} --sysroot=$${SYSROOT}" CFLAGS="-I$${INCLUDEDIR}" # LDFLAGS LDFALGS="-L$${LIBRARYDIR}" LDFLAGS="$${LDFLAGS} -L$${LIBRARYDIR}" LDFLAGS="$${LDFLAGS} -B$${LIBRARYDIR}" LDFLAGS="$${LDFLAGS} -lc" export CC export CXX export LD export AS export AR export NM export GCOV export OBJDUMP export CFLAGS export LDFLAGS export LD_LIBRARY_PATH endef export ENV_SH debian_toolchain_env.sh: @echo "$${ENV_SH}" > $@ # output some info about the locally generated filesystem info: @[ -f ${OUTPUT_FILE} ] || (echo "The image ${OUTPUT_FILE} is not build, yet."; false) @targethostname="$$(tar -O -xf ${OUTPUT_FILE} ./etc/hostname)"; \ printf "Hostname: %s\n" $${targethostname}; \ printf "IP: %s (if target is running)\n" $$(ping -c 1 "$${targethostname}" 2>&1 | sed -n '/bytes from/ s,.*(\([^)]*\)).*,\1, p'); clean: rm -f debian_version.mk rm -f debian_*.tar rm -f *.piling.tar *.piling.tar.snar for i in ???????.piling/; do sudo rm -Rf "./$$i"; done for i in ????????.piling/; do sudo rm -Rf "./$$i"; done |