Compare commits

...

No commits in common. "1.3" and "master" have entirely different histories.
1.3 ... master

20 changed files with 1366 additions and 590 deletions

20
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,20 @@
name: Builds
run-name: ${{ github.actor }} runs Gitea Actions
on: [push]
jobs:
XTChain:
runs-on: oscw
container:
image: codingworkshop/oscw-runner:latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Build XTChain
run: CORES=10 ./build-linux.sh
- name: Publish binaries
if: startsWith(github.ref, 'refs/tags/')
env:
OSCW_GITHUB_USERNAME: ${{ secrets.OSCW_GITHUB_USERNAME }}
OSCW_GITHUB_PASSWORD: ${{ secrets.OSCW_GITHUB_PASSWORD }}
run: github_publish $OSCW_GITHUB_USERNAME $OSCW_GITHUB_PASSWORD $(ls xtchain-*-linux.tar.zst)

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
binaries/*
sources/*
xtchain-*.zst

View File

@ -1,22 +1,52 @@
<p align=center>
<a href="https://git.codingworkshop.eu.org/xt-sys/xtchain">
<img alt="GIT Repository" src="https://img.shields.io/badge/Source-GIT-purple">
</a>
<a href="https://git.codingworkshop.eu.org/xt-sys/xtchain/actions">
<img alt="Build Status" src="https://codingworkshop.eu.org/actions.php?project=xt-sys/xtchain">
</a>
<a href="https://github.com/xt-sys/xtchain/releases">
<img alt="Releases" src="https://img.shields.io/github/v/release/xt-sys/xtchain?label=Release&amp;color=blueviolet">
</a>
<a href="https://git.codingworkshop.eu.org/xt-sys/xtchain/src/branch/master/COPYING.md">
<img alt="License" src="https://img.shields.io/badge/License-GPLv3-blue.svg">
</a>
<a href="https://github.com/sponsors/xt-sys/">
<img alt="Sponsors" src="https://img.shields.io/badge/Sponsor-%E2%9D%A4-red?logo=GitHub">
</a>
<a href="https://discord.com/invite/zBzJ5qMGX7">
<img alt="Discord" src="https://img.shields.io/badge/Chat-Join%20Discord-success">
</a>
</p>
---
## XT Toolchain
This is a GNU-based mingw-w64 toolchain. It currently supports C and C++, and provides a variety of
tools including IDL, message and resource compilers. The XT Toolchain is also the official build
environment for compiling XT software, including the FerretOS. Currently, it is targeted at Linux
host only, however it should be possible to build it in MSYS2 as well.
This is a LLVM/Clang/LLD based mingw-w64 toolchain. It currently supports C and C++, and provides
a variety of tools including IDL, message and resource compilers. The XT Toolchain is also the
official build environment for compiling XT software, including the XT OS. Currently, it is
targeted at Linux host only, however it should be possible to build it in MSYS2 as well.
Benefits of a LLVM based MinGW toolchain are:
* Single toolchain targeting all architectures (i686, x86_64, armv7 and aarch64),
* Support for generating debug info in PDB format,
* Support for targeting ARM/AARCH64 architectures and ability to produce Windows ARM binaries.
This software includes:
* Binutils
* CMake
* GCC
* GNU Assembler
* LLVM
* Make
* Mingw-w64
* Ninja
* Wine
This software is based on [LLVM MinGW Toolchain](https://github.com/mstorsjo/llvm-mingw).
## Licensing
The XTchain project includes the scripts for building and assembling a toolchain as well as
environmental shell. These are licensed under the GPLv3 license. It covers only mentioned
components that are provided by XTchain directly. For more information on that, refer to the
COPYING.md file. The final pre-built toolchain is covered by the licenses of the individual,
The XTchain project includes the scripts for building and assembling a toolchain as well as wrappers
for LLVM tools and environmental shell. These are licensed under the GPLv3 license. It covers only
mentioned components that are provided by XTchain directly. For more information on that, refer to
the COPYING.md file. The final pre-built toolchain is covered by the licenses of the individual,
external projects. The full list of software incorporated into this toolchain is available in the
README.md file.

View File

@ -13,49 +13,40 @@ SRCDIR="$(pwd)/sources"
WRKDIR="$(pwd)"
# Architecture Settings
ARCHS="i686 x86_64"
ARCHS="aarch64 armv7 i686 x86_64"
GENERIC="generic-w64-mingw32"
# Compiler Flags
CFLAGS="-march=x86-64 -mtune=generic -O2 -s -pipe"
CXXFLAGS="${CFLAGS}"
# Binutils Settings
BINUTILSDIR="${SRCDIR}/binutils"
BINUTILSTAG="binutils-2_35"
BINUTILSVCS="git://sourceware.org/git/binutils-gdb.git"
# CMake Settings
CMAKEDIR="${SRCDIR}/cmake"
CMAKETAG="v3.18.1"
CMAKETAG="v3.31.3"
CMAKEVCS="https://gitlab.kitware.com/cmake/cmake.git"
# GCC Settings
GCCDIR="${SRCDIR}/gcc"
GCCTAG="releases/gcc-9.3.0"
GCCVCS="git://gcc.gnu.org/git/gcc.git"
# LLVM Settings
LLVMDIR="${SRCDIR}/llvm"
LLVMTAG="llvmorg-19.1.6"
LLVMVCS="https://github.com/llvm/llvm-project.git"
# Make Settings
MAKEDIR="${SRCDIR}/make"
MAKETAG="4.3"
MAKETAG="4.4.1"
MAKEVCS="git://git.savannah.gnu.org/make"
# Mingw-w64 Settings
MINGWDIR="${SRCDIR}/mingw-w64"
MINGWLIB="ucrt"
MINGWTAG="v7.0.0"
MINGWTAG="master"
MINGWNTV="0x601"
MINGWVCS="https://github.com/mirror/mingw-w64.git"
# Ninja Settings
NINJADIR="${SRCDIR}/ninja"
NINJATAG="v1.10.0"
NINJATAG="v1.12.1"
NINJAVCS="https://github.com/ninja-build/ninja.git"
# Wine Settings
WINEDIR="${SRCDIR}/wine"
WINETAG="wine-5.15"
WINEVCS="git://source.winehq.org/git/wine.git"
WINETAG="wine-9.8"
WINEVCS="https://github.com/wine-mirror/wine.git"
# This function applies a patches to the 3rd party project
@ -83,44 +74,6 @@ apply_patches()
fi
}
# This function compiles and installs BINUTILS
binutils_build()
{
for ARCH in ${ARCHS}; do
echo ">>> Building BINUTILS for ${ARCH} ..."
[ -z ${CLEAN} ] || rm -rf ${BINUTILSDIR}/build-${ARCH}
mkdir -p ${BINUTILSDIR}/build-${ARCH}
cd ${BINUTILSDIR}/build-${ARCH}
../configure \
--target=${ARCH}-w64-mingw32 \
--prefix=${BINDIR} \
--with-sysroot=${BINDIR} \
--with-zlib=yes \
--disable-multilib \
--disable-nls \
--disable-werror \
--enable-gold \
--enable-lto \
--enable-plugins
make -j${CORES}
make install
done
cd ${WRKDIR}
}
# This function downloads BINUTILS from VCS
binutils_fetch()
{
if [ ! -d ${BINUTILSDIR} ]; then
echo ">>> Downloading BINUTILS ..."
git clone ${BINUTILSVCS} ${BINUTILSDIR}
cd ${BINUTILSDIR}
git checkout tags/${BINUTILSTAG}
apply_patches ${BINUTILSDIR##*/} ${BINUTILSTAG##*-}
cd ${WRKDIR}
fi
}
# This function compiles and installs CMAKE
cmake_build()
{
@ -142,68 +95,145 @@ cmake_fetch()
{
if [ ! -d ${CMAKEDIR} ]; then
echo ">>> Downloading CMAKE ..."
git clone ${CMAKEVCS} ${CMAKEDIR}
git clone --depth 1 --branch ${CMAKETAG} ${CMAKEVCS} ${CMAKEDIR}
cd ${CMAKEDIR}
git checkout tags/${CMAKETAG}
apply_patches ${CMAKEDIR##*/} ${CMAKETAG}
cd ${WRKDIR}
fi
}
# This function compiles and install GCC (phase 1)
gcc_build_phase1()
# This function compiles and install LLVM
llvm_build()
{
echo ">>> Building LLVM ..."
[ -z ${CLEAN} ] || rm -rf ${LLVMDIR}/llvm/build
LLVM_ARCHS=()
for ARCH in ${ARCHS}; do
echo ">>> Building GCC (phase1) for ${ARCH} ..."
[ -z ${CLEAN} ] || rm -rf ${GCCDIR}/build-${ARCH}
mkdir -p ${GCCDIR}/build-${ARCH}
cd ${GCCDIR}/build-${ARCH}
../configure \
--target=${ARCH}-w64-mingw32 \
--prefix=${BINDIR} \
--with-sysroot=${BINDIR} \
--with-pkgversion="FerretOS Build Environment" \
--without-zstd \
--disable-libstdcxx-verbose \
--disable-multilib \
--disable-nls \
--disable-shared \
--disable-werror \
--disable-win32-registry \
--enable-fully-dynamic-string \
--enable-languages=c,c++ \
--enable-lto \
--enable-sjlj-exceptions \
--enable-version-specific-runtime-libs
make -j${CORES} all-gcc
make install-gcc
make install-lto-plugin
case ${ARCH} in
"aarch64")
LLVM_ARCHS+=( "AArch64" )
;;
"armv7")
LLVM_ARCHS+=( "ARM" )
;;
"i686"|"x86_64")
LLVM_ARCHS+=( "X86" )
;;
esac
done
LLVM_ARCHS=( $(for ARCH in ${LLVM_ARCHS[@]}; do echo ${ARCH}; done | sort -u) )
cd ${LLVMDIR}/llvm/tools
for UTIL in clang lld; do
if [ ! -e ${UTIL} ]; then
ln -sf ../../${UTIL} .
fi
done
mkdir -p ${LLVMDIR}/llvm/build
cd ${LLVMDIR}/llvm/build
cmake -G Ninja \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_INSTALL_PREFIX=${BINDIR} \
-DLLDB_INCLUDE_TESTS=FALSE \
-DLLVM_ENABLE_ASSERTIONS=FALSE \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb" \
-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \
-DLLVM_LINK_LLVM_DYLIB=ON \
-DLLVM_TARGETS_TO_BUILD="$(echo ${LLVM_ARCHS[@]} | tr ' ' ';')" \
-DLLVM_TOOLCHAIN_TOOLS="llvm-addr2line;llvm-ar;llvm-as;llvm-cov;llvm-cvtres;llvm-dlltool;llvm-lib;llvm-ml;llvm-nm;llvm-objdump;llvm-objcopy;llvm-pdbutil;llvm-profdata;llvm-ranlib;llvm-rc;llvm-readelf;llvm-readobj;llvm-strings;llvm-strip;llvm-symbolizer;llvm-windres" \
..
ninja install/strip
cd ${WRKDIR}
}
# This function compiles and install LIBCXX & LIBUNWIND
llvm_build_libs()
{
echo ">>> Building LLVM libraries (libcxx) ..."
for ARCH in ${ARCHS}; do
[ -z ${CLEAN} ] || rm -rf ${LLVMDIR}/runtimes/build-${ARCH}
mkdir -p ${LLVMDIR}/runtimes/build-${ARCH}
cd ${LLVMDIR}/runtimes/build-${ARCH}
cmake -G Ninja \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_INSTALL_PREFIX="${BINDIR}/${ARCH}-w64-mingw32" \
-DCMAKE_AR="${BINDIR}/bin/llvm-ar" \
-DCMAKE_C_COMPILER="${BINDIR}/bin/${ARCH}-w64-mingw32-clang" \
-DCMAKE_C_COMPILER_WORKS=1 \
-DCMAKE_C_FLAGS_INIT=-mguard=cf \
-DCMAKE_CXX_COMPILER="${BINDIR}/bin/${ARCH}-w64-mingw32-clang++" \
-DCMAKE_CXX_COMPILER_TARGET=${ARCH}-w64-windows-gnu \
-DCMAKE_CXX_COMPILER_WORKS=1 \
-DCMAKE_CXX_FLAGS_INIT=-mguard=cf \
-DCMAKE_CROSSCOMPILING=TRUE \
-DCMAKE_RANLIB="${BINDIR}/bin/llvm-ranlib" \
-DCMAKE_SYSTEM_NAME="Windows" \
-DLLVM_PATH="${LLVMDIR}/llvm" \
-DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx" \
-DLIBUNWIND_USE_COMPILER_RT=TRUE \
-DLIBUNWIND_ENABLE_SHARED=TRUE \
-DLIBUNWIND_ENABLE_STATIC=TRUE \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXX_ENABLE_SHARED=TRUE \
-DLIBCXX_ENABLE_STATIC=TRUE \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \
-DLIBCXX_CXX_ABI="libcxxabi" \
-DLIBCXX_LIBDIR_SUFFIX="" \
-DLIBCXX_INCLUDE_TESTS=FALSE \
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=FALSE \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DLIBCXXABI_ENABLE_SHARED=OFF \
-DLIBCXXABI_LIBDIR_SUFFIX="" \
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
..
ninja
ninja install
done
cd ${WRKDIR}
}
# This function compiles and install GCC (phase 2)
gcc_build_phase2()
# This function compiles and install LLVM runtime
llvm_build_runtime()
{
echo ">>> Building LLVM compiler runtime ..."
for ARCH in ${ARCHS}; do
echo ">>> Building GCC (phase2) for ${ARCH} ..."
cd ${GCCDIR}/build-${ARCH}
make -j${CORES}
make install
[ -z ${CLEAN} ] || rm -rf ${LLVMDIR}/compiler-rt/build-${ARCH}
mkdir -p ${LLVMDIR}/compiler-rt/build-${ARCH}
cd ${LLVMDIR}/compiler-rt/build-${ARCH}
cmake -G Ninja \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_AR="${BINDIR}/bin/llvm-ar" \
-DCMAKE_C_COMPILER="${BINDIR}/bin/${ARCH}-w64-mingw32-clang" \
-DCMAKE_C_COMPILER_TARGET="${ARCH}-windows-gnu" \
-DCMAKE_C_FLAGS_INIT="-mguard=cf" \
-DCMAKE_CXX_COMPILER="${BINDIR}/bin/${ARCH}-w64-mingw32-clang++" \
-DCMAKE_CXX_FLAGS_INIT="-mguard=cf" \
-DCMAKE_FIND_ROOT_PATH="${BINDIR}/${ARCH}-w64-mingw32" \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
-DCMAKE_INSTALL_PREFIX=$(${BINDIR}/bin/${ARCH}-w64-mingw32-clang --print-resource-dir) \
-DCMAKE_RANLIB="${BINDIR}/bin/llvm-ranlib" \
-DCMAKE_SYSTEM_NAME="Windows" \
-DCOMPILER_RT_BUILD_BUILTINS=TRUE \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=TRUE \
-DCOMPILER_RT_USE_BUILTINS_LIBRARY=TRUE \
-DLLVM_CONFIG_PATH="" \
-DSANITIZER_CXX_ABI="libc++" \
../lib/builtins
ninja
ninja install
done
cd ${WRKDIR}
}
# This function downloads GCC from VCS
gcc_fetch()
# This function downloads LLVM from VCS
llvm_fetch()
{
if [ ! -d ${GCCDIR} ]; then
echo ">>> Downloading GCC ..."
git clone ${GCCVCS} ${GCCDIR}
cd ${GCCDIR}
git checkout tags/${GCCTAG}
apply_patches ${GCCDIR##*/} ${GCCTAG##*-}
./contrib/download_prerequisites
if [ ! -d ${LLVMDIR} ]; then
echo ">>> Downloading LLVM ..."
git clone --depth 1 --branch ${LLVMTAG} ${LLVMVCS} ${LLVMDIR}
cd ${LLVMDIR}
apply_patches ${LLVMDIR##*/} ${LLVMTAG##*-}
cd ${WRKDIR}
fi
}
@ -237,9 +267,8 @@ make_fetch()
{
if [ ! -d ${MAKEDIR} ]; then
echo ">>> Downloading Make ..."
git clone ${MAKEVCS} ${MAKEDIR}
git clone --depth 1 --branch ${MAKETAG} ${MAKEVCS} ${MAKEDIR}
cd ${MAKEDIR}
git checkout tags/${MAKETAG}
apply_patches ${MAKEDIR##*/} ${MAKETAG}
cd ${WRKDIR}
fi
@ -249,15 +278,21 @@ make_fetch()
mingw_build_crt()
{
for ARCH in ${ARCHS}; do
echo ">>> Building Mingw-w64 (CRT) for ${ARCH} ..."
echo ">>> Building Mingw-W64 (CRT) for ${ARCH} ..."
[ -z ${CLEAN} ] || rm -rf ${MINGWDIR}/mingw-w64-crt/build-${ARCH}
mkdir -p ${MINGWDIR}/mingw-w64-crt/build-${ARCH}
cd ${MINGWDIR}/mingw-w64-crt/build-${ARCH}
case ${ARCH} in
i686)
"aarch64")
FLAGS="--disable-lib32 --disable-lib64 --enable-libarm64"
;;
"armv7")
FLAGS="--disable-lib32 --disable-lib64 --enable-libarm32"
;;
"i686")
FLAGS="--enable-lib32 --disable-lib64"
;;
x86_64)
"x86_64")
FLAGS="--disable-lib32 --enable-lib64"
;;
esac
@ -268,6 +303,7 @@ mingw_build_crt()
--prefix=${BINDIR}/${ARCH}-w64-mingw32 \
--with-sysroot=${BINDIR} \
--with-default-msvcrt=${MINGWLIB} \
--enable-cfguard \
${FLAGS}
make -j${CORES}
make install
@ -279,7 +315,7 @@ mingw_build_crt()
# This function compiles and installs MINGW headers
mingw_build_headers()
{
echo ">>> Building Mingw-w64 (headers) ..."
echo ">>> Building Mingw-W64 (headers) ..."
[ -z ${CLEAN} ] || rm -rf ${MINGWDIR}/mingw-w64-headers/build-${GENERIC}
mkdir -p ${MINGWDIR}/mingw-w64-headers/build-${GENERIC}
cd ${MINGWDIR}/mingw-w64-headers/build-${GENERIC}
@ -290,10 +326,6 @@ mingw_build_headers()
--with-default-win32-winnt=${MINGWNTV}
make -j${CORES}
make install
mkdir -p ${BINDIR}/mingw
if [ ! -e ${BINDIR}/mingw/include ]; then
ln -sfn ../${GENERIC}/include ${BINDIR}/mingw/include
fi
for ARCH in ${ARCHS}; do
mkdir -p ${BINDIR}/${ARCH}-w64-mingw32
if [ ! -e ${BINDIR}/${ARCH}-w64-mingw32/include ]; then
@ -306,7 +338,7 @@ mingw_build_headers()
# This function compiles and install MINGW libraries
mingw_build_libs()
{
for LIB in libmangle winstorecompat; do
for LIB in libmangle winpthreads winstorecompat; do
echo ">>> Building Mingw-w64 (libs) for ${ARCH} ..."
for ARCH in ${ARCHS}; do
[ -z ${CLEAN} ] || rm -rf ${MINGWDIR}/mingw-w64-libraries/${LIB}/build-${ARCH}
@ -317,7 +349,9 @@ mingw_build_libs()
../configure \
--host=${ARCH}-w64-mingw32 \
--prefix=${BINDIR}/${ARCH}-w64-mingw32 \
--libdir=${BINDIR}/${ARCH}-w64-mingw32/lib
--libdir=${BINDIR}/${ARCH}-w64-mingw32/lib \
CFLAGS="-O2 -mguard=cf" \
CXXFLAGS="-O2 -mguard=cf"
make -j${CORES}
make install
PATH="${ORIGPATH}"
@ -329,7 +363,7 @@ mingw_build_libs()
# This function compiles and installs MINGW tools
mingw_build_tools()
{
for TOOL in gendef genidl genlib genpeimg widl; do
for TOOL in gendef genidl genpeimg widl; do
for ARCH in ${ARCHS}; do
echo ">>> Building Mingw-w64 (tools) for ${ARCH} ..."
[ -z ${CLEAN} ] || rm -rf ${MINGWDIR}/mingw-w64-tools/${TOOL}/build-${ARCH}
@ -352,10 +386,9 @@ mingw_build_tools()
mingw_fetch()
{
if [ ! -d ${MINGWDIR} ]; then
echo ">>> Downloading Mingw-w64 ..."
git clone ${MINGWVCS} ${MINGWDIR}
echo ">>> Downloading MinGW-w64 ..."
git clone --depth 1 --branch ${MINGWTAG} ${MINGWVCS} ${MINGWDIR}
cd ${MINGWDIR}
git checkout tags/${MINGWTAG}
apply_patches ${MINGWDIR##*/} ${MINGWTAG}
cd ${WRKDIR}
fi
@ -378,9 +411,8 @@ ninja_fetch()
{
if [ ! -d ${NINJADIR} ]; then
echo ">>> Downloading NINJA ..."
git clone ${NINJAVCS} ${NINJADIR}
git clone --depth 1 --branch ${NINJATAG} ${NINJAVCS} ${NINJADIR}
cd ${NINJADIR}
git checkout tags/${NINJATAG}
apply_patches ${NINJADIR##*/} ${NINJATAG}
cd ${WRKDIR}
fi
@ -393,9 +425,11 @@ wine_build()
mkdir -p ${WINEDIR}/build
cd ${WINEDIR}/build
../configure \
-enable-win64
-enable-win64 \
--without-freetype \
--without-x
for TOOL in winedump wmc wrc; do
make -j${CORES} tools/${TOOL}
make -j${CORES} tools/${TOOL}/all
cp tools/${TOOL}/${TOOL} ${BINDIR}/bin/
for ARCH in ${ARCHS}; do
if [ ! -e ${BINDIR}/bin/${ARCH}-w64-mingw32-${TOOL} ]; then
@ -411,9 +445,8 @@ wine_fetch()
{
if [ ! -d ${WINEDIR} ]; then
echo ">>> Downloading WINE ..."
git clone ${WINEVCS} ${WINEDIR}
git clone --depth 1 --branch ${WINETAG} ${WINEVCS} ${WINEDIR}
cd ${WINEDIR}
git checkout tags/${WINETAG}
apply_patches ${WINEDIR##*/} ${WINETAG##*-}
cd ${WRKDIR}
fi
@ -426,8 +459,18 @@ xtchain_build()
mkdir -p ${BINDIR}/bin
mkdir -p ${BINDIR}/lib/xtchain
mkdir -p ${BINDIR}/${GENERIC}/bin
cp ${WRKDIR}/scripts/*-wrapper ${BINDIR}/${GENERIC}/bin
for ARCH in ${ARCHS}; do
for EXEC in xtcspecc; do
for EXEC in c++ c11 c99 cc clang clang++ g++ gcc; do
ln -sf ../${GENERIC}/bin/clang-target-wrapper ${BINDIR}/bin/${ARCH}-w64-mingw32-${EXEC}
done
for EXEC in addr2line ar as nm objcopy pdbutil ranlib rc strings strip; do
ln -sf llvm-${EXEC} ${BINDIR}/bin/${ARCH}-w64-mingw32-${EXEC}
done
for EXEC in dlltool ld objdump; do
ln -sf ../${GENERIC}/bin/${EXEC}-wrapper ${BINDIR}/bin/${ARCH}-w64-mingw32-${EXEC}
done
for EXEC in bin2c exetool windres xtcspecc; do
if [ ! -e ${BINDIR}/bin/${EXEC} ]; then
gcc ${WRKDIR}/tools/${EXEC}.c -o ${BINDIR}/bin/${EXEC}
fi
@ -436,58 +479,46 @@ xtchain_build()
done
cp ${WRKDIR}/scripts/xtclib ${BINDIR}/lib/xtchain/
cp ${WRKDIR}/scripts/xtchain ${BINDIR}/
cd ${WRKDIR}
}
# Exit immediately on any failure
set -e
# Check if script launched as root
if [ "$(whoami)" = "root" ]; then
echo "This script cannot be run as root!"
exit 1
fi
# Check number of CPU cores available
: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)}
: ${CORES:=$(nproc 2>/dev/null)}
: ${CORES:=1}
if [[ ! -n ${CORES} ]]; then
: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)}
: ${CORES:=$(nproc 2>/dev/null)}
: ${CORES:=1}
fi
# Create working directories
mkdir -p ${BINDIR}
mkdir -p ${SRCDIR}
# Export compiler flags
export CFLAGS
export CXXFLAGS
# XTchain
xtchain_build
# Download LLVM
llvm_fetch
# Build and install LLVM
llvm_build
# Download Mingw-W64
mingw_fetch
# Build and install Mingw-W64 headers
mingw_build_headers
# Download Binutils
binutils_fetch
# Build and install Binutils
binutils_build
# Download GCC
gcc_fetch
# Build and install minimal GCC
gcc_build_phase1
# Build and install MSVCRT
# Build and install Mingw-W64 CRT
mingw_build_crt
# Build and install GCC
gcc_build_phase2
# Build and install LLVM compiler runtime
llvm_build_runtime
# Build and install LLVM compiler libraries
llvm_build_libs
# Build and install Mingw-W64 libraries
mingw_build_libs
@ -521,12 +552,13 @@ ninja_build
# Remove unneeded files to save disk space
echo ">>> Removing unneeded files to save disk space ..."
rm -rf ${BINDIR}/{doc,include,mingw,share/{bash-completion,emacs,gcc*,info,man,vim}}
rm -rf ${BINDIR}/{doc,include,share/{bash-completion,emacs,info,locale,man,vim}}
rm -rf ${BINDIR}/bin/amdgpu-arch,{clang-{check,exdef-mapping,import-test,offload-*,rename,scan-deps},diagtool,hmaptool,ld64.lld,modularize,nxptx-arch,wasm-ld}
# Save XT Toolchain version
cd ${WRKDIR}
: ${XTCVER:=$(git describe --exact-match --tags 2>/dev/null)}
: ${XTCVER:=DEV}
: ${XTCVER:=DEVEL}
echo "${XTCVER}" > ${BINDIR}/Version
# Prepare archive

View File

@ -1,126 +0,0 @@
diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index 5149ef582b..f09e4b7382 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -2952,6 +2952,25 @@ _bfd_XX_print_private_bfd_data_common (bfd * abfd, void * vfile)
case IMAGE_SUBSYSTEM_XBOX:
subsystem_name = "XBOX";
break;
+ /* These are the XT specific subsystems */
+ case IMAGE_SUBSYSTEM_XT_DRIVER:
+ subsystem_name = "XT driver";
+ break;
+ case IMAGE_SUBSYSTEM_XT_NATIVE:
+ subsystem_name = "XT native";
+ break;
+ case IMAGE_SUBSYSTEM_XT_GDIAPP:
+ subsystem_name = "XT GDI application";
+ break;
+ case IMAGE_SUBSYSTEM_XT_CLIAPP:
+ subsystem_name = "XT CLI application";
+ break;
+ case IMAGE_SUBSYSTEM_XT_PSXAPP:
+ subsystem_name = "XT PSX application";
+ break;
+ case IMAGE_SUBSYSTEM_XT_DYNLIB:
+ subsystem_name = "XT dynamic library";
+ break;
/* Added default case for clarity - subsystem_name is NULL anyway. */
default:
subsystem_name = NULL;
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 3866c7f458..55e069831b 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4860,7 +4860,13 @@ set_pe_subsystem (const char *s)
{ "efi-bsd", 1, IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER },
{ "efi-rtd", 1, IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER },
{ "sal-rtd", 1, IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER },
- { "xbox", 0, IMAGE_SUBSYSTEM_XBOX }
+ { "xbox", 0, IMAGE_SUBSYSTEM_XBOX },
+ { "xt-driver", 0, IMAGE_SUBSYSTEM_XT_DRIVER },
+ { "xt-native", 0, IMAGE_SUBSYSTEM_XT_NATIVE },
+ { "xt-gdiapp", 0, IMAGE_SUBSYSTEM_XT_GDIAPP },
+ { "xt-cliapp", 0, IMAGE_SUBSYSTEM_XT_CLIAPP },
+ { "xt-psxapp", 0, IMAGE_SUBSYSTEM_XT_PSXAPP },
+ { "xt-dynlib", 0, IMAGE_SUBSYSTEM_XT_DYNLIB }
};
short value;
char *copy;
diff --git a/include/coff/pe.h b/include/coff/pe.h
index c83a958eee..deeea6b49a 100644
--- a/include/coff/pe.h
+++ b/include/coff/pe.h
@@ -169,6 +169,12 @@
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
#define IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
#define IMAGE_SUBSYSTEM_XBOX 14
+#define IMAGE_SUBSYSTEM_XT_DRIVER 21
+#define IMAGE_SUBSYSTEM_XT_NATIVE 22
+#define IMAGE_SUBSYSTEM_XT_GDIAPP 23
+#define IMAGE_SUBSYSTEM_XT_CLIAPP 24
+#define IMAGE_SUBSYSTEM_XT_PSXAPP 25
+#define IMAGE_SUBSYSTEM_XT_DYNLIB 26
/* NT allows long filenames, we want to accommodate this.
This may break some of the bfd functions. */
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 3899c9d92c..c9277ded20 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -539,6 +539,12 @@ set_entry_point (void)
{ 7, "__PosixProcessStartup"},
{ 9, "WinMainCRTStartup" },
{14, "mainCRTStartup" },
+ {21, "XtDriverStartup" },
+ {22, "XtProcessStartup" },
+ {23, "XtgMainProcessStartup" },
+ {24, "XtcMainProcessStartup" },
+ {25, "XtpMainProcessStartup" },
+ {26, "XtlMainLibraryStartup" },
{ 0, NULL }
};
@@ -606,6 +611,12 @@ set_pe_subsystem (void)
{ "posix", 7},
{ "wince", 9},
{ "xbox", 14},
+ { "xt-driver", 21},
+ { "xt-native", 22},
+ { "xt-gdiapp", 23},
+ { "xt-cliapp", 24},
+ { "xt-psxapp", 25},
+ { "xt-dynlib", 26},
{ NULL, 0 }
};
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index a0a7023e70..001aa34769 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -504,6 +504,12 @@ set_entry_point (void)
{ 7, "__PosixProcessStartup" },
{ 9, "WinMainCRTStartup" },
{14, "mainCRTStartup" },
+ {21, "XtDriverStartup" },
+ {22, "XtProcessStartup" },
+ {23, "XtgMainProcessStartup" },
+ {24, "XtcMainProcessStartup" },
+ {25, "XtpMainProcessStartup" },
+ {26, "XtlMainLibraryStartup" },
{ 0, NULL }
};
@@ -568,6 +573,12 @@ set_pep_subsystem (void)
{ "posix", 7 },
{ "wince", 9 },
{ "xbox", 14 },
+ { "xt-driver", 21},
+ { "xt-native", 22},
+ { "xt-gdiapp", 23},
+ { "xt-cliapp", 24},
+ { "xt-psxapp", 25},
+ { "xt-dynlib", 26},
{ NULL, 0 }
};

View File

@ -1,36 +0,0 @@
Though GOLD is not yet enabled for TDM-GCC, this patch will help
From: J.M. Eubank <john@thesnappy.net>
From
<https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-binutils/0001-enable-gold-on.mingw32.patch>
---
0 files changed
diff --git a/configure b/configure
index 6a9719f6..f07a3b7f 100755
--- a/configure
+++ b/configure
@@ -3001,6 +3001,7 @@ case "${ENABLE_GOLD}" in
yes|default)
# Check for ELF target.
is_elf=no
+ is_pe=no
case "${target}" in
*-*-elf* | *-*-sysv4* | *-*-unixware* | *-*-eabi* | hppa*64*-*-hpux* \
| *-*-linux* | *-*-gnu* | frv-*-uclinux* | *-*-irix5* | *-*-irix6* \
@@ -3012,10 +3013,12 @@ case "${ENABLE_GOLD}" in
*)
is_elf=yes
;;
- esac
+ esac;;
+ *-*-mingw*)
+ is_pe=yes;;
esac
- if test "$is_elf" = "yes"; then
+ if test "$is_elf" = "yes" -o "$is_pe" = "yes"; then
# Check for target supported by gold.
case "${target}" in
i?86-*-* | x86_64-*-* | sparc*-*-* | powerpc*-*-* | arm*-*-* \

View File

@ -0,0 +1,13 @@
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 818109f0b7..749377d193 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -7,7 +7,7 @@ set(CMake_VERSION_IS_DIRTY 0)
# Start with the full version number used in tags. It has no dev info.
set(CMake_VERSION
- "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
+ "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}-XTC")
if(DEFINED CMake_VERSION_RC)
set(CMake_VERSION "${CMake_VERSION}-rc${CMake_VERSION_RC}")
endif()

View File

@ -0,0 +1,13 @@
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 818109f0b7..749377d193 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -7,7 +7,7 @@ set(CMake_VERSION_IS_DIRTY 0)
# Start with the full version number used in tags. It has no dev info.
set(CMake_VERSION
- "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
+ "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}-XTC")
if(DEFINED CMake_VERSION_RC)
set(CMake_VERSION "${CMake_VERSION}-rc${CMake_VERSION_RC}")
endif()

View File

@ -1,57 +0,0 @@
Make GCC fully relocatable, not searching any fixed paths
From: J.M. Eubank <john@thesnappy.net>
that aren't relative to the current installation path
# HG changeset patch
# Parent 2a1167ee4ed20c6ff3558a104218585837e9963f
---
0 files changed
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index 086c0e460..f0ceca42b 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -78,7 +78,7 @@ along with GCC; see the file COPYING3. If not see
#endif
#undef NATIVE_SYSTEM_HEADER_COMPONENT
-#define NATIVE_SYSTEM_HEADER_COMPONENT "MINGW"
+#undef NATIVE_SYSTEM_HEADER_DIR
#undef CPP_SPEC
#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \
@@ -183,17 +183,12 @@ along with GCC; see the file COPYING3. If not see
/* Override startfile prefix defaults. */
#ifndef STANDARD_STARTFILE_PREFIX_1
-#define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/"
+#define STANDARD_STARTFILE_PREFIX_1 ""
#endif
#ifndef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_2 ""
#endif
-/* For native mingw-version we need to take care that NATIVE_SYSTEM_HEADER_DIR
- macro contains POSIX-style path. See bug 52947. */
-#undef NATIVE_SYSTEM_HEADER_DIR
-#define NATIVE_SYSTEM_HEADER_DIR "/mingw/include"
-
/* Output STRING, a string representing a filename, to FILE.
We canonicalize it to be in Unix format (backslashes are replaced
forward slashes. */
diff --git a/gcc/incpath.c b/gcc/incpath.c
index bcbe20829..c5d4453d8 100644
--- a/gcc/incpath.c
+++ b/gcc/incpath.c
@@ -183,8 +183,7 @@ add_standard_paths (const char *sysroot, const char *iprefix,
str = concat (sysroot_no_trailing_dir_separator, p->fname, NULL);
free (sysroot_no_trailing_dir_separator);
}
- else if (!p->add_sysroot && relocated
- && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len))
+ if (relocated && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len))
{
static const char *relocated_prefix;
char *ostr;

View File

@ -1,7 +1,7 @@
diff -apurN a/mingw-w64-tools/widl/Makefile.am b/mingw-w64-tools/widl/Makefile.am
--- a/mingw-w64-tools/widl/Makefile.am 2020-07-31 23:17:43.793863913 +0200
+++ b/mingw-w64-tools/widl/Makefile.am 2020-07-31 21:16:36.330432306 +0200
@@ -30,6 +30,7 @@ widl_SOURCES = src/widl.h \
--- a/mingw-w64-tools/widl/Makefile.am 2020-10-13 16:23:12.944066396 +0200
+++ b/mingw-w64-tools/widl/Makefile.am 2020-10-13 16:19:00.523221067 +0200
@@ -29,6 +29,7 @@ widl_SOURCES = src/widl.h \
src/utils.c \
src/widl.c \
src/write_msft.c \
@ -10,18 +10,19 @@ diff -apurN a/mingw-w64-tools/widl/Makefile.am b/mingw-w64-tools/widl/Makefile.a
src/wpp/ppy.tab.h \
src/wpp/ppl.yy.c \
diff -apurN a/mingw-w64-tools/widl/Makefile.in b/mingw-w64-tools/widl/Makefile.in
--- a/mingw-w64-tools/widl/Makefile.in 2020-07-31 23:17:43.793863913 +0200
+++ b/mingw-w64-tools/widl/Makefile.in 2020-07-31 21:21:18.957064708 +0200
@@ -117,7 +117,7 @@ am_widl_OBJECTS = src/widl-client.$(OBJE
src/widl-widl.$(OBJEXT) src/widl-write_msft.$(OBJEXT) \
src/wpp/widl-ppl.yy.$(OBJEXT) src/wpp/widl-ppy.tab.$(OBJEXT) \
src/wpp/widl-preproc.$(OBJEXT) src/wpp/widl-wpp.$(OBJEXT) \
- src/widl-pathtools.$(OBJEXT)
+ src/widl-pathtools.$(OBJEXT) src/widl-write_sltg.$(OBJEXT)
--- a/mingw-w64-tools/widl/Makefile.in 2020-10-13 16:23:12.944066396 +0200
+++ b/mingw-w64-tools/widl/Makefile.in 2020-10-13 16:21:19.069027341 +0200
@@ -117,7 +117,8 @@ am_widl_OBJECTS = src/widl-client.$(OBJE
src/widl-utils.$(OBJEXT) src/widl-widl.$(OBJEXT) \
src/widl-write_msft.$(OBJEXT) src/wpp/widl-ppl.yy.$(OBJEXT) \
src/wpp/widl-ppy.tab.$(OBJEXT) src/wpp/widl-preproc.$(OBJEXT) \
- src/wpp/widl-wpp.$(OBJEXT) src/widl-pathtools.$(OBJEXT)
+ src/wpp/widl-wpp.$(OBJEXT) src/widl-pathtools.$(OBJEXT) \
+ src/widl-write_sltg.$(OBJEXT)
widl_OBJECTS = $(am_widl_OBJECTS)
widl_LDADD = $(LDADD)
widl_LINK = $(CCLD) $(widl_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
@@ -340,6 +340,7 @@ widl_SOURCES = src/widl.h \
@@ -356,6 +357,7 @@ widl_SOURCES = src/widl.h \
src/utils.c \
src/widl.c \
src/write_msft.c \
@ -29,7 +30,7 @@ diff -apurN a/mingw-w64-tools/widl/Makefile.in b/mingw-w64-tools/widl/Makefile.i
src/wpp/wpp_private.h \
src/wpp/ppy.tab.h \
src/wpp/ppl.yy.c \
@@ -513,6 +514,8 @@ src/widl-widl.$(OBJEXT): src/$(am__dirst
@@ -527,6 +529,8 @@ src/widl-widl.$(OBJEXT): src/$(am__dirst
src/$(DEPDIR)/$(am__dirstamp)
src/widl-write_msft.$(OBJEXT): src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
@ -38,15 +39,7 @@ diff -apurN a/mingw-w64-tools/widl/Makefile.in b/mingw-w64-tools/widl/Makefile.i
src/wpp/$(am__dirstamp):
@$(MKDIR_P) src/wpp
@: > src/wpp/$(am__dirstamp)
@@ -559,6 +562,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/widl-utils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/widl-widl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/widl-write_msft.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/widl-write_sltg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/port/$(DEPDIR)/widl-getopt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/port/$(DEPDIR)/widl-getopt1.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/port/$(DEPDIR)/widl-port.Po@am__quote@
@@ -835,6 +839,20 @@ src/widl-write_msft.obj: src/write_msft.
@@ -840,6 +845,20 @@ src/widl-write_msft.obj: src/write_msft.
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(widl_CPPFLAGS) $(CPPFLAGS) $(widl_CFLAGS) $(CFLAGS) -c -o src/widl-write_msft.obj `if test -f 'src/write_msft.c'; then $(CYGPATH_W) 'src/write_msft.c'; else $(CYGPATH_W) '$(srcdir)/src/write_msft.c'; fi`
@ -68,9 +61,9 @@ diff -apurN a/mingw-w64-tools/widl/Makefile.in b/mingw-w64-tools/widl/Makefile.i
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(widl_CPPFLAGS) $(CPPFLAGS) $(widl_CFLAGS) $(CFLAGS) -MT src/wpp/widl-ppl.yy.o -MD -MP -MF src/wpp/$(DEPDIR)/widl-ppl.yy.Tpo -c -o src/wpp/widl-ppl.yy.o `test -f 'src/wpp/ppl.yy.c' || echo '$(srcdir)/'`src/wpp/ppl.yy.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/wpp/$(DEPDIR)/widl-ppl.yy.Tpo src/wpp/$(DEPDIR)/widl-ppl.yy.Po
diff -apurN a/mingw-w64-tools/widl/src/register.c b/mingw-w64-tools/widl/src/register.c
--- a/mingw-w64-tools/widl/src/register.c 2020-07-31 23:17:43.798863890 +0200
+++ b/mingw-w64-tools/widl/src/register.c 2020-07-31 21:13:59.935209986 +0200
@@ -286,7 +286,12 @@ void write_typelib_regscript( const stat
--- a/mingw-w64-tools/widl/src/register.c 2020-10-13 16:23:12.950066345 +0200
+++ b/mingw-w64-tools/widl/src/register.c 2020-10-13 16:19:00.523221067 +0200
@@ -281,7 +281,12 @@ void write_typelib_regscript( const stat
if (count && !strendswith( typelib_name, ".res" ))
error( "Cannot store multiple typelibs into %s\n", typelib_name );
else
@ -85,8 +78,8 @@ diff -apurN a/mingw-w64-tools/widl/src/register.c b/mingw-w64-tools/widl/src/reg
}
if (count && strendswith( typelib_name, ".res" )) flush_output_resources( typelib_name );
diff -apurN a/mingw-w64-tools/widl/src/typelib.h b/mingw-w64-tools/widl/src/typelib.h
--- a/mingw-w64-tools/widl/src/typelib.h 2020-07-31 23:17:43.537865053 +0200
+++ b/mingw-w64-tools/widl/src/typelib.h 2020-07-31 21:13:59.935209986 +0200
--- a/mingw-w64-tools/widl/src/typelib.h 2020-10-13 16:23:12.950066345 +0200
+++ b/mingw-w64-tools/widl/src/typelib.h 2020-10-13 16:19:00.523221067 +0200
@@ -83,4 +83,5 @@ enum VARENUM {
extern unsigned short get_type_vt(type_t *t);
@ -94,17 +87,17 @@ diff -apurN a/mingw-w64-tools/widl/src/typelib.h b/mingw-w64-tools/widl/src/type
+extern int create_sltg_typelib(typelib_t *typelib);
#endif
diff -apurN a/mingw-w64-tools/widl/src/widl.c b/mingw-w64-tools/widl/src/widl.c
--- a/mingw-w64-tools/widl/src/widl.c 2020-07-31 23:17:43.799863886 +0200
+++ b/mingw-w64-tools/widl/src/widl.c 2020-07-31 21:13:59.935209986 +0200
@@ -62,6 +62,7 @@ static const char usage[] =
" -m32, -m64 Set the target architecture (Win32 or Win64)\n"
" -N Do not preprocess input\n"
--- a/mingw-w64-tools/widl/src/widl.c 2020-10-13 16:23:12.951066337 +0200
+++ b/mingw-w64-tools/widl/src/widl.c 2020-10-13 16:22:05.493635687 +0200
@@ -64,6 +64,7 @@ static const char usage[] =
" --nostdinc Do not search the standard include path\n"
" --ns_prefix Prefix namespaces with ABI namespace\n"
" --oldnames Use old naming conventions\n"
+" --oldtlb Use old typelib (SLTG) format\n"
" -o, --output=NAME Set the output file name\n"
" -Otype Type of stubs to generate (-Os, -Oi, -Oif)\n"
" -p Generate proxy\n"
@@ -114,6 +115,7 @@ int do_everything = 1;
@@ -116,6 +117,7 @@ int do_everything = 1;
static int preprocess_only = 0;
int do_header = 0;
int do_typelib = 0;
@ -112,23 +105,23 @@ diff -apurN a/mingw-w64-tools/widl/src/widl.c b/mingw-w64-tools/widl/src/widl.c
int do_proxies = 0;
int do_client = 0;
int do_server = 0;
@@ -164,6 +166,7 @@ enum {
@@ -168,6 +170,7 @@ enum {
DLLDATA_OPTION,
DLLDATA_ONLY_OPTION,
LOCAL_STUBS_OPTION,
+ OLD_TYPELIB_OPTION,
NOSTDINC_OPTION,
PREFIX_ALL_OPTION,
PREFIX_CLIENT_OPTION,
PREFIX_SERVER_OPTION,
@@ -188,6 +191,7 @@ static const struct option long_options[
{ "local-stubs", 1, NULL, LOCAL_STUBS_OPTION },
@@ -195,6 +198,7 @@ static const struct option long_options[
{ "nostdinc", 0, NULL, NOSTDINC_OPTION },
{ "ns_prefix", 0, NULL, RT_NS_PREFIX },
{ "oldnames", 0, NULL, OLDNAMES_OPTION },
+ { "oldtlb", 0, NULL, OLD_TYPELIB_OPTION },
{ "output", 0, NULL, 'o' },
{ "prefix-all", 1, NULL, PREFIX_ALL_OPTION },
{ "prefix-client", 1, NULL, PREFIX_CLIENT_OPTION },
@@ -325,6 +329,7 @@ static void set_everything(int x)
@@ -333,6 +337,7 @@ static void set_everything(int x)
{
do_header = x;
do_typelib = x;
@ -136,7 +129,7 @@ diff -apurN a/mingw-w64-tools/widl/src/widl.c b/mingw-w64-tools/widl/src/widl.c
do_proxies = x;
do_client = x;
do_server = x;
@@ -712,6 +717,9 @@ int main(int argc,char *argv[])
@@ -749,6 +754,9 @@ int main(int argc,char *argv[])
do_everything = 0;
do_typelib = 1;
break;
@ -147,8 +140,8 @@ diff -apurN a/mingw-w64-tools/widl/src/widl.c b/mingw-w64-tools/widl/src/widl.c
typelib_name = xstrdup(optarg);
break;
diff -apurN a/mingw-w64-tools/widl/src/widl.h b/mingw-w64-tools/widl/src/widl.h
--- a/mingw-w64-tools/widl/src/widl.h 2020-07-31 23:17:43.537865053 +0200
+++ b/mingw-w64-tools/widl/src/widl.h 2020-07-31 21:13:59.935209986 +0200
--- a/mingw-w64-tools/widl/src/widl.h 2020-10-13 16:23:12.951066337 +0200
+++ b/mingw-w64-tools/widl/src/widl.h 2020-10-13 16:19:00.524221058 +0200
@@ -38,6 +38,7 @@ extern int pedantic;
extern int do_everything;
extern int do_header;
@ -159,7 +152,7 @@ diff -apurN a/mingw-w64-tools/widl/src/widl.h b/mingw-w64-tools/widl/src/widl.h
extern int do_server;
diff -apurN a/mingw-w64-tools/widl/src/write_sltg.c b/mingw-w64-tools/widl/src/write_sltg.c
--- a/mingw-w64-tools/widl/src/write_sltg.c 1970-01-01 01:00:00.000000000 +0100
+++ b/mingw-w64-tools/widl/src/write_sltg.c 2020-07-31 21:13:59.936209981 +0200
+++ b/mingw-w64-tools/widl/src/write_sltg.c 2020-10-13 16:19:00.524221058 +0200
@@ -0,0 +1,1857 @@
+/*
+ * Typelib (SLTG) generation

42
scripts/clang-target-wrapper Executable file
View File

@ -0,0 +1,42 @@
#!/bin/sh
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/clang-target-wrapper
# DESCRIPTION: CLANG Wrapper
# DEVELOPERS: Martin Storsjo <martin@martin.st>
# Rafal Kupiec <belliash@codingworkshop.eu.org>
# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
CLANG="$DIR/clang"
BASENAME="$(basename $0)"
TARGET="${BASENAME%-*}"
EXECUTABLE="${BASENAME##*-}"
DEFAULT_TARGET="x86_64-w64-mingw32"
ARCH="${TARGET%%-*}"
# Set proper target
if [ "${TARGET}" = "${BASENAME}" ]; then
TARGET="${DEFAULT_TARGET}"
fi
# Set lang-specific flags
case ${EXECUTABLE} in
"clang++"|"g++"|"c++")
FLAGS="$FLAGS --driver-mode=g++"
;;
*)
FLAGS=""
;;
esac
# Set compiler flags
FLAGS="${FLAGS} -target ${TARGET}"
FLAGS="${FLAGS} -rtlib=compiler-rt"
FLAGS="${FLAGS} -stdlib=libc++"
FLAGS="${FLAGS} -fuse-ld=lld"
FLAGS="${FLAGS} -Qunused-arguments"
# Launch the compiler
$CLANG $FLAGS "$@"

42
scripts/dlltool-wrapper Executable file
View File

@ -0,0 +1,42 @@
#!/bin/sh
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/dlltool-wrapper
# DESCRIPTION: DLLTOOL Wrapper
# DEVELOPERS: Martin Storsjo <martin@martin.st>
# Rafal Kupiec <belliash@codingworkshop.eu.org>
# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
BASENAME="$(basename $0)"
TARGET="${BASENAME%-*}"
DEFAULT_TARGET="x86_64-w64-mingw32"
# Update PATH
export PATH="$DIR":"$PATH"
# Set proper target
if [ "${TARGET}" = "${BASENAME}" ]; then
TARGET="${DEFAULT_TARGET}"
fi
# Set target machine
ARCH="${TARGET%%-*}"
case $ARCH in
aarch64)
M="arm64"
;;
armv7)
M="arm"
;;
i686)
M="i386"
;;
x86_64)
M="i386:x86-64"
;;
esac
# Launch the utility
llvm-dlltool -m ${M} "$@"

42
scripts/ld-wrapper Executable file
View File

@ -0,0 +1,42 @@
#!/bin/sh
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/ld-wrapper
# DESCRIPTION: LLD Wrapper
# DEVELOPERS: Martin Storsjo <martin@martin.st>
# Rafal Kupiec <belliash@codingworkshop.eu.org>
# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
BASENAME="$(basename $0)"
TARGET="${BASENAME%-*}"
DEFAULT_TARGET="x86_64-w64-mingw32"
# Update PATH
export PATH="${DIR}":"${PATH}"
# Set proper target
if [ "${TARGET}" = "${BASENAME}" ]; then
TARGET="${DEFAULT_TARGET}"
fi
# Set target machine
ARCH="${TARGET%%-*}"
case ${ARCH} in
aarch64)
M="arm64pe"
;;
armv7)
M="thumb2pe"
;;
i686)
M="i386pe"
;;
x86_64)
M="i386pep"
;;
esac
# Launch the linker
ld.lld -m ${M} "$@"

46
scripts/objdump-wrapper Executable file
View File

@ -0,0 +1,46 @@
#!/bin/sh
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/objdump-wrapper
# DESCRIPTION: OBJDUMP Wrapper
# DEVELOPERS: Martin Storsjo <martin@martin.st>
# Rafal Kupiec <belliash@codingworkshop.eu.org>
# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
# Update PATH
export PATH="$DIR":"$PATH"
# Libtool can try to run objdump -f and wants to see certain strings in
# the output, to accept it being a valid windows (import) library
if [ "$1" = "-f" ]; then
llvm-readobj $2 | while read -r line; do
case $line in
File:*)
file=$(echo $line | awk '{print $2}')
;;
Format:*)
format=$(echo $line | awk '{print $2}')
case $format in
COFF-i386)
format=pe-i386
;;
COFF-x86-64)
format=pe-x86-64
;;
COFF-ARM*)
# This is wrong; modern COFF armv7 isn't pe-arm-wince, and
# arm64 definitely isn't, but libtool wants to see this
# string (or some of the others) in order to accept it.
format=pe-arm-wince
;;
esac
echo $file: file format $format
;;
esac
done
else
llvm-objdump "$@"
fi

View File

@ -6,12 +6,6 @@
# DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
# Check if script launched as root
if [ "$(whoami)" = "root" ]; then
echo "This script cannot be run as root!"
exit 1
fi
# Get the absolute path to the XTchain
export XTCDIR="$(realpath $(dirname ${0}))"

View File

@ -14,8 +14,14 @@ charch()
return
fi
case ${1} in
"aarch64"|"arm64")
export TARGET="aarch64"
;;
"arm"|"armv7")
export TARGET="armv7"
;;
"i386"|"i486"|"i586"|"i686"|"x86")
export TARGET="i386"
export TARGET="i686"
;;
"amd64"|"x64"|"x86_64")
export TARGET="amd64"
@ -27,23 +33,72 @@ charch()
}
export -f charch
# Sets the build type
chbuild()
{
if [ "x${1}" == "x" ]; then
echo "Syntax: chbuild [DEBUG|RELEASE]"
return
fi
case ${1} in
[Rr][Ee][Ll][Ee][Aa][Ss][Ee])
export BUILD_TYPE="RELEASE"
;;
*)
export BUILD_TYPE="DEBUG"
esac
echo "Target build type: ${BUILD_TYPE}"
}
export -f chbuild
# Prints help
help()
{
version
echo "XTChain defines an internal list of commands:"
echo " * charch [arch] - sets the target CPU architecture [aarch64/armv7/i686/amd64]"
echo " * chbuild [type] - sets build type [debug/release]"
echo " * help - prints this message"
echo " * version - prints XTChain and its components version"
echo " * xbuild - builds an application with a Ninja build system"
}
export -f help
# Displays version banner
version()
{
echo "###############################################################################"
echo "# FerretOS Build Environment v${XTCVER} for Linux #"
echo "# XT Toolchain v${XTCVER} for Linux #"
echo "# by Rafal Kupiec <belliash@codingworkshop.eu.org> #"
echo "###############################################################################"
echo
echo
echo "Binutils Version: $(${XTCDIR}/bin/i686-w64-mingw32-ld -v | cut -d' ' -f5)"
echo "GCC Version: $(${XTCDIR}/bin/i686-w64-mingw32-gcc -v 2>&1| grep 'gcc version' | cut -d' ' -f3)"
echo "IDL Compiler Version: $(${XTCDIR}/bin/i686-w64-mingw32-widl -V | grep 'version' | cut -d' ' -f5)"
echo "LLVM Compiler Version: $(${XTCDIR}/bin/clang --version | grep 'clang version' | cut -d' ' -f3)"
echo "LLVM Windres Utility Version: $(${XTCDIR}/bin/i686-w64-mingw32-windres -V | cut -d' ' -f6)"
echo "Mingw IDL Compiler Version: $(${XTCDIR}/bin/i686-w64-mingw32-widl -V | grep 'version' | cut -d' ' -f5)"
echo "Wine Message Compiler Version: $(${XTCDIR}/bin/wmc -V | grep 'version' | cut -d' ' -f5)"
echo "Wine Resource Compiler Version: $(${XTCDIR}/bin/wrc --version | grep 'version' | cut -d' ' -f5)"
echo
charch ${TARGET}
charch ${TARGET:-amd64}
chbuild ${BUILD_TYPE:-DEBUG}
echo
echo
}
export -f version
# Builds application (wrapper to Ninja)
xbuild()
{
if [ ! -f build.arch ]; then
ninja "$@"
else
ARCH=$(cat build.arch)
if [ x"${ARCH}" != x"${TARGET}" ]; then
echo "Build is configured for '${ARCH}' while current target set to '${TARGET}'!"
echo "Cannot continue until conflict is resolved ..."
return 1
fi
ninja "$@"
fi
}
export -f xbuild

74
tools/bin2c.c Normal file
View File

@ -0,0 +1,74 @@
/**
* PROJECT: XTchain
* LICENSE: See COPYING.md in the top level directory
* FILE: tools/bin2c.c
* DESCRIPTION: Binary to C converter
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include "xtchain.h"
int main(int argc, char *argv[])
{
/* Check for proper number of arguments */
if(argc != 4)
{
printf("Usage: %s <input binary> <output file> <structure name>\n", argv[0]);
return 1;
}
/* Open the input binary file in binary mode */
FILE *inputFile = fopen(argv[1], "rb");
if(inputFile == NULL)
{
printf("Error: unable to open file %s\n", argv[1]);
return 1;
}
/* Open the destination source code file in text mode */
FILE *outputFile = fopen(argv[2], "w");
if(outputFile == NULL)
{
printf("Error: unable to open file %s\n", argv[2]);
fclose(inputFile);
return 1;
}
/* Get the size of the binary file */
fseek(inputFile, 0, SEEK_END);
long binSize = ftell(inputFile);
rewind(inputFile);
/* Allocate memory for the binary data */
unsigned char *binData = (unsigned char *)malloc(binSize);
if(binData == NULL)
{
printf("Error: unable to allocate memory for binary data\n");
fclose(inputFile);
fclose(outputFile);
return 1;
}
/* Read the binary data into memory */
fread(binData, sizeof(unsigned char), binSize, inputFile);
/* Write the C structure to the header file */
fprintf(outputFile, "unsigned char %s[] = {", argv[3]);
for(int i = 0; i < binSize; i++)
{
fprintf(outputFile, "0x%02X", binData[i]);
if(i < binSize - 1)
{
fprintf(outputFile, ",");
}
}
fprintf(outputFile, "};\nunsigned int %s_size = %ld;\n", argv[3], binSize);
free(binData);
/* Close all open files */
fclose(inputFile);
fclose(outputFile);
printf("Binary data converted to C structure successfully.\n");
return 0;
}

182
tools/exetool.c Normal file
View File

@ -0,0 +1,182 @@
/**
* PROJECT: XTchain
* LICENSE: See COPYING.md in the top level directory
* FILE: tools/exetool.c
* DESCRIPTION: Portable Executable (PE) utility for changing its signature and subsystem
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include "xtchain.h"
typedef struct _PE_SUBSYSTEM
{
int Identifier;
char *Name;
} PE_SUBSYSTEM, *PPE_SUBSYSTEM;
static PE_SUBSYSTEM SubSystems[] = {
{0x00, "INVALID_SUBSYSTEM"},
{0x01, "NT_NATIVE"},
{0x02, "WINDOWS_GUI"},
{0x03, "WINDOWS_CLI"},
{0x04, "WINDOWS_CE_OLD"},
{0x05, "OS2_CUI"},
{0x07, "POSIX_CUI"},
{0x08, "NATIVE_WINDOWS"},
{0x09, "WINDOWS_CE_GUI"},
{0x0A, "EFI_APPLICATION"},
{0x0B, "EFI_BOOT_SERVICE_DRIVER"},
{0x0C, "EFI_RUNTIME_DRIVER"},
{0x0D, "EFI_ROM"},
{0x0E, "XBOX"},
{0x10, "WINDOWS_BOOT_APPLICATION"},
{0x14, "XT_NATIVE_KERNEL"},
{0x15, "XT_NATIVE_APPLICATION"},
{0x16, "XT_NATIVE_DRIVER"},
{0x17, "XT_DYNAMIC_LIBRARY"},
{0x18, "XT_APPLICATION_CLI"},
{0x19, "XT_APPLICATION_GDI"}
};
PPE_SUBSYSTEM getSubSystem(char *Name)
{
int Index;
int SubSystemsCount;
PPE_SUBSYSTEM SubSystem;
/* Count number of subsystems avaialble */
SubSystemsCount = sizeof(SubSystems) / sizeof(PE_SUBSYSTEM);
/* Find subsystem */
for(Index = 0; Index < SubSystemsCount; Index++)
{
SubSystem = &SubSystems[Index];
if(strcasecmp(SubSystem->Name, Name) == 0)
{
/* Subsystem found, return its ID */
return SubSystem;
}
}
/* No valid subsystem found */
return &SubSystems[0];
}
char *getSubSystemName(int Identifier)
{
int Index;
int SubSystemsCount;
PPE_SUBSYSTEM SubSystem;
/* Count number of subsystems avaialble */
SubSystemsCount = sizeof(SubSystems) / sizeof(PE_SUBSYSTEM);
/* Find subsystem */
for(Index = 0; Index < SubSystemsCount; Index++)
{
SubSystem = &SubSystems[Index];
if(SubSystem->Identifier == Identifier)
{
/* Subsystem found, return its ID */
return SubSystem->Name;
}
}
/* No valid subsystem found */
return SubSystems[0].Name;
}
int main(int argc, char *argv[])
{
FILE *ExeFile;
unsigned char Signature[4];
unsigned int HeaderOffset;
unsigned int ImageSignature;
unsigned short SubSystem;
PPE_SUBSYSTEM NewSubSystem;
/* Check for proper number of arguments */
if(argc != 3)
{
printf("Usage: %s <filename> <new SubSystem>\n", argv[0]);
return 1;
}
/* Parse the new SubSystem value from the command line argument */
NewSubSystem = getSubSystem(argv[2]);
if(NewSubSystem->Identifier == 0)
{
/* Invalid SubSystem provided */
printf("Error: %s is not a valid PE SubSystem\n", argv[2]);
return 1;
}
/* Open the EXE file in binary mode */
ExeFile = fopen(argv[1], "r+b");
if(ExeFile == NULL)
{
/* Failed to open PE file */
printf("ERROR: Unable to open file %s\n", argv[1]);
return 2;
}
/* Verify that the input file has a valid DOS header */
fread(Signature, sizeof(unsigned char), 4, ExeFile);
if(Signature[0] != 'M' || Signature[1] != 'Z')
{
/* Invalid DOS header */
printf("ERROR: %s is not a valid EXE file\n", argv[1]);
fclose(ExeFile);
return 3;
}
/* Verify that the input file has a valid PE header */
fseek(ExeFile, 0x3C, SEEK_SET);
fread(&HeaderOffset, sizeof(unsigned int), 1, ExeFile);
fseek(ExeFile, HeaderOffset, SEEK_SET);
fread(Signature, sizeof(unsigned char), 4, ExeFile);
if((Signature[0] != 'P' || Signature[1] != 'E' || Signature[2] != 0 || Signature[3] != 0) &&
(Signature[0] != 'P' || Signature[1] != 'E' || Signature[2] != 'X' || Signature[3] != 'T'))
{
/* Invalid PE header */
printf("Error: %s is not a valid PE file\n", argv[1]);
fclose(ExeFile);
return 3;
}
/* Check if setting XT subsystem */
if(NewSubSystem->Identifier >= 0x14 && NewSubSystem->Identifier <= 0x19)
{
/* Write PEXT signature */
ImageSignature = 0x54584550;
}
else
{
/* Write PE00 signature */
ImageSignature = 0x00004550;
}
/* Seek back to header offset and write new signature */
fseek(ExeFile, HeaderOffset, SEEK_SET);
fwrite(&ImageSignature, sizeof(ImageSignature), 1, ExeFile);
/* Seek to the offset of the SubSystem field in the optional header */
fseek(ExeFile, HeaderOffset + 0x5C, SEEK_SET);
/* Read the current SubSystem value */
fread(&SubSystem, sizeof(unsigned short), 1, ExeFile);
/* Seek back to the SubSystem field in the optional header */
fseek(ExeFile, -sizeof(unsigned short), SEEK_CUR);
/* Write the new SubSystem value */
fwrite(&NewSubSystem->Identifier, sizeof(unsigned short), 1, ExeFile);
/* Close the file */
fclose(ExeFile);
/* Finished successfully */
printf("PE SubSystem modified: 0x%02X <%s> to 0x%02X <%s>\n",
SubSystem, getSubSystemName(SubSystem), NewSubSystem->Identifier, NewSubSystem->Name);
return 0;
}

558
tools/windres.c Normal file
View File

@ -0,0 +1,558 @@
/**
* PROJECT: XTchain
* LICENSE: See COPYING.md in the top level directory
* FILE: tools/windres.c
* DESCRIPTION: WINDRES compatible interface to LLVM
* DEVELOPERS: Josh de Kock <josh@itanimul.li>
* Martin Storsjo <martin@martin.st>
* Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include "xtchain.h"
#define WINDRES_VERSION "1.0"
#ifndef DEFAULT_TARGET
#define DEFAULT_TARGET "x86_64-w64-mingw32"
#endif
#include <stdarg.h>
#define _tspawnvp_escape _spawnvp
#include <sys/wait.h>
#include <errno.h>
#define _P_WAIT 0
static
int
_spawnvp(int mode,
const char *filename,
const char * const *argv)
{
pid_t pid;
if(!(pid = fork()))
{
execvp(filename, (char **) argv);
perror(filename);
exit(1);
}
int stat = 0;
if(waitpid(pid, &stat, 0) == -1)
{
return -1;
}
if(WIFEXITED(stat))
{
return WEXITSTATUS(stat);
}
errno = EIO;
return -1;
}
static
const
char *unescape_cpp(const char *str)
{
char *out = strdup(str);
int len = strlen(str);
int i, outpos = 0;
for(i = 0; i < len - 1; i++)
{
if(str[i] == '\\' && str[i + 1] == '"')
{
continue;
}
out[outpos++] = str[i];
}
while(i < len)
{
out[outpos++] = str[i++];
}
out[outpos++] = '\0';
return out;
}
static
void print_version(void)
{
printf("XTchain windres (GNU windres compatible) %s\n", WINDRES_VERSION);
exit(0);
}
static
void print_help(void)
{
printf(
"usage: llvm-windres <OPTION> [INPUT-FILE] [OUTPUT-FILE]\n"
"\n"
"LLVM Tool to manipulate Windows resources with a GNU windres interface.\n"
"\n"
"Options:\n"
" -i, --input <arg> Name of the input file.\n"
" -o, --output <arg> Name of the output file.\n"
" -J, --input-format <arg> Input format to read.\n"
" -O, --output-format <arg> Output format to generate.\n"
" --preprocessor <arg> Custom preprocessor command.\n"
" --preprocessor-arg <arg> Preprocessor command arguments.\n"
" -F, --target <arg> Target for COFF objects to be compiled for.\n"
" -I, --include-dir <arg> Include directory to pass to preprocessor and resource compiler.\n"
" -D, --define <arg[=val]> Define to pass to preprocessor.\n"
" -U, --undefine <arg[=val]> Undefine to pass to preprocessor.\n"
" -c, --codepage <arg> Default codepage to use when reading an rc file (0x0-0xffff).\n"
" -l, --language <arg> Specify default language (0x0-0xffff).\n"
" --use-temp-file Use a temporary file for the preprocessing output.\n"
" -v, --verbose Enable verbose output.\n"
" -V, --version Display version.\n"
" -h, --help Display this message and exit.\n"
"Input Formats:\n"
" rc Text Windows Resource\n"
" res Binary Windows Resource\n"
"Output Formats:\n"
" res Binary Windows Resource\n"
" coff COFF object\n"
"Targets:\n"
" pe-x86-64\n"
" pei-x86-64\n"
" pe-i386\n"
" pei-i386\n");
exit(0);
}
static
void error(const char *basename,
const char *fmt,
...)
{
fprintf(stderr, _T(TS": error: "), basename);
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, _T("\n"));
va_end(ap);
exit(1);
}
static
void print_argv(const char **exec_argv)
{
while(*exec_argv)
{
fprintf(stderr, _T(TS" "), *exec_argv);
exec_argv++;
}
fprintf(stderr, _T("\n"));
}
static
void check_num_args(int arg,
int max_arg)
{
if(arg > max_arg)
{
fprintf(stderr, "Too many options added\n");
abort();
}
}
int main(int argc,
char* argv[])
{
char *dir;
char *basename;
char *target;
split_argv(argv[0], &dir, &basename, &target, NULL);
if (!target)
target = _T(DEFAULT_TARGET);
const char *bfd_target = NULL;
const char *input = _T("-");
const char *output = _T("/dev/stdout");
const char *input_format = _T("rc");
const char *output_format = _T("coff");
const char **includes = malloc(argc * sizeof(*includes));
int nb_includes = 0;
const char *codepage = _T("1252");
const char *language = NULL;
const char **cpp_options = malloc(argc * sizeof(*cpp_options));
int nb_cpp_options = 0;
int verbose = 0;
#define _tcslen_const(a) (sizeof(a)/sizeof(char) - 1)
#define _tcsstart(a, b) !strncmp(a, b, _tcslen_const(b))
#define IF_MATCH_EITHER(short, long) \
if(!strcmp(argv[i], _T(short)) || !strcmp(argv[i], _T(long)))
#define IF_MATCH_THREE(first, second, third) \
if(!strcmp(argv[i], _T(first)) || !strcmp(argv[i], _T(second)) || !strcmp(argv[i], _T(third)))
#define OPTION(short, long, var) \
if(_tcsstart(argv[i], _T(short)) && argv[i][_tcslen_const(_T(short))]) { \
var = argv[i] + _tcslen_const(_T(short)); \
} else if(_tcsstart(argv[i], _T(long "="))) { \
var = strchr(argv[i], '=') + 1; \
} else IF_MATCH_EITHER(short, long) { \
if(i + 1 < argc) \
var = argv[++i]; \
else \
error(basename, _T(TS" missing argument"), argv[i]); \
}
#define SEPARATE_ARG(var) do { \
if(i + 1 < argc) \
var = argv[++i]; \
else \
error(basename, _T(TS" missing argument"), argv[i]); \
} while (0)
#define SEPARATE_ARG_PREFIX(var, prefix) do { \
if(i + 1 < argc) \
var = concat(_T(prefix), argv[++i]); \
else \
error(basename, _T(TS" missing argument"), argv[i]); \
} while (0)
for(int i = 1; i < argc; i++)
{
OPTION("-i", "--input", input)
else OPTION("-o", "--output", output)
else OPTION("-J", "--input-format", input_format)
else OPTION("-O", "--output-format", output_format)
else OPTION("-F", "--target", bfd_target)
else IF_MATCH_THREE("-I", "--include-dir", "--include") {
SEPARATE_ARG(includes[nb_includes++]);
}
else if(_tcsstart(argv[i], _T("--include-dir=")) ||
_tcsstart(argv[i], _T("--include=")))
{
includes[nb_includes++] = strchr(argv[i], '=') + 1;
}
else if(_tcsstart(argv[i], _T("-I")))
{
includes[nb_includes++] = argv[i] + 2;
}
else OPTION("-c", "--codepage", codepage)
else OPTION("-l", "--language", language)
else if(!strcmp(argv[i], _T("--preprocessor")))
{
error(basename, _T("ENOSYS"));
}
else if(_tcsstart(argv[i], _T("--preprocessor-arg=")))
{
cpp_options[nb_cpp_options++] = strchr(argv[i], '=') + 1;
}
else if(!strcmp(argv[i], _T("--preprocessor-arg")))
{
SEPARATE_ARG(cpp_options[nb_cpp_options++]);
}
else IF_MATCH_EITHER("-D", "--define")
{
SEPARATE_ARG_PREFIX(cpp_options[nb_cpp_options++], "-D");
}
else if(_tcsstart(argv[i], _T("-D")))
{
cpp_options[nb_cpp_options++] = argv[i];
}
else IF_MATCH_EITHER("-U", "--undefine")
{
SEPARATE_ARG_PREFIX(cpp_options[nb_cpp_options++], "-U");
}
else if(_tcsstart(argv[i], _T("-U")))
{
cpp_options[nb_cpp_options++] = argv[i];
}
else IF_MATCH_EITHER("-v", "--verbose")
{
verbose = 1;
}
else IF_MATCH_EITHER("-V", "--version")
{
print_version();
}
else IF_MATCH_EITHER("-h", "--help")
{
print_help();
}
else if(!strcmp(argv[i], _T("--use-temp-file")))
{
// No-op, we use a temp file by default.
}
else if(_tcsstart(argv[i], _T("-")))
{
error(basename, _T("unrecognized option: `"TS"'"), argv[i]);
}
else
{
if(!strcmp(input, _T("-")))
{
input = argv[i];
}
else if(!strcmp(output, _T("/dev/stdout")))
{
output = argv[i];
}
else
{
error(basename, _T("rip: `"TS"'"), argv[i]);
}
}
}
if(bfd_target)
{
if(!strcmp(bfd_target, _T("pe-x86-64")) ||
!strcmp(bfd_target, _T("pei-x86-64")))
{
target = _T("x86_64-w64-mingw32");
}
else if(!strcmp(bfd_target, _T("pe-i386")) ||
!strcmp(bfd_target, _T("pei-i386")))
{
target = _T("i686-w64-mingw32");
}
else
{
error(basename, _T("unsupported target: `"TS"'"), bfd_target);
}
}
char *arch = strdup(target);
char *dash = strchr(arch, '-');
if(dash)
{
*dash = '\0';
}
const char *machine = _T("unknown");
if(!strcmp(arch, _T("i686")))
{
machine = _T("X86");
}
else if(!strcmp(arch, _T("x86_64")))
{
machine = _T("X64");
}
else if(!strcmp(arch, _T("armv7")))
{
machine = _T("ARM");
}
else if(!strcmp(arch, _T("aarch64")))
{
machine = _T("ARM64");
}
const char *CC = concat(target, _T("-clang"));
const char **rc_options = malloc(2 * argc * sizeof(*cpp_options));
int nb_rc_options = 0;
for(int i = 0; i < nb_includes; i++)
{
cpp_options[nb_cpp_options++] = concat(_T("-I"), includes[i]);
rc_options[nb_rc_options++] = _T("-I");
rc_options[nb_rc_options++] = includes[i];
}
for(int i = 0; i < nb_cpp_options; i++)
{
cpp_options[i] = unescape_cpp(cpp_options[i]);
}
const char *preproc_rc = concat(output, _T(".preproc.rc"));
const char *res = concat(output, _T(".out.res"));
char *inputdir = strdup(input);
{
char *sep = _tcsrchrs(inputdir, '/', '\\');
if(sep)
{
*sep = '\0';
}
else
{
inputdir = strdup(_T("."));
}
}
int max_arg = 2 * argc + 20;
const char **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv));
int arg = 0;
if(!_tcsicmp(input_format, _T("rc")))
{
exec_argv[arg++] = concat(dir, CC);
exec_argv[arg++] = _T("-E");
for(int i = 0; i < nb_cpp_options; i++)
{
exec_argv[arg++] = cpp_options[i];
}
exec_argv[arg++] = _T("-xc");
exec_argv[arg++] = _T("-DRC_INVOKED=1");
exec_argv[arg++] = input;
exec_argv[arg++] = _T("-o");
exec_argv[arg++] = preproc_rc;
exec_argv[arg] = NULL;
check_num_args(arg, max_arg);
if(verbose)
{
print_argv(exec_argv);
}
int ret = _tspawnvp_escape(_P_WAIT, exec_argv[0], exec_argv);
if(ret == -1)
{
perror(exec_argv[0]);
return 1;
}
if(ret != 0)
{
error(basename, _T("preprocessor failed"));
return ret;
}
arg = 0;
exec_argv[arg++] = concat(dir, _T("llvm-rc"));
for(int i = 0; i < nb_rc_options; i++)
{
exec_argv[arg++] = rc_options[i];
}
exec_argv[arg++] = _T("-I");
exec_argv[arg++] = inputdir;
exec_argv[arg++] = preproc_rc;
exec_argv[arg++] = _T("-c");
exec_argv[arg++] = codepage;
if(language)
{
exec_argv[arg++] = _T("-l");
exec_argv[arg++] = language;
}
exec_argv[arg++] = _T("-fo");
if(!_tcsicmp(output_format, _T("res")))
{
exec_argv[arg++] = output;
}
else
{
exec_argv[arg++] = res;
}
exec_argv[arg] = NULL;
check_num_args(arg, max_arg);
if(verbose)
{
print_argv(exec_argv);
}
ret = _tspawnvp_escape(_P_WAIT, exec_argv[0], exec_argv);
if(ret == -1)
{
perror(exec_argv[0]);
return 1;
}
if(ret != 0)
{
error(basename, _T("llvm-rc failed"));
if(!verbose)
{
unlink(preproc_rc);
}
return ret;
}
if(!_tcsicmp(output_format, _T("res")))
{
// All done
}
else if(!_tcsicmp(output_format, _T("coff")))
{
arg = 0;
exec_argv[arg++] = concat(dir, _T("llvm-cvtres"));
exec_argv[arg++] = res;
exec_argv[arg++] = concat(_T("-machine:"), machine);
exec_argv[arg++] = concat(_T("-out:"), output);
exec_argv[arg] = NULL;
check_num_args(arg, max_arg);
if(verbose)
{
print_argv(exec_argv);
}
int ret = _tspawnvp_escape(_P_WAIT, exec_argv[0], exec_argv);
if(ret == -1)
{
perror(exec_argv[0]);
return 1;
}
if(!verbose)
{
unlink(preproc_rc);
unlink(res);
}
return ret;
} else {
error(basename, _T("invalid output format: `"TS"'"), output_format);
}
}
else if(!_tcsicmp(input_format, _T("res")))
{
exec_argv[arg++] = concat(dir, _T("llvm-cvtres"));
exec_argv[arg++] = input;
exec_argv[arg++] = concat(_T("-machine:"), machine);
exec_argv[arg++] = concat(_T("-out:"), output);
exec_argv[arg] = NULL;
check_num_args(arg, max_arg);
if(verbose)
{
print_argv(exec_argv);
}
int ret = _tspawnvp_escape(_P_WAIT, exec_argv[0], exec_argv);
if(ret == -1)
{
perror(exec_argv[0]);
return 1;
}
return ret;
}
else
{
error(basename, _T("invalid input format: `"TS"'"), input_format);
}
return 0;
}

View File

@ -49,7 +49,6 @@ enum _ARCH
};
typedef int (*PFNOUTLINE)(FILE *, EXPORT *);
int gbMSComp = 0;
int gbImportLib = 0;
int gbNotPrivateNoWarn = 0;
int gbTracing = 0;
@ -531,20 +530,13 @@ PrintName(FILE *fileDest,
pcAt = ScanToken(pcName, '@');
if(pcAt && (pcAt < (pcName + nNameLength)))
{
/* On GCC, we need to remove the leading stdcall underscore */
if(!gbMSComp && (pexp->nCallingConvention == CC_STDCALL))
{
pcName++;
nNameLength--;
}
/* Print the already decorated function name */
fprintf(fileDest, "%.*s", nNameLength, pcName);
}
else
{
/* Print the prefix, but skip it for (GCC && stdcall) */
if(gbMSComp || (pexp->nCallingConvention != CC_STDCALL))
/* Print the prefix, but skip it for stdcall */
if(pexp->nCallingConvention != CC_STDCALL)
{
fprintf(fileDest, "%c", pexp->nCallingConvention == CC_FASTCALL ? '@' : '_');
}
@ -560,10 +552,13 @@ PrintName(FILE *fileDest,
}
}
void
OutputLine_def_MS(FILE *fileDest,
EXPORT *pexp)
int
OutputLine_def(FILE *fileDest,
EXPORT *pexp)
{
DbgPrint("OutputLine_def: '%.*s'...\n", pexp->strName.len, pexp->strName.buf);
fprintf(fileDest, " ");
PrintName(fileDest, pexp, &pexp->strName, 0);
if(gbImportLib)
@ -610,92 +605,6 @@ OutputLine_def_MS(FILE *fileDest,
/* Redirect it to the relay-tracing trampoline */
fprintf(fileDest, "=$relaytrace$%.*s", pexp->strName.len, pexp->strName.buf);
}
}
void
OutputLine_def_GCC(FILE *fileDest,
EXPORT *pexp)
{
int bTracing = 0;
/* Print the function name, with decoration for export libs */
PrintName(fileDest, pexp, &pexp->strName, gbImportLib);
DbgPrint("Generating def line for '%.*s'\n", pexp->strName.len, pexp->strName.buf);
/* Check if this is a forwarded export */
if(pexp->strTarget.buf)
{
int fIsExternal = !!ScanToken(pexp->strTarget.buf, '.');
DbgPrint("Got redirect '%.*s'\n", pexp->strTarget.len, pexp->strTarget.buf);
/* print the target name, don't decorate if it is external */
fprintf(fileDest, "=");
PrintName(fileDest, pexp, &pexp->strTarget, !fIsExternal);
}
else if(((pexp->uFlags & FL_STUB) || (pexp->nCallingConvention == CC_STUB)) &&
(pexp->strName.buf[0] == '?'))
{
/* C++ stubs are forwarded to C stubs */
fprintf(fileDest, "=stub_function%d", pexp->nNumber);
}
else if(gbTracing && ((pexp->uFlags & FL_NORELAY) == 0) &&
(pexp->nCallingConvention == CC_STDCALL) &&
(pexp->strName.buf[0] != '?'))
{
/* Redirect it to the relay-tracing trampoline */
char buf[256];
STRING strTarget;
fprintf(fileDest, "=");
sprintf(buf, "$relaytrace$%.*s", pexp->strName.len, pexp->strName.buf);
strTarget.buf = buf;
strTarget.len = pexp->strName.len + 12;
PrintName(fileDest, pexp, &strTarget, 1);
bTracing = 1;
}
/* Special handling for stdcall and fastcall */
if((giArch == ARCH_X86) &&
((pexp->nCallingConvention == CC_STDCALL) ||
(pexp->nCallingConvention == CC_FASTCALL)))
{
/* Is this the import lib? */
if(gbImportLib)
{
/* Is the name in the spec file decorated? */
const char* pcDeco = ScanToken(pexp->strName.buf, '@');
if(pcDeco &&
(pexp->strName.len > 1) &&
(pcDeco < pexp->strName.buf + pexp->strName.len))
{
/* Write the name including the leading @ */
fprintf(fileDest, "==%.*s", pexp->strName.len, pexp->strName.buf);
}
}
else if((!pexp->strTarget.buf) && !(bTracing))
{
/* Write a forwarder to the actual decorated symbol */
fprintf(fileDest, "=");
PrintName(fileDest, pexp, &pexp->strName, 1);
}
}
}
int
OutputLine_def(FILE *fileDest,
EXPORT *pexp)
{
DbgPrint("OutputLine_def: '%.*s'...\n", pexp->strName.len, pexp->strName.buf);
fprintf(fileDest, " ");
if(gbMSComp)
OutputLine_def_MS(fileDest, pexp);
else
OutputLine_def_GCC(fileDest, pexp);
/* On GCC builds we force ordinals */
if((pexp->uFlags & FL_ORDINAL) || (!gbMSComp && !gbImportLib))
{
fprintf(fileDest, " @%d", pexp->nOrdinal);
}
if(pexp->uFlags & FL_NONAME)
{
@ -1028,10 +937,6 @@ ParseFile(char* pcStart,
else if(CompareToken(pc, "-ordinal"))
{
exp.uFlags |= FL_ORDINAL;
/* GCC doesn't automatically import by ordinal if an ordinal
* is found in the def file. Force it. */
if(gbImportLib && !gbMSComp)
exp.uFlags |= FL_NONAME;
}
else if(CompareToken(pc, "-stub"))
{
@ -1226,41 +1131,6 @@ ParseFile(char* pcStart,
Fatal(pszSourceFileName, nLine, pcLine, pc, 0, "Ordinal export without ordinal");
}
/*
* Check for special handling of OLE exports, only when MSVC
* is not used, since otherwise this is handled by MS LINK.EXE.
*/
if(!gbMSComp)
{
/* Check whether the current export is not PRIVATE, or has an ordinal */
int bIsNotPrivate = (!gbNotPrivateNoWarn && /*gbImportLib &&*/ !(exp.uFlags & FL_PRIVATE));
int bHasOrdinal = (exp.uFlags & FL_ORDINAL);
/* Check whether the current export is an OLE export, in case any of these tests pass */
if(bIsNotPrivate || bHasOrdinal)
{
for(i = 0; i < ARRAYSIZE(astrOlePrivateExports); ++i)
{
if(strlen(astrOlePrivateExports[i]) == exp.strName.len &&
strncmp(exp.strName.buf, astrOlePrivateExports[i], exp.strName.len) == 0)
{
/* The current export is an OLE export: display the corresponding warning */
if(bIsNotPrivate)
{
fprintf(stderr, "WARNING: %s line %d: Exported symbol '%.*s' should be PRIVATE\n",
pszSourceFileName, nLine, exp.strName.len, exp.strName.buf);
}
if(bHasOrdinal)
{
fprintf(stderr, "WARNING: %s line %d: exported symbol '%.*s' should not be assigned an ordinal\n",
pszSourceFileName, nLine, exp.strName.len, exp.strName.buf);
}
break;
}
}
}
}
pexports[*cExports] = exp;
(*cExports)++;
gbDebug = 0;
@ -1329,7 +1199,6 @@ void usage(void)
" -n=<name> name of the dll\n"
" -a=<arch> set architecture to one of: aarch64, armv7, i686, x86_64\n"
" --implib generate a def file for an import library\n"
" --msvc MSVC compatibility\n"
" --no-private-warnings suppress warnings about symbols that should be private\n"
" --with-tracing generate wine-like \"+relay\" trace trampolines (needs -s)\n",
XTCSPECC_VERSION,
@ -1393,10 +1262,6 @@ int main(int argc,
{
gbImportLib = 1;
}
else if(strcasecmp(argv[i], "--msvc") == 0)
{
gbMSComp = 1;
}
else if(strcasecmp(argv[i], "--no-private-warnings") == 0)
{
gbNotPrivateNoWarn = 1;
@ -1516,15 +1381,6 @@ int main(int argc,
return -1;
}
if(!gbMSComp)
{
if(ApplyOrdinals(pexports, cExports) < 0)
{
fprintf(stderr, "error: could not apply ordinals!\n");
return -1;
}
}
if(pszDefFileName)
{
/* Open output file */