chore: Fix build process

This commit is contained in:
EnderIce2
2024-11-26 03:27:08 +02:00
parent ce4ebaf6c5
commit 00a37325f6
18 changed files with 392 additions and 781 deletions

View File

@ -4,79 +4,133 @@ export PATH := $(CROSS_DIR):$(PATH)
QEMU_VERSION = 8.1.2
all: do_rep do_ep do_limine clone_all do_binutils_64 do_gcc_64 do_binutils_32 do_gcc_32 do_qemu
all: do_tools do_limine __clone_all do_binutils_64 do_gcc_64 do_binutils_32 do_gcc_32 do_qemu
clean:
rm -f rep ep fex
rm -f rep ep
do_rep:
do_tools:
gcc -w ReadEthernetPackets.c -o rep
chmod +x rep
do_ep:
g++ -w ErrorParser.cpp -o ep
chmod +x rep
chmod +x ep
do_limine:
git clone https://github.com/limine-bootloader/limine.git --branch=v6.x-branch-binary --depth=1
ifeq ("$(wildcard ./limine)", "")
git clone https://github.com/limine-bootloader/limine.git --branch=v6.x-branch-binary --depth=1 limine
else
$(info > TOOLS: Skipping cloning limine because directory already exists.)
endif
__clone_qemu:
ifeq ("$(wildcard ./qemu)", "")
wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz
tar xvJf qemu-${QEMU_VERSION}.tar.xz
rm -f qemu-${QEMU_VERSION}.tar.xz
mv qemu-${QEMU_VERSION} qemu
else
$(info > TOOLS: Skipping cloning qemu because directory already exists.)
endif
__clone_all_no_qemu:
git clone -b binutils-2_42-branch --single-branch https://github.com/Fennix-Project/binutils-gdb.git binutils-gdb
git clone -b releases/gcc-13 --single-branch https://github.com/Fennix-Project/gcc.git gcc
cd gcc && $(shell ./contrib/download_prerequisites)
.PHONY: all clean __clone_binutils __clone_gcc __prep_cross __patch_cross __patch_cross_binutils __patch_cross_gcc
__clone_binutils:
ifeq ("$(wildcard ./binutils-gdb)", "")
git clone --depth 1 -b binutils-2_43_1 --single-branch git://sourceware.org/git/binutils-gdb.git binutils-gdb
else
$(info > TOOLS: Reseting binutils-gdb...)
cd binutils-gdb && \
git fetch origin && \
git reset --hard binutils-2_43_1 && \
git clean -dfx
$(info > TOOLS: Operation completed for binutils-gdb)
endif
__clone_gcc:
ifeq ("$(wildcard ./gcc)", "")
git clone --depth 1 -b releases/gcc-14.2.0 --single-branch git://gcc.gnu.org/git/gcc.git gcc
else
$(info > TOOLS: Reseting gcc...)
cd gcc && \
git fetch origin && \
git reset --hard releases/gcc-14.2.0 && \
git clean -dfx
$(info > TOOLS: Operation completed for gcc)
endif
__patch_cross_binutils: __clone_binutils
$(info > TOOLS: Patching binutils-gcc)
cd binutils-gdb && git apply ../binutils-gdb.patch
$(info > TOOLS: Running automake for binutils-gdb/ld)
cd binutils-gdb/ld && automake
__patch_cross_gcc: __clone_gcc
$(info > TOOLS: Patching gcc)
cd gcc && git apply ../gcc.patch
cd gcc && ./contrib/download_prerequisites
$(info > TOOLS: Running autoconf for gcc/libstdc++-v3)
cd gcc/libstdc++-v3 && autoconf
__patch_cross: __patch_cross_binutils __patch_cross_gcc
__prep_cross:
mkdir -p cross
mkdir -p build-binutils64
mkdir -p build-gcc64
mkdir -p build-binutils32
mkdir -p build-gcc32
mkdir -p binutils-gdb/__build
mkdir -p gcc/__build
clone_all: __clone_qemu __clone_all_no_qemu
__clone_all_no_qemu: __clone_binutils __clone_gcc
do_qemu:
__clone_all: __clone_qemu __clone_all_no_qemu
do_qemu: __prep_cross
cd qemu && \
bash ./configure --target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu \
--prefix="$(CROSS_DIR)" \
--enable-gtk --disable-tools \
--disable-gio --disable-virtfs --disable-vnc \
--disable-opengl && \
make -j$(shell nproc) && make install
make --quiet -j$(shell nproc) && make --quiet install
do_binutils_64:
cd build-binutils64 && \
../binutils-gdb/configure --target=x86_64-fennix \
--prefix="$(CROSS_DIR)" --disable-nls \
$(MAKE) __patch_cross_binutils
$(MAKE) __prep_cross
cd binutils-gdb/__build && \
../configure --target=x86_64-fennix \
--prefix="$(CROSS_DIR)" --disable-nls --quiet \
--with-sysroot --enable-shared --disable-werror && \
make all -j$(shell nproc) && make install
make --quiet all -j$(shell nproc) && \
make --quiet install
do_gcc_64:
cd build-gcc64 && \
../gcc/configure --target=x86_64-fennix \
$(MAKE) __patch_cross_gcc
$(MAKE) __prep_cross
cd gcc/__build && \
../configure --target=x86_64-fennix --quiet \
--prefix="$(CROSS_DIR)" --disable-nls --enable-default-pie \
--enable-languages=c,c++ --enable-shared --without-headers && \
make all-gcc -j$(shell nproc) && \
make all-target-libgcc -j$(shell nproc) && \
make install-gcc -j$(shell nproc) && \
make install-target-libgcc -j$(shell nproc)
make --quiet all-gcc -j$(shell nproc) && \
make --quiet all-target-libgcc -j$(shell nproc) && \
make --quiet install-gcc -j$(shell nproc) && \
make --quiet install-target-libgcc -j$(shell nproc)
do_binutils_32:
cd build-binutils32 && \
../binutils-gdb/configure --target=i386-fennix \
--prefix="$(CROSS_DIR)" --disable-nls \
$(MAKE) __patch_cross_binutils
$(MAKE) __prep_cross
cd binutils-gdb/__build && \
../configure --target=i386-fennix \
--prefix="$(CROSS_DIR)" --disable-nls --quiet \
--with-sysroot --enable-shared --disable-werror && \
make all -j$(shell nproc) && make install
make --quiet all -j$(shell nproc) && \
make --quiet install
do_gcc_32:
cd build-gcc32 && \
../gcc/configure --target=i386-fennix \
$(MAKE) __patch_cross_gcc
$(MAKE) __prep_cross
cd gcc/__build && \
../configure --target=i386-fennix --quiet \
--prefix="$(CROSS_DIR)" --disable-nls --enable-default-pie \
--enable-languages=c,c++ --enable-shared --without-headers && \
make all-gcc -j$(shell nproc) && \
make all-target-libgcc -j$(shell nproc) && \
make install-gcc -j$(shell nproc) && \
make install-target-libgcc -j$(shell nproc)
make --quiet all-gcc -j$(shell nproc) && \
make --quiet all-target-libgcc -j$(shell nproc) && \
make --quiet install-gcc -j$(shell nproc) && \
make --quiet install-target-libgcc -j$(shell nproc)

127
tools/binutils-gdb.patch Normal file
View File

@ -0,0 +1,127 @@
diff --git a/bfd/config.bfd b/bfd/config.bfd
index 6553aac1e99..40429e9bf43 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -1502,6 +1502,20 @@ case "${targ}" in
;;
#endif
+ i[3-7]86-*-fennix*)
+ targ_defvec=i386_elf32_vec
+ targ_selvecs=
+ targ64_selvecs=x86_64_elf64_vec
+ ;;
+
+#ifdef BFD64
+ x86_64-*-fennix*)
+ targ_defvec=x86_64_elf64_vec
+ targ_selvecs=i386_elf32_vec
+ want64=true
+ ;;
+#endif
+
# END OF targmatch.h
bpf-*-*)
echo "*** Configuration $targ is not fully supported." >&2
diff --git a/config.sub b/config.sub
index 2c6a07ab3c3..d279b50dc8b 100755
--- a/config.sub
+++ b/config.sub
@@ -1768,7 +1768,7 @@ case $os in
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* | mlibc* | cos* | mbr* | ironclad* )
+ | fiwix* | mlibc* | cos* | mbr* | ironclad* | fennix* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff --git a/gas/configure.tgt b/gas/configure.tgt
index d58f21873a3..fa4215b9cff 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -267,6 +267,7 @@ case ${generic_target} in
i386-*-*nt*) fmt=coff em=pe ;;
i386-*-rdos*) fmt=elf ;;
i386-*-darwin*) fmt=macho ;;
+ i386-*-fennix*) fmt=elf em=gnu ;;
ia16-*-elf*) fmt=elf ;;
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 6a9833e5775..fb4f866ef55 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -279,6 +279,7 @@ ALL_EMULATION_SOURCES = \
eelf_i386.c \
eelf_i386_be.c \
eelf_i386_fbsd.c \
+ eelf_i386_fennix.c \
eelf_i386_haiku.c \
eelf_i386_ldso.c \
eelf_i386_sol2.c \
@@ -463,6 +464,7 @@ ALL_64_EMULATION_SOURCES = \
eelf_x86_64.c \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
+ eelf_x86_64_fennix.c \
eelf_x86_64_haiku.c \
eelf_x86_64_sol2.c \
ehppa64linux.c \
diff --git a/ld/configure.tgt b/ld/configure.tgt
index f937f78b876..ea5491a1447 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -409,6 +409,11 @@ i[3-7]86-*-elf* | i[3-7]86-*-rtems* | i[3-7]86-*-genode*)
i[3-7]86-*-dragonfly*) targ_emul=elf_i386
targ_extra_emuls="elf_iamcu i386bsd"
;;
+i[3-7]86-*-fennix*)
+ targ_emul=elf_i386_fennix
+ targ_extra_emuls=elf_i386
+ targ64_extra_emuls="elf_x86_64_fennix elf_x86_64"
+ ;;
i[3-7]86-*-freebsd* | i[3-7]86-*-kfreebsd*-gnu)
targ_emul=elf_i386_fbsd
targ_extra_emuls="elf_i386 elf_iamcu i386bsd"
@@ -1045,6 +1050,9 @@ x86_64-*-elf* | x86_64-*-rtems* | x86_64-*-fuchsia* | x86_64-*-genode*)
x86_64-*-dragonfly*) targ_emul=elf_x86_64
targ_extra_emuls="elf_i386 elf_iamcu"
;;
+x86_64-*-fennix*) targ_emul=elf_x86_64_fennix
+ targ_extra_emuls="elf_i386_fennix elf_x86_64 elf_i386"
+ ;;
x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
targ_emul=elf_x86_64_fbsd
targ_extra_emuls="elf_i386_fbsd elf_x86_64 elf_i386 elf_iamcu"
@@ -1112,6 +1120,10 @@ case "${target}" in
NATIVE_LIB_DIRS='/lib /usr/lib /usr/pkg/lib /usr/local/lib'
;;
+*-*-fennix*)
+ NATIVE_LIB_DIRS='/lib /usr/lib'
+ ;;
+
*-*-freebsd*)
NATIVE_LIB_DIRS='/lib /usr/lib /usr/local/lib'
;;
diff --git a/ld/emulparams/elf_i386_fennix.sh b/ld/emulparams/elf_i386_fennix.sh
new file mode 100644
index 00000000000..19b75a06cf9
--- /dev/null
+++ b/ld/emulparams/elf_i386_fennix.sh
@@ -0,0 +1,4 @@
+source_sh ${srcdir}/emulparams/elf_i386.sh
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
+TEXT_START_ADDR=0x400000
diff --git a/ld/emulparams/elf_x86_64_fennix.sh b/ld/emulparams/elf_x86_64_fennix.sh
new file mode 100644
index 00000000000..1509ec7fe53
--- /dev/null
+++ b/ld/emulparams/elf_x86_64_fennix.sh
@@ -0,0 +1,4 @@
+source_sh ${srcdir}/emulparams/elf_x86_64.sh
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
+TEXT_START_ADDR=0x400000

157
tools/gcc.patch Normal file
View File

@ -0,0 +1,157 @@
diff --git a/config.sub b/config.sub
index 38f3d037a78..e15a98ae991 100755
--- a/config.sub
+++ b/config.sub
@@ -1749,7 +1749,7 @@ case $os in
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | fennix* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 95c91ee02be..2f3e3b006dd 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -825,6 +825,14 @@ case ${target} in
rust_target_objs="${rust_target_objs} dragonfly-rust.o"
target_has_targetrustm=yes
;;
+*-*-fennix*)
+ tmake_file="t-fennix "
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ use_gcc_stdint=provide
+ native_system_header_dir=/include
+ ;;
*-*-freebsd*)
# This is the generic ELF configuration of FreeBSD. Later
# machine-specific sections may refine and add to this
@@ -1981,6 +1989,14 @@ x86_64-*-openbsd*)
gas=yes
gnu_ld=yes
;;
+i[34567]86-*-fennix*)
+ tmake_file="${tmake_file} i386/t-fennix"
+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h glibc-stdint.h i386/i386elf.h fennix.h"
+ ;;
+x86_64-*-fennix*)
+ tmake_file="${tmake_file} i386/t-fennix"
+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h fennix.h"
+ ;;
i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
# Intel 80386's running GNU/*
# with ELF format using glibc 2
diff --git a/gcc/config/fennix.h b/gcc/config/fennix.h
new file mode 100644
index 00000000000..3739abe7983
--- /dev/null
+++ b/gcc/config/fennix.h
@@ -0,0 +1,59 @@
+
+#undef TARGET_FENNIX
+#define TARGET_FENNIX 1
+
+#undef LIB_SPEC
+#define LIB_SPEC "-lc"
+
+#undef CPP_SPEC
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_POSIX_THREADS}"
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC \
+ "crti.o%s \
+ %{!shared: \
+ %{!static: \
+ crtbeginS.o%s Scrt1.o%s \
+ } \
+ } \
+ %{static:crtbegin.o%s crt1.o%s}"
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC \
+ "crtn.o%s \
+ %{!shared: \
+ %{!static: \
+ crtendS.o%s \
+ } \
+ } \
+ %{static:crtend.o%s}"
+
+#undef STANDARD_STARTFILE_PREFIX
+#define STANDARD_STARTFILE_PREFIX "/lib/"
+
+#undef LINK_SPEC
+#define LINK_SPEC \
+ "%{shared:-shared} \
+ %{static:-static} \
+ %{!shared: \
+ %{!static: \
+ %{rdynamic:-export-dynamic} \
+ } \
+ } \
+ %{!static: \
+ %{!dynamic-linker: \
+ -dynamic-linker=/lib/ld.so \
+ } \
+ } \
+ -z max-page-size=4096"
+
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
+ do \
+ { \
+ builtin_define("__fennix__"); \
+ builtin_define("__unix__"); \
+ builtin_assert("system=fennix"); \
+ builtin_assert("system=unix"); \
+ builtin_assert("system=posix"); \
+ } while (0);
diff --git a/gcc/config/i386/t-fennix b/gcc/config/i386/t-fennix
new file mode 100644
index 00000000000..8223e63c0c9
--- /dev/null
+++ b/gcc/config/i386/t-fennix
@@ -0,0 +1,2 @@
+MULTILIB_OPTIONS += mno-red-zone
+MULTILIB_DIRNAMES += no-red-zone
diff --git a/libgcc/config.host b/libgcc/config.host
index e75a7af647f..12ecba7be60 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -760,6 +760,14 @@ x86_64-*-dragonfly*)
tmake_file="${tmake_file} i386/t-dragonfly i386/t-crtstuff"
md_unwind_header=i386/dragonfly-unwind.h
;;
+i[34567]86-*-fennix*)
+ extra_parts="$extra_parts crti.o crtn.o crtbegin.o crtend.o crtbeginS.o crtendS.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ ;;
+x86_64-*-fennix*)
+ extra_parts="$extra_parts crti.o crtn.o crtbegin.o crtend.o crtbeginS.o crtendS.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ ;;
i[34567]86-*-freebsd*)
tmake_file="${tmake_file} i386/t-freebsd i386/t-crtstuff"
md_unwind_header=i386/freebsd-unwind.h
diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4
index b3269cb88e0..de1f886b9a6 100644
--- a/libstdc++-v3/crossconfig.m4
+++ b/libstdc++-v3/crossconfig.m4
@@ -88,6 +88,13 @@ case "${host}" in
AC_DEFINE(HAVE_HYPOT)
;;
+ *-fennix*)
+ GLIBCXX_CHECK_COMPILER_FEATURES
+ GLIBCXX_CHECK_LINKER_FEATURES
+ GLIBCXX_CHECK_MATH_SUPPORT
+ GLIBCXX_CHECK_STDLIB_SUPPORT
+ ;;
+
*-freebsd*)
SECTION_FLAGS='-ffunction-sections -fdata-sections'
AC_SUBST(SECTION_FLAGS)