Skip to content
This repository has been archived by the owner on Mar 11, 2019. It is now read-only.

[WIP] creation of an x86_64 build environment #2

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9f5d165
enh: create Dockerfile based on Slackware 14.1 for x86_64 builds
jopasserat Nov 17, 2016
4ef0c69
enh: add basic docker commands to README
jopasserat Nov 17, 2016
063edcf
enh: bump care and proot versions (integrate fix loader patch)
jopasserat Nov 17, 2016
3312688
Merge branch 'build_environment' of github.com:proot-me/proot-static-…
jopasserat Nov 17, 2016
b49b8de
Cleaner dockerfile based on debian jessie.
romainreuillon Nov 27, 2016
05dc96e
Merge pull request #3 from romainreuillon/build_environment
jopasserat Nov 28, 2016
8807e32
enh: specify jessie as Debian version and clean comments
jopasserat Nov 28, 2016
0a4be15
enh: add target building only libs and support destination folder for…
jopasserat Nov 29, 2016
14c324b
enh: Bake static libs build in Docker
jopasserat Nov 29, 2016
2187a25
enh: rewrite build script to call make in docker as one liner (and co…
jopasserat Nov 29, 2016
1168e38
enh: update README with new command lines
jopasserat Nov 29, 2016
d4b02c1
enh: update README with new command lines
jopasserat Nov 29, 2016
f33ef11
enh: add possibility to mount other volumes and change destinations +…
jopasserat Nov 29, 2016
7af3e62
Merge branch 'build_environment' of github.com:proot-me/proot-static-…
jopasserat Nov 29, 2016
49daa89
enh: rename Docker to make clearer it only target x86_64 archs
jopasserat Dec 21, 2016
742a84e
enh: lint Dockerfile
jopasserat Apr 13, 2017
80d5e4e
enh: update README
jopasserat Sep 7, 2017
fd6e053
enh: generate proot and care licenses upstream
jopasserat Sep 7, 2017
79313c5
enh: switch Dockerfile to multi-stage build
jopasserat Sep 7, 2017
49e9077
enh: try to mount latest version of sources by default
jopasserat Sep 8, 2017
04de69f
fix: missing file and set build dir permissions
jopasserat Sep 8, 2017
d4c66a0
fix: simplify user management
jopasserat Sep 8, 2017
4d08c91
enh: split build of environment and tools
jopasserat Sep 8, 2017
d75a917
enh: lint build.sh
jopasserat Sep 8, 2017
68dc928
fix: update README to new makefile
jopasserat Sep 8, 2017
21f4b39
enh: inject version files at runtime and use info in build
jopasserat Sep 16, 2017
3f703f1
enh: simplify build script
jopasserat Sep 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Dockerfile.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM debian:jessie as builder
MAINTAINER Jonathan Passerat-Palmbach, Imperial College London <[email protected]>

RUN apt-get -y update && \
apt-get -y --no-install-recommends install build-essential gawk autoconf autotools-dev python cmake uthash-dev


COPY packages /opt/build/packages
COPY versions.mak GNUmakefile /opt/build/
WORKDIR /opt/build

RUN make -f GNUmakefile all_libs -j4

FROM debian:jessie
WORKDIR /usr
COPY --from=builder /usr .
WORKDIR /opt/build
RUN chmod 1777 /opt/build
COPY --from=builder /opt/build/prefix /opt/build/prefix/
COPY versions.mak /opt/build/
COPY GNUmakefile_tools /opt/build/GNUmakefile

CMD bash

148 changes: 68 additions & 80 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
# -q qemu-sh4
# make ...

proot-version = proot-v5.1.0
care-version = care-v2.2.1
glibc-version = glibc-2.16.0
include versions.mak

glibc-version = glibc-2.19
libtalloc-version = talloc-2.1.1
libarchive-version = libarchive-3.1.2
libz-version = zlib-1.2.8
Expand All @@ -45,12 +45,6 @@ liblzo_a = $(prefix)/lib/liblzo2.a

env = CFLAGS="-g -O2 -isystem $(prefix)/include" LDFLAGS="-L$(prefix)/lib"

VPATH := $(dir $(lastword $(MAKEFILE_LIST)))
packages = $(VPATH)/packages
prefix = $(PWD)/prefix
$(prefix):
mkdir $@

$(libc_a):
tar -xzf $(packages)/$(glibc-version).tar.gz
mkdir $(glibc-version)/build
Expand Down Expand Up @@ -97,76 +91,70 @@ $(liblzo_a): $(libc_a)
all_libs_a = $(libc_a) $(libtalloc_a) $(libarchive_a) $(libz_a) $(liblzo_a)

proot-licenses: $(libc_a) $(libtalloc_a)
@echo "" >> $@
@echo "This version of PRoot is statically linked to the following software." >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "glibc:" >> $@
@echo "" >> $@
@$(glibc-license) >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "libtalloc:" >> $@
@echo "" >> $@
@$(libtalloc-license) >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "The build-system, sources and licences are available on:" >> $@
@echo "" >> $@
@echo " https://github.com/cedric-vincent/proot-static-build">> $@
mkdir -p $(prefix)/licenses
@echo "" >> $(prefix)/licenses/$@
@echo "This version of PRoot is statically linked to the following software." >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "glibc:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@$(glibc-license) >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "libtalloc:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@$(libtalloc-license) >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "The build-system, sources and licences are available on:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@echo " https://github.com/cedric-vincent/proot-static-build">> $(prefix)/licenses/$@

care-licenses: $(all_libs_a)
@echo "" >> $@
@echo "This version of CARE is statically linked to the following software." >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "proot:" >> $@
@echo "" >> $@
@echo " * Copyright (C) 2013 STMicroelectronics" >> $@
@echo " *" >> $@
@echo " * This program is free software; you can redistribute it and/or" >> $@
@echo " * modify it under the terms of the GNU General Public License as" >> $@
@echo " * published by the Free Software Foundation; either version 2 of the" >> $@
@echo " * License, or (at your option) any later version." >> $@
@echo " *" >> $@
@echo " * This program is distributed in the hope that it will be useful, but" >> $@
@echo " * WITHOUT ANY WARRANTY; without even the implied warranty of" >> $@
@echo " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU" >> $@
@echo " * General Public License for more details." >> $@
@echo " *" >> $@
@echo " * You should have received a copy of the GNU General Public License" >> $@
@echo " * along with this program; if not, write to the Free Software" >> $@
@echo " * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA" >> $@
@echo " * 02110-1301 USA." >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "glibc:" >> $@
@echo "" >> $@
@$(glibc-license) >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "libtalloc:" >> $@
@echo "" >> $@
@$(libtalloc-license) >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "libarchive:" >> $@
@echo "" >> $@
@$(libarchive-license) >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "zlib:" >> $@
@echo "" >> $@
@$(libz-license) >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "liblzo:" >> $@
@echo "" >> $@
@$(liblzo-license) >> $@
@echo "------------------------------------------------------------------------" >> $@
@echo "The build-system, sources and licences are available on:" >> $@
@echo "" >> $@
@echo " https://github.com/cedric-vincent/proot-static-build">> $@

care: $(all_libs_a) care-licenses
tar -xzf $(packages)/$(care-version).tar.gz
cp care-licenses $(care-version)/src/licenses
env OBJECTS="cli/care-licenses.o" LDFLAGS="-static -L$(prefix)/lib -larchive -lz -llzo2" CPPFLAGS="-isystem $(prefix)/include -DCARE_BINARY_IS_PORTABLE " $(MAKE) -C $(care-version)/src/ care GIT=false
cp $(care-version)/src/$@ .

proot: $(libc_a) $(libtalloc_a) proot-licenses
tar -xzf $(packages)/$(proot-version).tar.gz
cp proot-licenses $(proot-version)/src/licenses
env OBJECTS="cli/proot-licenses.o" LDFLAGS="-static -L$(prefix)/lib" CPPFLAGS="-isystem $(prefix)/include" $(MAKE) -C $(proot-version)/src/ GIT=false
cp $(proot-version)/src/$@ .
mkdir -p $(prefix)/licenses
@echo "" >> $(prefix)/licenses/$@
@echo "This version of CARE is statically linked to the following software." >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "proot:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@echo " * Copyright (C) 2013 STMicroelectronics" >> $(prefix)/licenses/$@
@echo " *" >> $(prefix)/licenses/$@
@echo " * This program is free software; you can redistribute it and/or" >> $(prefix)/licenses/$@
@echo " * modify it under the terms of the GNU General Public License as" >> $(prefix)/licenses/$@
@echo " * published by the Free Software Foundation; either version 2 of the" >> $(prefix)/licenses/$@
@echo " * License, or (at your option) any later version." >> $(prefix)/licenses/$@
@echo " *" >> $(prefix)/licenses/$@
@echo " * This program is distributed in the hope that it will be useful, but" >> $(prefix)/licenses/$@
@echo " * WITHOUT ANY WARRANTY; without even the implied warranty of" >> $(prefix)/licenses/$@
@echo " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU" >> $(prefix)/licenses/$@
@echo " * General Public License for more details." >> $(prefix)/licenses/$@
@echo " *" >> $(prefix)/licenses/$@
@echo " * You should have received a copy of the GNU General Public License" >> $(prefix)/licenses/$@
@echo " * along with this program; if not, write to the Free Software" >> $(prefix)/licenses/$@
@echo " * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA" >> $(prefix)/licenses/$@
@echo " * 02110-1301 USA." >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "glibc:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@$(glibc-license) >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "libtalloc:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@$(libtalloc-license) >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "libarchive:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@$(libarchive-license) >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "zlib:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@$(libz-license) >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "liblzo:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@$(liblzo-license) >> $(prefix)/licenses/$@
@echo "------------------------------------------------------------------------" >> $(prefix)/licenses/$@
@echo "The build-system, sources and licences are available on:" >> $(prefix)/licenses/$@
@echo "" >> $(prefix)/licenses/$@
@echo " https://github.com/cedric-vincent/proot-static-build">> $(prefix)/licenses/$@


all_libs: $(all_libs_a) care-licenses proot-licenses

16 changes: 16 additions & 0 deletions GNUmakefile_tools
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include versions.mak

care:
tar --transform='s,care-[^/]*,$(care-version),g' -zx -f $(packages)/$(care-version).tar.gz
cp $(prefix)/licenses/care-licenses $(care-version)/src/licenses
env OBJECTS="cli/care-licenses.o" LDFLAGS="-static -L$(prefix)/lib -larchive -lz -llzo2" CPPFLAGS="-isystem $(prefix)/include -DCARE_BINARY_IS_PORTABLE " $(MAKE) -C $(care-version)/src/ care GIT=false
mkdir -p ./target
cp $(care-version)/src/$@ $(prefix)/licenses/care-licenses ./target/

proot:
tar --transform="s,proot-[^/]*,$(proot-version),g" -zx -f $(packages)/$(proot-version).tar.gz
cp $(prefix)/licenses/proot-licenses $(proot-version)/src/licenses
env OBJECTS="cli/proot-licenses.o" LDFLAGS="-static -L$(prefix)/lib" CPPFLAGS="-isystem $(prefix)/include" $(MAKE) -C $(proot-version)/src/ GIT=false
mkdir -p ./target
cp $(proot-version)/src/$@ $(prefix)/licenses/proot-licenses ./target/

91 changes: 67 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,75 @@
# proot-static-build
Build static variants of PRoot

PRoot static binaries were built using:
PRoot static binaries were built using:

https://github.com/proot-me/proot-static-build
https://github.com/proot-me/proot-static-build

The ARM one was built on x86_64 using this command:

# Build PRoot/ARM statically:
cd ~/git/proot-static-build
mkdir build-arm
cd build-arm
proot -R ~/rootfs/slackwarearm-14.1 -b $(which cmake) -q qemu-arm make glibc-version=glibc-2.18 -f ../GNUmakefile proot -j4

## Docker build environment ##

Build the Docker container:

`docker build -t proot/proot-buildenv:latest -f Dockerfile.x86_64 .`

Run a build
`./build.sh make care proot -j4`

This creates a `target` folder with both static binaries for care and proot.

## Special variables

If needed you can override the default values by prefixing the call to `build.sh` with these variables.

### `PROOT_TARBALL` and `CARE_TARBALL`

- Must point to an **absolute path**
- Contains the path to a tarball of the source directories (including the parent project directory, see *Important notes* below to learn how to generate such a tarball)
- Example: `PROOT_TARBALL="/tmp/proot-portmap-seccomp.tar.gz" CARE_TARBALL="/tmp/care-portmap-seccomp.tar.gz" ./build.sh make care proot -j4`

### `TARGET_DIR`

- This is the destination folder for static binaries
- Example: `TARGET_DIR=/tmp/mytarget`

### Example of modified command line

`VOLUMES=/data/my_modified_proot.tar.gz:/opt/build/packages/proot-latest.tar.gz;/data/my_modified_care.tar.gz:/opt/build/packages/care-latest.tar.gz TARGET_DIR=/tmp/mytarget ./build.sh make care proot -j4`


### Important Notes ###

- When preparing your modified version of the proot source tree to be statically build, think of cleaning the target files before generating the tarball:
`make clean`

- The paths within the source archives **must match** those in the `GNUmakefile` file. They can be renamed on the fly using the following command (assuming a source directory named `PRoot`):
`tar cfz proot-latest.tar.gz PRoot --transform='s/PRoot/proot-latest/g'`


## Legacy builds (pre 5.1.1)

The ARM one was built on x86_64 using this command:

# Build PRoot/ARM statically:
cd ~/git/proot-static-build
mkdir build-arm
cd build-arm
proot -R ~/rootfs/slackwarearm-14.1 -b $(which cmake) -q qemu-arm make glibc-version=glibc-2.18 -f ../GNUmakefile proot -j4

Where slackwarearm-14.1 was created this way:

# Get Slackware/ARM packages:
wget -r -np http://ftp.arm.slackware.com/slackwarearm/slackwarearm-14.1/slackware/{a,ap,d,e,l,n,tcl}/
mkdir ~/rootfs/slackwarearm-14.1
# Extract only a minimal subset (ignore errors):
ls ftp.arm.slackware.com/slackwarearm/slackwarearm-14.1/slackware/{a,l}/*.t?z | xargs -n 1 tar -C ~/rootfs/slackwarearm-14.1 -xf

# Do a minimal post-installation setup:
mv ~/rootfs/slackwarearm-14.1/lib/incoming/* ~/rootfs/slackwarearm-14.1/lib/
mv ~/rootfs/slackwarearm-14.1/bin/bash4.new ~/rootfs/slackwarearm-14.1/bin/bash
proot -q qemu-arm -r ~/rootfs/slackwarearm-14.1 /sbin/ldconfig
proot -q qemu-arm -r ~/rootfs/slackwarearm-14.1 ln -s /bin/bash /bin/sh

# Install all package correcty (ignore warnings):
ls ftp.arm.slackware.com/slackwarearm/slackwarearm-14.1/slackware/*/*.t?z | xargs -n 1 proot -q qemu-arm -S ~/rootfs/slackwarearm-14.1 -b ftp.arm.slackware.com installpkg
# Get Slackware/ARM packages:
wget -r -np http://ftp.arm.slackware.com/slackwarearm/slackwarearm-14.1/slackware/{a,ap,d,e,l,n,tcl}/
mkdir ~/rootfs/slackwarearm-14.1

# Extract only a minimal subset (ignore errors):
ls ftp.arm.slackware.com/slackwarearm/slackwarearm-14.1/slackware/{a,l}/*.t?z | xargs -n 1 tar -C ~/rootfs/slackwarearm-14.1 -xf

# Do a minimal post-installation setup:
mv ~/rootfs/slackwarearm-14.1/lib/incoming/* ~/rootfs/slackwarearm-14.1/lib/
mv ~/rootfs/slackwarearm-14.1/bin/bash4.new ~/rootfs/slackwarearm-14.1/bin/bash
proot -q qemu-arm -r ~/rootfs/slackwarearm-14.1 /sbin/ldconfig
proot -q qemu-arm -r ~/rootfs/slackwarearm-14.1 ln -s /bin/bash /bin/sh

# Install all package correcty (ignore warnings):
ls ftp.arm.slackware.com/slackwarearm/slackwarearm-14.1/slackware/*/*.t?z | xargs -n 1 proot -q qemu-arm -S ~/rootfs/slackwarearm-14.1 -b ftp.arm.slackware.com installpkg
47 changes: 47 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

### VARIABLES

DOCKER_IMAGE='proot/proot-buildenv:latest'

BUILD_DIR="/opt/build"
GROUP_ID=$(id -g)
USER_ID=$(id -u)

# must be an absolute path
TARGET_DIR=${TARGET_DIR:-"$(pwd)/target"}
VERSIONS_FILE="$(dirname $(readlink -f $0))/versions.mak"

PROOT_VERSION="$(grep 'proot-version' ${VERSIONS_FILE} | tr -s ' ' | cut -d ' ' -f 3)"
CARE_VERSION="$(grep 'care-version' ${VERSIONS_FILE} | tr -s ' ' | cut -d ' ' -f 3)"
PROOT_TARBALL=${PROOT_TARBALL:-"$(pwd)/src/${PROOT_VERSION}.tar.gz"}
CARE_TARBALL=${CARE_TARBALL:-"$(pwd)/src/${CARE_VERSION}.tar.gz"}

# VOLUMES must be formatted as Docker expects them -> /path_on_host:/mountpoint
# specify multiple volumes using the ; separator
# if no volume specified -> mount latest items
VOLUMES="${PROOT_TARBALL}:/opt/build/packages/${PROOT_VERSION}.tar.gz;${CARE_TARBALL}:/opt/build/packages/${CARE_VERSION}.tar.gz"

### FUNCTIONS

mount_volumes() {

if [[ -n ${VOLUMES} ]]; then
echo -n "-v ${VOLUMES}" | sed -e 's/;/ -v /g'
fi

}

### MAIN

mkdir -p "${TARGET_DIR}"
eval docker run \
--user="${USER_ID}:${GROUP_ID}" \
-it \
--rm=true \
-v "${TARGET_DIR}:/opt/build/target" "$(mount_volumes)" \
-w "${BUILD_DIR}" \
-e "PWD=${BUILD_DIR}" \
"${DOCKER_IMAGE}" \
"$@"

Binary file removed packages/care-v2.2.1.tar.gz
Binary file not shown.
Binary file removed packages/glibc-2.16.0.tar.gz
Binary file not shown.
Binary file not shown.
Binary file removed packages/proot-v5.1.0.tar.gz
Binary file not shown.
Binary file added src/care-v2.2.2.tar.gz
Binary file not shown.
Binary file added src/proot-v5.1.1.tar.gz
Binary file not shown.
9 changes: 9 additions & 0 deletions versions.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
proot-version = proot-latest
care-version = care-latest

prefix = $(PWD)/prefix
$(prefix):
mkdir $@

packages = ./packages