├── .dockerignore ├── .gitmodules ├── Dockerfile ├── LICENSE ├── README.md ├── build.sh ├── circle.yml ├── example ├── README.md ├── axel │ ├── .dockerignore │ ├── 00-get-repo.sh │ ├── 01-build-image.sh │ ├── 02-configure.sh │ ├── 03-make.sh │ ├── 04-tar.sh │ ├── Dockerfile │ └── config.sh ├── qtbase │ ├── .dockerignore │ ├── 00-get-repo.sh │ ├── 01-build-image.sh │ ├── 02-configure.sh │ ├── 03-make.sh │ ├── 04-tar.sh │ ├── Dockerfile │ └── config.sh └── run-example.sh └── image ├── etc └── sudoers.d │ └── rpxc-user ├── rpxc ├── entrypoint.sh └── rpxc └── usr └── bin ├── install-debian ├── install-raspbian └── rpdo /.dockerignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | example/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "examples/axel/repo"] 2 | path = example/axel/repo 3 | url = https://github.com/eribertomota/axel.git 4 | [submodule "example/qtbase/repo"] 5 | path = example/qtbase/repo 6 | url = https://github.com/qtproject/qtbase.git 7 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:jessie 2 | 3 | RUN apt-get update \ 4 | && DEBIAN_FRONTEND=noninteractive apt-get install -y apt-utils \ 5 | && DEBIAN_FRONTEND=noninteractive dpkg-reconfigure apt-utils \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get install -y \ 7 | automake \ 8 | cmake \ 9 | curl \ 10 | fakeroot \ 11 | g++ \ 12 | git \ 13 | make \ 14 | runit \ 15 | sudo \ 16 | xz-utils 17 | 18 | # Here is where we hardcode the toolchain decision. 19 | ENV HOST=arm-linux-gnueabihf \ 20 | TOOLCHAIN=gcc-linaro-arm-linux-gnueabihf-raspbian-x64 \ 21 | RPXC_ROOT=/rpxc 22 | 23 | # TOOLCHAIN=arm-rpi-4.9.3-linux-gnueabihf \ 24 | # TOOLCHAIN=gcc-linaro-arm-linux-gnueabihf-raspbian-x64 \ 25 | 26 | WORKDIR $RPXC_ROOT 27 | RUN curl -L https://github.com/raspberrypi/tools/tarball/master \ 28 | | tar --wildcards --strip-components 3 -xzf - "*/arm-bcm2708/$TOOLCHAIN/" 29 | 30 | ENV ARCH=arm \ 31 | CROSS_COMPILE=$RPXC_ROOT/bin/$HOST- \ 32 | PATH=$RPXC_ROOT/bin:$PATH \ 33 | QEMU_PATH=/usr/bin/qemu-arm-static \ 34 | QEMU_EXECVE=1 \ 35 | SYSROOT=$RPXC_ROOT/sysroot 36 | 37 | WORKDIR $SYSROOT 38 | RUN curl -Ls https://github.com/sdhibit/docker-rpi-raspbian/raw/master/raspbian.2015.05.05.tar.xz \ 39 | | tar -xJf - \ 40 | && curl -Ls https://github.com/resin-io-projects/armv7hf-debian-qemu/raw/master/bin/qemu-arm-static \ 41 | > $SYSROOT/$QEMU_PATH \ 42 | && chmod +x $SYSROOT/$QEMU_PATH \ 43 | && mkdir -p $SYSROOT/build \ 44 | && chroot $SYSROOT $QEMU_PATH /bin/sh -c '\ 45 | echo "deb http://archive.raspbian.org/raspbian jessie firmware" \ 46 | >> /etc/apt/sources.list \ 47 | && apt-get update \ 48 | && DEBIAN_FRONTEND=noninteractive apt-get install -y apt-utils \ 49 | && DEBIAN_FRONTEND=noninteractive dpkg-reconfigure apt-utils \ 50 | && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \ 51 | && DEBIAN_FRONTEND=noninteractive apt-get install -y \ 52 | libc6-dev \ 53 | symlinks \ 54 | && symlinks -cors /' 55 | 56 | COPY image/ / 57 | 58 | WORKDIR /build 59 | ENTRYPOINT [ "/rpxc/entrypoint.sh" ] 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2016 Stephen Thirlwall 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CircleCI](https://circleci.com/gh/sdt/docker-raspberry-pi-cross-compiler.svg?style=svg)](https://circleci.com/gh/sdt/docker-raspberry-pi-cross-compiler) 2 | # Raspberry Pi Cross-Compiler in a Docker Container 3 | 4 | An easy-to-use all-in-one cross compiler for the Raspberry Pi. 5 | 6 | This project is available as [sdthirlwall/raspberry-pi-cross-compiler](https://registry.hub.docker.com/u/sdthirlwall/raspberry-pi-cross-compiler/) on [Docker Hub](https://hub.docker.com/), and as [sdt/docker-raspberry-pi-cross-compiler](https://github.com/sdt/docker-raspberry-pi-cross-compiler) on [GitHub](https://github.com). 7 | 8 | Please raise any issues on the [GitHub issue tracker](https://github.com/sdt/docker-raspberry-pi-cross-compiler/issues) as I don't get notified about Docker Hub comments. 9 | 10 | ## Contents 11 | 12 | * [Features](#features) 13 | * [Installation](#installation) 14 | * [Usage](#usage) 15 | * [Configuration](#configuration) 16 | * [Custom Images](#custom-images) 17 | * [Examples](#examples) 18 | 19 | ## Features 20 | 21 | * The [gcc-linaro-arm-linux-gnueabihf-raspbian-x64 toolchain](https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64) from [raspberrypi/tools](https://github.com/raspberrypi/tools) 22 | * Raspbian sysroot from [sdhibit/docker-rpi-raspbian](https://github.com/sdhibit/docker-rpi-raspbian) :new: 23 | * Easy installation of raspbian packages into the sysroot using the [customised qemu arm emulator](https://resin.io/blog/building-arm-containers-on-any-x86-machine-even-dockerhub/) from [resin-io-projects/armv7hf-debian-qemu](https://github.com/resin-io-projects/armv7hf-debian-qemu) :new: 24 | * Easy-to-use front end wrapper program `rpxc`. 25 | 26 | ## Installation 27 | 28 | This image is not intended to be run manually. Instead, there is a helper script which comes bundled with the image. 29 | 30 | To install the helper script, run the image with no arguments, and redirect the output to a file. 31 | 32 | eg. 33 | ``` 34 | docker run sdthirlwall/raspberry-pi-cross-compiler > ~/bin/rpxc 35 | chmod +x ~/bin/rpxc 36 | ``` 37 | 38 | ## Usage 39 | 40 | `rpxc [command] [args...]` 41 | 42 | Execute the given command-line inside the container. 43 | 44 | If the command matches one of the rpxc built-in commands (see below), that will be executed locally, otherwise the command is executed inside the container. 45 | 46 | `rpxc -- [command] [args...]` 47 | 48 | To force a command to run inside the container (in case of a name clash with a built-in command), use `--` before the command. 49 | 50 | ### Built-in commands 51 | 52 | #### install-debian 53 | 54 | `rpxc install-debian [--update] package packages...` 55 | 56 | Install native packages into the docker image. Changes are committed back to the sdthirlwall/raspberry-pi-cross-compiler image. 57 | 58 | #### install-raspbian 59 | 60 | `rpxc install-raspbian [--update] package packages...` 61 | 62 | Install raspbian packages from the raspbian repositories into the sysroot of thedocker image. Changes are committed back to the sdthirlwall/raspberry-pi-cross-compiler image. 63 | 64 | #### update-image 65 | 66 | `rpxc update-image` 67 | 68 | Pull the latest version of the docker image. 69 | 70 | If a new docker image is available, any extra packages installed with `install-debian` or `install-raspbian` _will be lost_. 71 | 72 | #### update-script 73 | 74 | `rpxc update-script` 75 | 76 | Update the installed rpxc script with the one bundled in the image. 77 | 78 | #### update 79 | 80 | `rpxc update` 81 | 82 | Update both the docker image and the rpxc script. 83 | 84 | ## Configuration 85 | 86 | The following command-line options and environment variables are used. In all cases, the command-line option overrides the environment variable. 87 | 88 | ### RPXC_CONFIG / --config <path-to-config-file> 89 | 90 | This file is sourced if it exists. 91 | 92 | Default: `~/.rpxc` 93 | 94 | ### RPXC_IMAGE / --image <docker-image-name> 95 | 96 | The docker image to run. 97 | 98 | Default: sdthirlwall/raspberry-pi-cross-compiler 99 | 100 | ### RPXC_ARGS / --args <docker-run-args> 101 | 102 | Extra arguments to pass to the `docker run` command. 103 | 104 | ## Custom Images 105 | 106 | Using `rpxc install-debian` and `rpxc install-raspbian` are really only intended for getting a build environment together. Once you've figured out which debian and raspbian packages you need, it's better to create a custom downstream image that has all your tools and development packages built in. 107 | 108 | ### Create a Dockerfile 109 | 110 | ```Dockerfile 111 | FROM sdthirlwall/raspberry-pi-cross-compiler 112 | 113 | # Install some native build-time tools 114 | RUN install-debian scons 115 | 116 | # Install raspbian development libraries 117 | RUN install-raspbian libboost-dev-all 118 | ``` 119 | 120 | ### Name your image with an RPXC_IMAGE variable and build the image 121 | 122 | ```sh 123 | export RPXC_IMAGE=my-custom-rpxc-image 124 | docker build -t $RPXC_IMAGE . 125 | ``` 126 | 127 | ### With RPXC_IMAGE set, rpxc will automatically use your new image. 128 | 129 | ```sh 130 | # These are typical cross-compilation flags to pass to configure. 131 | # Note the use of single quotes in the shell command-line. We want the 132 | # variables to be interpolated in the container, not in the host system. 133 | rpxc sh -c 'CFLAGS=--sysroot=$SYSROOT ./configure --host=$HOST' 134 | rpxc make 135 | ``` 136 | 137 | Another way to achieve this is to create a shell script. 138 | 139 | ```sh 140 | #!/bin/sh 141 | CFLAGS=--sysroot=$SYSROOT ./configure --host=$HOST 142 | make 143 | ``` 144 | 145 | And call it as `rpxc ./mymake.sh` 146 | 147 | ## Examples 148 | 149 | See the [examples directory](https://github.com/sdt/docker-raspberry-pi-cross-compiler/tree/master/example) for some real examples. 150 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | : ${RPXC_IMAGE:=sdthirlwall/raspberry-pi-cross-compiler} 4 | 5 | docker build -t $RPXC_IMAGE . 6 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | environment: 3 | RPXC_IMAGE: sdthirlwall/raspberry-pi-cross-compiler 4 | RPXC_SCRIPT: "/home/ubuntu/bin/rpxc" 5 | RPXC_DISTRO: jessie 6 | 7 | services: 8 | - docker 9 | 10 | dependencies: 11 | override: 12 | - ./build.sh 13 | - docker run --rm $RPXC_IMAGE > $RPXC_SCRIPT 14 | - chmod +x $RPXC_SCRIPT 15 | 16 | test: 17 | override: 18 | - ./example/run-example.sh ./example/axel 19 | 20 | deployment: 21 | hub: 22 | branch: master 23 | commands: 24 | - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD 25 | - docker push $RPXC_IMAGE 26 | - docker tag $RPXC_IMAGE $RPXC_IMAGE:$RPXC_DISTRO 27 | - docker push $RPXC_IMAGE:$RPXC_DISTRO 28 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # rpxc examples 2 | 3 | This directory contains examples using rpxc to build real software packages. 4 | 5 | Each one contains a git submodule link to the github repo, as well as the 6 | following files: 7 | 8 | * `config.sh` has environment variables and is sourced by the other scripts 9 | * `00-get-repo.sh` to pull down the submodule to `repo/` 10 | * `01-build-image.sh` to build a downstream rpxc image from `Dockerfile` 11 | * `02-configure.sh` runs the one-off configure scripts for the source package 12 | * `03-make.sh` builds the package 13 | * `04-tar.sh` installs the package and tars up the install files 14 | 15 | The interesting parts are usually in `02-configure.sh`, where we coax the 16 | software package into cross-compiling in the rpxc environment. 17 | -------------------------------------------------------------------------------- /example/axel/.dockerignore: -------------------------------------------------------------------------------- 1 | repo/ 2 | -------------------------------------------------------------------------------- /example/axel/00-get-repo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | git submodule sync 4 | git submodule update --init --recursive -- ./repo 5 | -------------------------------------------------------------------------------- /example/axel/01-build-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source config.sh 4 | docker build -t $RPXC_IMAGE . 5 | -------------------------------------------------------------------------------- /example/axel/02-configure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source config.sh 4 | 5 | cd repo 6 | rpxc ./autogen.sh 7 | rpxc sh -c 'CFLAGS=--sysroot=$SYSROOT ./configure --host=$HOST --prefix=/opt' 8 | -------------------------------------------------------------------------------- /example/axel/03-make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source config.sh 4 | 5 | cd repo 6 | rpxc make "$@" 7 | -------------------------------------------------------------------------------- /example/axel/04-tar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source config.sh 4 | 5 | cd repo 6 | rpxc sh -c 'sudo make install && fakeroot tar -czvf /build/axel.tar.gz /opt/' 7 | -------------------------------------------------------------------------------- /example/axel/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM sdthirlwall/raspberry-pi-cross-compiler 2 | 3 | # axel uses gettext in the build context 4 | RUN install-debian --update gettext 5 | 6 | # axel links against openssl 7 | RUN install-raspbian --update libssl-dev 8 | -------------------------------------------------------------------------------- /example/axel/config.sh: -------------------------------------------------------------------------------- 1 | # This file gets sourced from the shell scripts in this directory. 2 | export RPXC_IMAGE=rpxc-axel 3 | -------------------------------------------------------------------------------- /example/qtbase/.dockerignore: -------------------------------------------------------------------------------- 1 | repo/ 2 | -------------------------------------------------------------------------------- /example/qtbase/00-get-repo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | git submodule sync 4 | git submodule update --init --recursive -- ./repo 5 | -------------------------------------------------------------------------------- /example/qtbase/01-build-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source config.sh 4 | docker build -t $RPXC_IMAGE . 5 | -------------------------------------------------------------------------------- /example/qtbase/02-configure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source config.sh 4 | 5 | cd repo 6 | rpxc sh -c './configure -v -device linux-rasp-pi2-g++ -device-option CROSS_COMPILE=$CROSS_COMPILE -sysroot $SYSROOT -prefix /opt -extprefix /opt -opensource -confirm-license -make libs -nomake tests -no-linuxfb -no-xcb -no-qml-debug -no-cups -no-pulseaudio -no-alsa -no-evdev -qt-libjpeg -qt-libpng' 7 | -------------------------------------------------------------------------------- /example/qtbase/03-make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source config.sh 4 | 5 | cd repo 6 | rpxc make "$@" 7 | -------------------------------------------------------------------------------- /example/qtbase/04-tar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source config.sh 4 | 5 | cd repo 6 | rpxc sh -c 'sudo make install && fakeroot tar -czvf /build/qtbase.tar.gz /opt/' 7 | -------------------------------------------------------------------------------- /example/qtbase/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM sdthirlwall/raspberry-pi-cross-compiler 2 | 3 | # axel uses gettext in the build context 4 | RUN install-debian --update build-essential python 5 | 6 | # axel links against openssl 7 | RUN install-raspbian --update libgles2-mesa-dev zlib1g zlib1g-dev 8 | -------------------------------------------------------------------------------- /example/qtbase/config.sh: -------------------------------------------------------------------------------- 1 | # This file gets sourced from the shell scripts in this directory. 2 | export RPXC_IMAGE=rpxc-qt 3 | -------------------------------------------------------------------------------- /example/run-example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | if [[ $# != 1 ]]; then 4 | echo usage: $0 example-dir 1>&2 5 | exit 1 6 | fi 7 | 8 | cd $1 9 | ./00-get-repo.sh 10 | ./01-build-image.sh 11 | ./02-configure.sh 12 | ./03-make.sh 13 | ./04-tar.sh 14 | -------------------------------------------------------------------------------- /image/etc/sudoers.d/rpxc-user: -------------------------------------------------------------------------------- 1 | rpxc-user ALL=(ALL:ALL) NOPASSWD: ALL 2 | -------------------------------------------------------------------------------- /image/rpxc/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is the entrypoint script for the dockerfile. Executed in the 4 | # container at runtime. 5 | 6 | if [[ $# == 0 ]]; then 7 | # Presumably the image has been run directly, so help the user get started. 8 | cat /rpxc/rpxc 9 | exit 0 10 | fi 11 | 12 | # If we are running docker natively, we want to create a user in the container 13 | # with the same UID and GID as the user on the host machine, so that any files 14 | # created are owned by that user. Without this they are all owned by root. 15 | # If we are running from boot2docker, this is not necessary, and you end up not 16 | # being able to write to the volume. 17 | # The rpxc script sets the RPXC_UID and RPXC_GID vars. 18 | if [[ -n $RPXC_UID ]] && [[ -n $RPXC_GID ]]; then 19 | 20 | RPXC_USER=rpxc-user 21 | RPXC_GROUP=rpxc-group 22 | RPXC_HOME=/home/$RPXC_USER 23 | 24 | groupadd -o -g $RPXC_GID $RPXC_GROUP 2> /dev/null 25 | useradd -o -m -d $RPXC_HOME -g $RPXC_GID -u $RPXC_UID $RPXC_USER 2> /dev/null 26 | 27 | # Run the command as the specified user/group. 28 | HOME=$RPXC_HOME exec chpst -u :$RPXC_UID:$RPXC_GID "$@" 29 | else 30 | # Just run the command as root. 31 | exec "$@" 32 | fi 33 | -------------------------------------------------------------------------------- /image/rpxc/rpxc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #------------------------------------------------------------------------------ 4 | # Helpers 5 | # 6 | err() { 7 | echo -e >&2 ERROR: $@\\n 8 | } 9 | 10 | die() { 11 | err $@ 12 | exit 1 13 | } 14 | 15 | has() { 16 | # eg. has command update 17 | local kind=$1 18 | local name=$2 19 | 20 | type -t $kind:$name | grep -q function 21 | } 22 | 23 | #------------------------------------------------------------------------------ 24 | # Command handlers 25 | # 26 | command:update-image() { 27 | docker pull $FINAL_IMAGE 28 | } 29 | 30 | help:update-image() { 31 | echo Pull the latest $FINAL_IMAGE . 32 | } 33 | 34 | command:update-script() { 35 | local newfile=$( mktemp ) 36 | if docker run $FINAL_IMAGE > $newfile; then 37 | if [[ -s $newfile ]]; then 38 | if ! cmp -s $0 $newfile; then 39 | echo -n Updating $0 '... ' 40 | chmod 755 $newfile && mv $newfile $0 && echo ok 41 | else 42 | echo $0 is up to date. 43 | fi 44 | fi 45 | fi 46 | rm -f $newfile 47 | } 48 | 49 | help:update-image() { 50 | echo Update $0 from $FINAL_IMAGE . 51 | } 52 | 53 | command:update() { 54 | command:update-image && command:update-script 55 | } 56 | 57 | install-packages() { 58 | local installer=$1 59 | shift 60 | 61 | CONTAINER=rpxc-temp-$$ 62 | docker rm -f $CONTAINER >/dev/null 2>/dev/null 63 | set -e 64 | docker run -ti --name $CONTAINER $FINAL_IMAGE $installer "$@" 65 | docker commit $CONTAINER $FINAL_IMAGE 66 | docker rm -f $CONTAINER 67 | echo Updated image: $FINAL_IMAGE. 68 | } 69 | 70 | command:install-debian() { 71 | install-packages install-debian "$@" 72 | } 73 | 74 | help:install-debian() { 75 | echo usage: rpxc install-debian [--update] package \[packages...\] 76 | echo Install native debian packages into $FINAL_IMAGE . 77 | echo Use --update to run apt-get update beforehand. 78 | } 79 | 80 | command:install-raspbian() { 81 | install-packages install-raspbian "$@" 82 | } 83 | 84 | help:install-raspbian() { 85 | echo usage: rpxc install-raspbian [--update] package \[packages...\] 86 | echo Install raspbian packages into the sysroot of $FINAL_IMAGE . 87 | echo Use --update to run apt-get update beforehand. 88 | } 89 | 90 | help:update() { 91 | echo Pull the latest $FINAL_IMAGE, and then update $0 from that. 92 | } 93 | 94 | command:help() { 95 | if [[ $# != 0 ]]; then 96 | if ! has command $1; then 97 | err \"$1\" is not an rpxc command 98 | command:help 99 | elif ! has help $1; then 100 | err No help found for \"$1\" 101 | else 102 | help:$1 103 | fi 104 | else 105 | cat >&2 < 118 | ENDHELP 119 | fi 120 | } 121 | 122 | #------------------------------------------------------------------------------ 123 | # Option processing 124 | # 125 | while [[ $# != 0 ]]; do 126 | case $1 in 127 | 128 | --) 129 | break 130 | ;; 131 | 132 | --args) 133 | ARG_ARGS="$2" 134 | shift 2 135 | ;; 136 | 137 | --config) 138 | ARG_CONFIG="$2" 139 | shift 2 140 | ;; 141 | 142 | --image) 143 | ARG_IMAGE="$2" 144 | shift 2 145 | ;; 146 | 147 | -*) 148 | err Unknown option \"$1\" 149 | command:help 150 | exit 151 | ;; 152 | 153 | *) 154 | break 155 | ;; 156 | 157 | esac 158 | done 159 | 160 | # The precedence for options is: 161 | # 1. command-line arguments 162 | # 2. environment variables 163 | # 3. defaults 164 | 165 | # Source the config file if it exists 166 | DEFAULT_CONFIG=~/.rpxc 167 | FINAL_CONFIG=${ARG_CONFIG-${RPXC_CONFIG-$DEFAULT_CONFIG}} 168 | 169 | [[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG" 170 | 171 | # Set the docker image 172 | DEFAULT_IMAGE=sdthirlwall/raspberry-pi-cross-compiler 173 | FINAL_IMAGE=${ARG_IMAGE-${RPXC_IMAGE-$DEFAULT_IMAGE}} 174 | 175 | # Set the docker run extra args (if any) 176 | FINAL_ARGS=${ARG_ARGS-${RPXC_ARGS}} 177 | 178 | # If we are not running via boot2docker 179 | if [ -z $DOCKER_HOST ]; then 180 | USER_IDS="-e RPXC_UID=$( id -u ) -e RPXC_GID=$( id -g )" 181 | fi 182 | 183 | #------------------------------------------------------------------------------ 184 | # Command-line processing 185 | # 186 | if [[ $# == 0 ]]; then 187 | command:help 188 | exit 189 | fi 190 | 191 | case $1 in 192 | 193 | --) 194 | # Everything after this is the command-line to be executed 195 | shift 196 | ;; 197 | 198 | *) 199 | # If this is a builtin command, execute it, otherwise fall through 200 | if has command $1; then 201 | command:$1 "${@:2}" # array slice skipping first element 202 | exit $? 203 | fi 204 | ;; 205 | 206 | esac 207 | 208 | #------------------------------------------------------------------------------ 209 | # Now, finally, run the command in a container 210 | # 211 | docker run -i -t --rm \ 212 | -v $PWD:/build \ 213 | -v $PWD:/rpxc/sysroot/build \ 214 | $USER_IDS \ 215 | $FINAL_ARGS \ 216 | $FINAL_IMAGE "$@" 217 | 218 | ################################################################################ 219 | # 220 | # This image is not intended to be run manually. 221 | # 222 | # To install the rpxc helper, run the following commands: 223 | # 224 | # docker run sdthirlwall/raspberry-pi-cross-compiler > rpxc 225 | # chmod +x rpxc 226 | # 227 | # You may then wish to move rpxc to somewhere in your path. 228 | # 229 | ################################################################################ 230 | -------------------------------------------------------------------------------- /image/usr/bin/install-debian: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ $# -eq 0 ]; then 6 | echo usage: install-debian [--update] package [packages...] 7 | exit 1 8 | fi 9 | 10 | if [ "$1" = "--update" ]; then 11 | shift 12 | apt-get update 13 | fi 14 | 15 | DEBIAN_FRONTEND=noninteractive apt-get install -y "$@" 16 | -------------------------------------------------------------------------------- /image/usr/bin/install-raspbian: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ $# -eq 0 ]; then 6 | echo usage: install-raspbian [--update] package [packages...] 7 | exit 1 8 | fi 9 | 10 | if [ "$1" = "--update" ]; then 11 | shift 12 | rpdo apt-get update 13 | fi 14 | 15 | rpdo DEBIAN_FRONTEND=noninteractive apt-get install -y "$@" 16 | rpdo symlinks -cors / 17 | -------------------------------------------------------------------------------- /image/usr/bin/rpdo: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # cd into $SYSROOT so that $PWD is inside the chroot 4 | cd $SYSROOT 5 | 6 | # Execute raspbian binaries using the qemu-arm-static emulator, while chrooted 7 | # to the sysroot. 8 | # If we're running as the $RPXC_USER we need to sudo to root to perform the 9 | # chroot, and then drop back down to the user afterwards. 10 | if [ -z "$RPXC_UID" ]; then 11 | chroot $SYSROOT \ 12 | $QEMU_PATH /bin/sh -c "cd /build && $*" 13 | else 14 | sudo -E chroot --userspec $RPXC_UID:$RPXC_GID $SYSROOT \ 15 | $QEMU_PATH /bin/sh -c "cd /build && $*" 16 | fi 17 | --------------------------------------------------------------------------------