├── README.md ├── armv7l-toolchain.cmake └── bootstrap.sh /README.md: -------------------------------------------------------------------------------- 1 | # WebKit2GTK+ cross-compilation environment for ARM 2 | 3 | Resources to allow cross compiling WebKit2GTK+ for ARM. 4 | 5 | ## Requirements 6 | 7 | * A host machine with lots of CPUs and RAM (16GB recommended) 8 | * RootFS for the target device 9 | - You need to adjust the path in the CMake Toolchain file accordingly (e.g /schroot/eos-master-armhf) 10 | * Packages to create and use the chroot: debootstrap, chroot and schroot 11 | - Debian/Ubuntu: `sudo apt-get install debootstrap chroot schroot` 12 | - Fedora: `sudo dnf install debootstrap chroot schroot` 13 | 14 | ## Instructions 15 | 16 | (1) First of all, create the chroot: 17 | ``` 18 | $ sudo /usr/sbin/debootstrap \ 19 | --arch amd64 \ 20 | --components=main,universe \ 21 | xenial /path/to/chroot http://uk.archive.ubuntu.com/ubuntu 22 | ``` 23 | 24 | (2) Create a configuration file for schroot, for instance under `/etc/schroot/chroot.d/xenial-amd64`, with the following contents (replacing `` and ``): 25 | ``` 26 | [xenial-amd64] 27 | description=Ubuntu 64-bit chroot based on Xenial 28 | type=directory 29 | directory=/path/to/chroot 30 | users= 31 | groups= 32 | root-users= 33 | setup.copyfiles=default/copyfiles 34 | setup.fstab=default/xenial-amd64.fstab 35 | ``` 36 | 37 | (3) Now you need to create that file under `/etc/schroot/default` so that you can tell schroot to bind mount the path to the RootFS when entering the chroot. To do that, create a copy of `/etc/schroot/default/fstab` (`sudo cp /etc/schroot/default/fstab/xenial-amd64.fstab`) and then add this line to its contents: 38 | ``` 39 | # To crosscompile WebKitGTK 40 | /schroot/eos-master-armhf /schroot/eos-master-armhf none rw,bind 0 0 41 | ``` 42 | ...or whatever the path to the RootFS is. Just remember that the second column specifies the mount point **inside** the chroot, so it has to be on sync with the path referenced from the CMake Toolchain file. 43 | 44 | (4) You should be able to **enter the chroot** with your regular user session: 45 | ``` 46 | $ schroot -c xenial-amd64 47 | ``` 48 | 49 | (5) Finally, from inside the chroot, you can **run the `bootstrap.sh` script as the root user** (or using sudo) provided with this repository to provision it with the tools you need to build Webkit, and then **copy the `armv7l-toolchain.cmake` file to some local path**, and you're good to go. 50 | 51 | (6) Now create a BUILD directory in `/path/to/your/WebKit` and configure the build (you might want to pass extra/different parameters, though) from inside the chroot: 52 | ``` 53 | $ mkdir /path/to/your/WebKit/BUILD && cd /path/to/your/WebKit/BUILD 54 | $ cmake -DCMAKE_TOOLCHAIN_FILE=/home/mario/work/webkit2gtk-ARM/armv7l-toolchain.cmake \ 55 | -DPORT=GTK \ 56 | -DCMAKE_BUILD_TYPE=Release \ 57 | -DCMAKE_INSTALL_SYSCONFDIR=/etc \ 58 | -DCMAKE_INSTALL_LOCALSTATEDIR=/var \ 59 | -DCMAKE_INSTALL_PREFIX=/usr \ 60 | -DCMAKE_INSTALL_LIBDIR=lib/arm-linux-gnueabihf \ 61 | -DCMAKE_INSTALL_LIBEXECDIR=lib/arm-linux-gnueabihf \ 62 | -DENABLE_PLUGIN_PROCESS_GTK2=OFF \ 63 | -DENABLE_GEOLOCATION=OFF \ 64 | -DENABLE_GLES2=ON \ 65 | -DUSE_LD_GOLD=OFF \ 66 | /path/to/your/WebKit 67 | ``` 68 | 69 | (7) Finally, and still from inside the chroot, build the thing: 70 | ``` 71 | $ make VERBOSE=1 -j12 # Or anything else, this is just what I use 72 | ``` 73 | 74 | And that should be all. Now you should be able to copy the relevant files over to the target machine and use your cross-compiled WebKit build. 75 | 76 | Enjoy! 77 | -------------------------------------------------------------------------------- /armv7l-toolchain.cmake: -------------------------------------------------------------------------------- 1 | # CMake Toolchain file to cross compile WebKit2GTK+ for ARM (tested with 2.14.0) 2 | # 3 | # Environment: 4 | # * Ubuntu Xenial chroot (amd64) 5 | # * Root FS for the target device (e.g. /schroot/eos-master-armhf) 6 | # * Usual WebKit build deps installed in the Root FS 7 | # * Build dependencies in the host (xenial chroot): 8 | # gawk cmake debhelper gperf bison flex ruby 9 | # * Cross compiler packages in the host (xenial chroot): 10 | # cpp-4.9-arm-linux-gnueabihf g++-4.9-arm-linux-gnueabihf \ 11 | # gcc-4.9-arm-linux-gnueabihf gcc-4.9-arm-linux-gnueabihf-base \ 12 | # libasan1-armhf-cross libgcc-4.9-dev-armhf-cross \ 13 | # libstdc++-4.9-dev-armhf-cross 14 | # 15 | # How to build: 16 | # 1. Write this file to disk (e.g. armv7l-toolchain.cmake) 17 | # 2. From WebKit top source directory, create a BUILD dir: 18 | # $ mkdir BUILD && cd BUILD 19 | # 3. Configure the build, passing any extra parameter you need: 20 | # $ cmake -DCMAKE_TOOLCHAIN_FILE=$(pwd)/../armv7l-toolchain.cmake \ 21 | # -DPORT=GTK \ 22 | # -DCMAKE_BUILD_TYPE=Release \ 23 | # -DCMAKE_INSTALL_SYSCONFDIR=/etc \ 24 | # -DCMAKE_INSTALL_LOCALSTATEDIR=/var \ 25 | # -DCMAKE_INSTALL_PREFIX=/usr \ 26 | # -DCMAKE_INSTALL_LIBDIR=lib/arm-linux-gnueabihf \ 27 | # -DCMAKE_INSTALL_LIBEXECDIR=lib/arm-linux-gnueabihf \ 28 | # -DENABLE_PLUGIN_PROCESS_GTK2=OFF \ 29 | # -DENABLE_GEOLOCATION=OFF \ 30 | # -DENABLE_GLES2=ON \ 31 | # -DUSE_LD_GOLD=OFF \ 32 | # .. 33 | # 4. Build the thing: 34 | # $ make VERBOSE=1 -j12 # Or anything else, this is just what I use 35 | 36 | # Path to the target RootFS (adjust as needed) 37 | SET(ROOTFS "/schroot/eos-master-armhf") 38 | 39 | SET(MULTIARCH "arm-linux-gnueabihf") 40 | 41 | # Setting the system name to "Linux" sets CMAKE_CROSSCOMPILING to true 42 | SET(CMAKE_SYSTEM_NAME "Linux") 43 | SET(CMAKE_SYSTEM_PROCESSOR "armv7l") 44 | 45 | # Specify the cross compilers 46 | SET(CMAKE_C_COMPILER /usr/bin/${MULTIARCH}-gcc-4.9) 47 | SET(CMAKE_CXX_COMPILER /usr/bin/${MULTIARCH}-g++-4.9) 48 | 49 | # This is very important, so that we find the right headers and libraries 50 | # without explicitly listing the default include directories (e.g. JSC) 51 | SET(CMAKE_SYSROOT "${ROOTFS}") 52 | 53 | # Ensure that FIND_PACKAGE() functions and friends look in the rootfs 54 | # only for libraries and header files, but not for programs (e.g perl) 55 | SET(CMAKE_FIND_ROOT_PATH "${ROOTFS}") 56 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 57 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 58 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 59 | 60 | # Add include directories from the rootfs matching the current toolchain 61 | INCLUDE_DIRECTORIES(SYSTEM 62 | "${ROOTFS}/usr/include" 63 | "${ROOTFS}/usr/include/c++/4.9" 64 | "${ROOTFS}/usr/include/arm-linux-gnueabihf/c++/4.9" 65 | ) 66 | 67 | # CMake does not pick CPPFLAGS, so we add it manually into CFLAGS and CXXFLAGS 68 | # Note: I have no idea why the first include directory from the previous list 69 | # gets ignored when building some components, so I pass it here as well. 70 | SET(CPPFLAGS "-DG_DISABLE_CAST_CHECKS") 71 | SET(ENV{CFLAGS} "${CPPFLAGS} -fstack-protector-strong -Wall -Wformat -Werror=format-security -I${ROOTFS}/usr/include -isystem ${ROOTFS}/usr/include") 72 | SET(ENV{CXXFLAGS} "${CPPFLAGS} -fstack-protector-strong -Wall -Wformat -Werror=format-security -I${ROOTFS}/usr/include -isystem ${ROOTFS}/usr/include") 73 | 74 | # CMake does not pick LDFLAGS, so we add it manually too 75 | SET(ENV{LDFLAGS} "-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -Wl,-rpath-link,${ROOTFS}/lib/arm-linux-gnueabihf") 76 | 77 | # This setup is meant for development so make sure we build without optimizations 78 | # and with some debug symbols (-g2 is too much in our ARM platform). 79 | SET(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Flags used by the compiler during release builds." FORCE) 80 | SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Flags used by the compiler during release builds." FORCE) 81 | SET(CMAKE_C_FLAGS_DEBUG "-g1 -O0" CACHE STRING "Flags used by the compiler during debug builds." FORCE) 82 | SET(CMAKE_CXX_FLAGS_DEBUG "-g1 -O0" CACHE STRING "Flags used by the compiler during debug builds." FORCE) 83 | 84 | # Need to export this variables for pkg-config to pick them up, so that it 85 | # sets the right search path and prefixes the result paths with the rootfs. 86 | SET(ENV{PKG_CONFIG_PATH} "${ROOTFS}/usr/share/pkgconfig") 87 | SET(ENV{PKG_CONFIG_LIBDIR} "${ROOTFS}/usr/lib/${MULTIARCH}/pkgconfig:${ROOTFS}/usr/lib/pkgconfig") 88 | SET(ENV{PKG_CONFIG_SYSROOT_DIR} "${ROOTFS}") 89 | 90 | # These variables make sure that pkg-config does never discard standard 91 | # include and library paths from the compile and linking flags. 92 | SET(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} 1) 93 | SET(ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS} 1) 94 | SET(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE) 95 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # 3 | # To be executed inside the chroot, to provision the environment 4 | 5 | export DEBIAN_FRONTEND=noninteractive 6 | apt-get update 7 | 8 | # Ubuntu Xenial does not get the _apt user installed when creating 9 | # a chroot via debootstrap, so create it now to prevent failures. 10 | adduser --force-badname --system --home /nonexistent \ 11 | --no-create-home --quiet _apt || true 12 | 13 | # General build dependencies: 14 | apt-get install -y --assume-yes \ 15 | bison \ 16 | cmake \ 17 | debhelper \ 18 | flex \ 19 | gawk \ 20 | gcc-4.9-base \ 21 | gperf \ 22 | libasan1 \ 23 | libgcc-4.9-dev \ 24 | libstdc++-4.9-dev \ 25 | pkg-config \ 26 | ruby 27 | 28 | # Cross compiler: 29 | apt-get install -y --assume-yes \ 30 | cpp-4.9-arm-linux-gnueabihf \ 31 | g++-4.9-arm-linux-gnueabihf \ 32 | gcc-4.9-arm-linux-gnueabihf \ 33 | gcc-4.9-arm-linux-gnueabihf-base \ 34 | libasan1-armhf-cross \ 35 | libgcc-4.9-dev-armhf-cross \ 36 | libstdc++-4.9-dev-armhf-cross 37 | --------------------------------------------------------------------------------