Git Product home page Git Product logo

gcc-build-tools's Introduction

GCC crosstoolchain build script

This is a simple script to build gcc based (cross) toolchains for various platforms. It is much like crosstool-ng, just simpler.

The buildscript is able to build toolchains and cross-toolchains for Linux hosts and targets Linux, Windows (mingw) as well as baremetal targets.

Specifically these target architectures are currently supported:

- arm 
- arm64 
- avr8
- cortex-m0 
- cortex-m3 
- cortex-m4 
- riscv32 
- riscv32-baremetal 
- riscv64 
- riscv64-baremetal
- riscv64-uclibc 
- x86 
- x86_64 
- x86_64_mingw 
- x86_mingw 

Supported GCC versions:

  • GCC-latest
  • GCC-13
  • GCC-12
  • GCC-11
  • GCC-10

Please be aware that some target/version combinations might not work.

Prebuilt toolchains can be downloaded here (note: links are only valid 90 days after the last successful github ci runner)

https://nightly.link/franzflasch/gcc-build-tools/workflows/arm/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/arm64/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/avr8/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/cortex-m0/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/cortex-m3/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/cortex-m4/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/riscv32/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/riscv32-baremetal/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/riscv64/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/riscv64-baremetal/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/riscv64-uclibc/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/x86/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/x86_64/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/x86_64_mingw/main/toolchain_built_from_tar
https://nightly.link/franzflasch/gcc-build-tools/workflows/x86_mingw/main/toolchain_built_from_tar

NOTE: Make sure to extract the prebuilt toolchains to /opt/local/ otherwise there might be issues for certain builds.

Prerequisites

To build a toolchain, you need to do the following:

A Linux distribution (the script has been tested on Ubuntu 22.04)
Core developer packages

  • For Ubuntu 22.04:
sudo apt install -y wget build-essential make gawk git subversion texinfo autoconf autopoint pkg-config gettext txt2man liblzma-dev libssl-dev libz-dev flex bison libexpat1-dev rsync file

In case you want to build a baremetal target you also need to install:

  • For picolibc:
sudo apt install -y python3-pip
sudo pip3 install meson ninja

Install directory

IMPORTANT: Create the folder /opt/local/ and ensure that you have write permissions otherwise the script wont work!!

Using the script

Once you have set up your environment, you can use the script like this:

  1. Clone the repository
git clone https://github.com/franzflasch/gcc-build-tools
  1. Add the script to your path
cd gcc-build-tools
export PATH=$PWD:$PATH
  1. Create a work directory for your build
mkdir ~/gcc-builds
cd ~/gcc-builds
  1. Use it!
build-gcc -h

The printout will show you how to run the script.

Example commands:

# build a riscv64-uclibc toolchain, stripping binaries, verbose mode
build-gcc -a riscv64-uclibc -v 13 -s -V

# Build a toolchain for x86_64
./build-gcc -a x86_64 -v 13

# Build a toolchain for arm64
./build-gcc -a arm64 -v 13

# Build a toolchain for arm
./build-gcc -a arm -v 13

# Build a toolchain for riscv linux
./build-gcc -a riscv64 -v 13

# Build a toolchain for avr microcontrollers
./build-gcc -a avr8 -v 13 -t

# Build a toolchain for arm cortex m3/m4 microcontrollers
./build-gcc -a cortex-m3 -v 13 -t

# Build a toolchain for riscv baremetal (sifive hifive1)
./build-gcc -a riscv32-baremetal -v 13

After compilation

The end result will be placed into /opt/local/ e.g. /opt/local/cross-tool-riscv64-uclibc-gcc13/.

To use the toolchain just add /opt/local/cross-tool-riscv64-uclibc-gcc13/bin to your $PATH and thats it.

Notes on using the toolchain

Building a fully static linked executable:

<target-triple>-gcc -o hello -static hello.c

With OpenMP:

<target-triple>-gcc -o omp_helloc -static -fopenmp omp_hello.c

For shared libraries ensure that you are building using the internal toolchain libs instead of ones already installed on the host linux - here for x86_64 openmp example:

x86_64-linux-gnu-gcc -o omp_helloc -Wl,--rpath=toolchain/lib64 -Wl,--rpath=toolchain/x86_64-linux-gnu/lib/ -Wl,--dynamic-linker=toolchain/x86_64-linux-gnu/lib/ld-linux-x86-64.so.2 -fopenmp omp_hello.c

For crosscompile targets it is probably necessary to install those libs into the target rootfs.

For developers

Adding a new target should be rather easy:

  • Add a new target file in configs/targets. Look at the existing targets to get an idea how to add your own.
  • There are default configs defined in configs/targets_config.sh that should be used as a base if possible.
  • SRC URLs for the various open source packages (gcc, binutils etc.) are handled in configs/common.sh.
  • SRC VERSIONs are handled either in configs/git_source_config.sh and configs/tar_source_config.sh.
    • git_source_config.sh defines SRC URLs for git repositories.
    • tar_source_config.sh defines SRC URLs for tarballs.

Pull requests/issues

Feel free to open an issue!

Pull requests are more than welcome as well!

gcc-build-tools's People

Contributors

ac130kz avatar ahmedradaideh avatar akhilnarang avatar blackhat01 avatar djb77 avatar franzflasch avatar frap129 avatar geyera avatar khusika avatar krascgq avatar msfjarvis avatar nathanchance avatar usbhost avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.