9 Commits
1.1 ... 1.2

5 changed files with 170 additions and 7 deletions

View File

@@ -2,10 +2,15 @@
set -e
# Working Directories
SRCDIR="$(pwd)/sources"
BINDIR="$(pwd)/binaries"
PCHDIR="$(pwd)/patches"
SRCDIR="$(pwd)/sources"
WRKDIR="$(pwd)"
# Compiler Flags
CFLAGS="-march=x86-64 -mtune=generic -O2 -s -pipe"
CXXFLAGS="${CFLAGS}"
# Binutils Settings
BINUTILSDIR="${SRCDIR}/binutils"
BINUTILSTAG="binutils-2_35"
@@ -36,9 +41,34 @@ ARCHS="i686 x86_64"
GENERIC="generic-w64-mingw32"
apply_patches()
{
local PACKAGE="${1}"
local VERSION="${2}"
if [ -d "${PCHDIR}/${PACKAGE}/${VERSION}" ]; then
PATCHES="$(find ${PCHDIR}/${PACKAGE}/${VERSION} -name '*.diff' -o -name '*.patch' | sort -n)"
echo ">>> Applying custom patches ..."
for PATCH in ${PATCHES}; do
if [ -f "${PATCH}" ] && [ -r "${PATCH}" ]; then
for PREFIX in {0..5}; do
if patch -i${PATCH} -p${PREFIX} --silent --dry-run >/dev/null; then
patch -i${PATCH} -p${PREFIX} --silent
echo ">>> Patch ${PATCH} applied ..."
break;
elif [ ${PREFIX} -ge 5 ]; then
echo "Patch ${PATCH} does not fit. Failed applying patch ..."
return 1
fi
done
fi
done
fi
}
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}
@@ -50,6 +80,7 @@ binutils_build()
--disable-multilib \
--disable-nls \
--disable-werror \
--enable-gold \
--enable-lto \
--enable-plugins
make -j${CORES}
@@ -61,15 +92,18 @@ binutils_build()
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
}
cmake_build()
{
echo ">>> Building CMAKE ..."
[ -z ${CLEAN} ] || rm -rf ${CMAKEDIR}/build-${GENERIC}
mkdir -p ${CMAKEDIR}/build-${GENERIC}
cd ${CMAKEDIR}/build-${GENERIC}
@@ -85,9 +119,11 @@ cmake_build()
cmake_fetch()
{
if [ ! -d ${CMAKEDIR} ]; then
echo ">>> Downloading CMAKE ..."
git clone ${CMAKEVCS} ${CMAKEDIR}
cd ${CMAKEDIR}
git checkout tags/${CMAKETAG}
apply_patches ${CMAKEDIR##*/} ${CMAKETAG}
cd ${WRKDIR}
fi
}
@@ -95,6 +131,7 @@ cmake_fetch()
gcc_build_phase1()
{
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}
@@ -125,6 +162,7 @@ gcc_build_phase1()
gcc_build_phase2()
{
for ARCH in ${ARCHS}; do
echo ">>> Building GCC (phase2) for ${ARCH} ..."
cd ${GCCDIR}/build-${ARCH}
make -j${CORES}
make install
@@ -135,9 +173,11 @@ gcc_build_phase2()
gcc_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
cd ${WRKDIR}
fi
@@ -146,6 +186,7 @@ gcc_fetch()
mingw_build_crt()
{
for ARCH in ${ARCHS}; do
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}
@@ -174,6 +215,7 @@ mingw_build_crt()
mingw_build_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}
@@ -200,6 +242,7 @@ mingw_build_headers()
mingw_build_libs()
{
for LIB in libmangle 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}
mkdir -p ${MINGWDIR}/mingw-w64-libraries/${LIB}/build-${ARCH}
@@ -222,6 +265,7 @@ mingw_build_tools()
{
for TOOL in gendef genidl genlib 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}
mkdir -p ${MINGWDIR}/mingw-w64-tools/${TOOL}/build-${ARCH}
cd ${MINGWDIR}/mingw-w64-tools/${TOOL}/build-${ARCH}
@@ -241,15 +285,18 @@ mingw_build_tools()
mingw_fetch()
{
if [ ! -d ${MINGWDIR} ]; then
echo ">>> Downloading Mingw-w64 ..."
git clone ${MINGWVCS} ${MINGWDIR}
cd ${MINGWDIR}
git checkout tags/${MINGWTAG}
apply_patches ${MINGWDIR##*/} ${MINGWTAG}
cd ${WRKDIR}
fi
}
ninja_build()
{
echo ">>> Building NINJA ..."
[ -z ${CLEAN} ] || rm -rf ${NINJADIR}/build-${GENERIC}
mkdir -p ${NINJADIR}/build-${GENERIC}
cd ${NINJADIR}/build-${GENERIC}
@@ -261,9 +308,11 @@ ninja_build()
ninja_fetch()
{
if [ ! -d ${NINJADIR} ]; then
echo ">>> Downloading NINJA ..."
git clone ${NINJAVCS} ${NINJADIR}
cd ${NINJADIR}
git checkout tags/${NINJATAG}
apply_patches ${NINJADIR##*/} ${NINJATAG}
cd ${WRKDIR}
fi
}
@@ -283,6 +332,10 @@ fi
mkdir -p ${BINDIR}
mkdir -p ${SRCDIR}
# Export compiler flags
export CFLAGS
export CXXFLAGS
# Download Mingw-W64
mingw_fetch
@@ -326,11 +379,11 @@ ninja_fetch
ninja_build
# Remove unneeded files to save disk space
echo "Removing 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}}
# Copy all scripts
echo "Copying scripts..."
echo ">>> Copying scripts ..."
cp -apf ${WRKDIR}/scripts/* ${BINDIR}/
# Save FBE version
@@ -340,5 +393,5 @@ cd ${WRKDIR}
echo "${FBEVER}" > ${BINDIR}/Version
# Prepare archive
echo "Creating toolchain archive..."
tar -I 'zstd -19' -cf fbe-${FBEVER}-linux.tar.zst -C ${BINDIR} .
echo ">>> Creating toolchain archive ..."
tar -I 'zstd -19' -cpf fbe-${FBEVER}-linux.tar.zst -C ${BINDIR} .

View File

@@ -0,0 +1,36 @@
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,57 @@
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;

11
readme.md Normal file
View File

@@ -0,0 +1,11 @@
## FerretOS Build Environment (FBE)
The FerretOS Build Environment (FBE) is the official build environment for compiling FerretOS.
Currently, it is targeted at Linux only, however a Windows and FerretOS versions will be available
in the future as well.
This software includes:
* Binutils
* GCC
* Mingw-w64
* CMake
* Ninja

View File

@@ -34,5 +34,11 @@ export PATH="${FBEDIR}/bin:${PATH}"
# Display banner
version
# Invoke shell
bash --rcfile <(echo 'cd ${SRCDIR}')
# Invoke shell with fancy prompt
export PFMAT1="\[\033[0;1;97;44m\]"
export PFMAT2="\[\033[0;34;104m\]"
export PFMAT3="\[\033[0;1;97;104m\]"
export PFMAT4="\[\033[0;94;49m\]"
export PFMAT5="\[\033[1;38;5;74m\]"
export PROMPT="\n${PFMAT1} FerretOS BE ${PFMAT2}${PFMAT3} \w ${PFMAT4}${PFMAT5} "
bash --rcfile <(echo 'source ~/.bashrc && export PS1="${PROMPT}" && cd ${SRCDIR}')