Skip to content

Commit

Permalink
Merge pull request #1 from NoMore201/feature/qemu
Browse files Browse the repository at this point in the history
Feature/qemu
  • Loading branch information
NoMore201 authored Dec 10, 2024
2 parents 5fc47dd + 613d6ff commit 93cacb6
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 12 deletions.
54 changes: 48 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
- main

jobs:
build:
name: Toolchain build
build-gcc:
name: GCC toolchain build
runs-on: ubuntu-22.04

steps:
Expand All @@ -21,7 +21,7 @@ jobs:

- name: Install dependencies
run: |
sudo ./scripts/install-deps
sudo ./scripts/install-gcc-deps
- name: Build Linux
run: |
Expand All @@ -31,7 +31,7 @@ jobs:
export CXXFLAGS="-O2"
export LDFLAGS="-static -s"
../configure --prefix /opt/gcc/linux
make -j$(nproc)
make -j$(nproc) stamps/build-gcc-stage2
- name: Build Win32
run: |
Expand All @@ -51,13 +51,55 @@ jobs:
- name: Package
run: |
cd /opt/gcc/linux
zip -r9 ../linux.zip .
zip -r9 ../gcc-linux.zip .
cd /opt/gcc/win32
zip -r9 ../win32.zip .
zip -r9 ../gcc-win32.zip .
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: tricore-gcc-artifacts
path: /opt/gcc/*.zip

build-qemu:
name: QEMU build
runs-on: ubuntu-24.04

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sudo ./scripts/install-qemu-deps
- name: Build Linux
run: |
mkdir build-linux
cd build-linux
../configure --prefix /opt/gcc/linux
make -j$(nproc) stamps/build-qemu
- name: Build Win32
run: |
mkdir build-win32
cd build-win32
../configure --prefix /opt/gcc/win32 --with-host=x86_64-w64-mingw32
make -j$(nproc) stamps/build-qemu
- name: Package
run: |
cd /opt/gcc/linux
zip -r9 ../qemu-linux.zip bin/qemu-system-tricore share
cd /opt/gcc/win32
zip -r9 ../qemu-win32.zip bin/qemu-system-tricore.exe share
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: tricore-qemu-artifacts
path: /opt/gcc/*.zip
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# GNU autoconf/automake artifacts
autom4te.cache
configure~
BUILD

# IDE config folders
.vscode
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
path = tricore-newlib-cygwin
url = https://github.com/EEESlab/tricore-newlib-cygwin.git
branch = master
[submodule "qemu"]
path = qemu
url = https://gitlab.com/qemu-project/qemu.git
30 changes: 29 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ INSTALL_DIR := @prefix@
BINUTILS_SRCDIR := @with_binutils_src@
NEWLIB_SRCDIR := @with_newlib_src@
GCC_SRCDIR := @with_gcc_src@
QEMU_SRCDIR := $(srcdir)/qemu

CONFIGURE_HOST = @configure_host@
QEMU_CONFIGURE_HOST = @qemu_configure_host@

all: stamps/build-gcc-stage2
ifeq ($(QEMU_CONFIGURE_HOST),--cross-prefix=x86_64-w64-mingw32-)
QEMU_ENV_VARS := PKG_CONFIG_PATH="$(INSTALL_DIR)/lib/pkgconfig" PKG_CONFIG_LIBDIR="$(INSTALL_DIR)/lib/pkgconfig"
else
QEMU_ENV_VARS :=
endif

all: stamps/build-qemu stamps/build-gcc-stage2

clean-binutils-tc:
rm -rf build-binutils-tc stamps/build-binutils-tc
Expand All @@ -28,6 +36,9 @@ clean-gcc-stage2:
clean-gcc-stage2-only:
rm -rf build-gcc-stage2-only stamps/build-gcc-stage2-only

clean-qemu:
rm -rf build-qemu stamps/build-qemu

clean:
rm -rf build-* stamps

Expand Down Expand Up @@ -224,3 +235,20 @@ stamps/build-gcc-stage2-only: $(GCC_SRCDIR) stamps/install-deps
$(MAKE) -C $(notdir $@) all
$(MAKE) -C $(notdir $@) install
mkdir -p $(dir $@) && touch $@

stamps/build-qemu: $(QEMU_SRCDIR)
rm -rf $@ $(notdir $@)
mkdir $(notdir $@)
if test "$(QEMU_CONFIGURE_HOST)" = "--cross-prefix=x86_64-w64-mingw32-"; then cd $(notdir $@) && $(srcdir)/scripts/build-mingw32-deps $(INSTALL_DIR); fi
cd $(notdir $@) && $(QEMU_ENV_VARS) $</configure \
--prefix=$(INSTALL_DIR) \
$(QEMU_CONFIGURE_HOST) \
--target-list=tricore-softmmu \
--bindir=bin \
--datadir=share/qemu \
--localedir=share/locale \
--static \
--without-default-features
$(MAKE) -C $(notdir $@) all
$(MAKE) -C $(notdir $@) install
mkdir -p $(dir $@) && touch $@
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@

# Tricore GCC
# Tricore GNU compiler toolchain

![ci build status](https://github.com/NoMore201/tricore-gcc-toolchain/actions/workflows/build.yml/badge.svg)

C/C++ toolchain based on GCC 11.3 for AURIX Tricore architecture. It supports
TriCore architectures 1.3, 1.3.1, 1.6, 1.6.1, 1.6.2 and 1.8.

Prebuilt packages are available in the
[release section](https://github.com/NoMore201/tricore-gcc-toolchain/releases).

> Note: Some feature in this fork are still waiting PR approval from upstream
> repository [EEESlab/tricore-gcc-toolchain-11.3.0](https://github.com/EEESlab/tricore-gcc-toolchain-11.3.0)
## Building (cross-compile)

Expand Down
9 changes: 9 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ LIBOBJS
with_gcc_src
with_newlib_src
with_binutils_src
qemu_configure_host
configure_host
NEED_GCC_EXTERNAL_LIBRARIES
BASH
Expand Down Expand Up @@ -3706,6 +3707,14 @@ else $as_nop
configure_host=""
fi
if test "x$with_host" != xdefault
then :
qemu_configure_host=--cross-prefix=$with_host-
else $as_nop
qemu_configure_host=""
fi
# Check whether --with-binutils-src was given.
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ AC_ARG_WITH(host,
AS_IF([test "x$with_host" != xdefault],
[AC_SUBST(configure_host,--host=$with_host)],
[AC_SUBST(configure_host,"")])
AS_IF([test "x$with_host" != xdefault],
[AC_SUBST(qemu_configure_host,--cross-prefix=$with_host-)],
[AC_SUBST(qemu_configure_host,"")])

AC_ARG_WITH(binutils-src,
[AS_HELP_STRING([--with-binutils-src],[Set binutils source path, use builtin source by default])],
Expand Down
1 change: 1 addition & 0 deletions qemu
Submodule qemu added at 7872e5
58 changes: 58 additions & 0 deletions scripts/build-mingw32-deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

###############################################################
#
# This script builds QEMU cross compile dependencies and
# installs them into the provided prefix. Currently only
# Glib2 is required.
#
# Usage: ./build-mingw-deps /opt/install-prefix
#
###############################################################

set -euo pipefail

GLIB_VERSION=2.83.0
GLIB_TARBALL="glib-$GLIB_VERSION.tar.xz"
GLIB_SRC_URL="https://download.gnome.org/sources/glib/2.83/glib-$GLIB_VERSION.tar.xz"

ARCH=x86_64-w64-mingw32

if [ $# -ne 1 ]; then
echo "Script require install prefix path as parameters"
exit 1
fi

INSTALL_PREFIX=$1

if [ ! -f $GLIB_TARBALL ]; then
curl -L --insecure --remote-name-all $GLIB_SRC_URL
fi
tar xJf $GLIB_TARBALL
cd "glib-$GLIB_VERSION"

cat > $ARCH.txt <<HereDoc
[binaries]
c = '$ARCH-gcc'
cpp = '$ARCH-g++'
ar = '$ARCH-ar'
windres = '$ARCH-windres'
strip = '$ARCH-strip'
[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
HereDoc

meson setup --cross-file $ARCH.txt build-mingw --prefix="$INSTALL_PREFIX" --buildtype=release \
--default-library=static \
-Dintrospection=disabled \
-Ddtrace=disabled \
-Dsystemtap=disabled \
-Dsysprof=disabled \
-Dglib_debug=disabled
cd build-mingw
meson compile
meson install
7 changes: 4 additions & 3 deletions scripts/install-deps → scripts/install-gcc-deps
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ set -e
if [ ! -f /etc/lsb_release ] && [ ! -f /etc/debian_version ]
then
echo "Script is meant to install packages on Debian/Ubuntu based distributions"
echo "Pleas install dependencies manually on other distributions"
echo "Please install dependencies manually on other distributions"
exit 1
fi

apt-get update
apt-get -y install build-essential texinfo \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
build-essential texinfo \
flex bison libmpfr-dev libgmp-dev libmpc-dev zip libdebuginfod-dev \
gcc-mingw-w64 g++-mingw-w64
gcc-mingw-w64 g++-mingw-w64 mingw-w64-tools
23 changes: 23 additions & 0 deletions scripts/install-qemu-deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

set -e

if [ ! -f /etc/lsb_release ] && [ ! -f /etc/debian_version ]
then
echo "Script is meant to install packages on Debian/Ubuntu based distributions"
echo "Please install dependencies manually on other distributions"
exit 1
fi

apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y install \
build-essential \
gcc-mingw-w64 g++-mingw-w64 mingw-w64-tools \
git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build \
python3-pip curl

# Make sure MingGW compiler uses Posix threads
update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix

pip3 install --break-system-packages meson==1.4.0

0 comments on commit 93cacb6

Please sign in to comment.