From 545076c6df89e02100da80b0f91dbe07bc2a88bd Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Tue, 1 Sep 2020 13:05:39 +0200 Subject: [PATCH] gcc: introduce `--posixly` command line option to ease the compilation of POSIX software --- cross/patch/gcc.patch | 5 +- cross/patch/gcc/gcc/config/jehanne.h | 73 ++++++++++++++++++++++++-- cross/patch/gcc/gcc/config/jehanne.opt | 25 +++++++++ 3 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 cross/patch/gcc/gcc/config/jehanne.opt diff --git a/cross/patch/gcc.patch b/cross/patch/gcc.patch index 1c53d6d..bc4239d 100644 --- a/cross/patch/gcc.patch +++ b/cross/patch/gcc.patch @@ -2,7 +2,7 @@ diff --git a/src/gcc/gcc/config.gcc b/src/gcc/gcc/config.gcc index ddd3b8f..702aa59 100644 --- a/src/gcc/gcc/config.gcc +++ b/src/gcc/gcc/config.gcc -@@ -947,6 +947,16 @@ case ${target} in +@@ -947,6 +947,18 @@ case ${target} in tmake_file="$tmake_file vms/t-vmsnative" fi ;; @@ -10,6 +10,7 @@ index ddd3b8f..702aa59 100644 + gas=yes + gnu_ld=yes + default_use_cxa_atexit=yes ++ extra_options="$extra_options jehanne.opt" + case $target in + x86_64-*) + native_system_header_dir="/arch/amd64/include" @@ -19,7 +20,7 @@ index ddd3b8f..702aa59 100644 *-*-vxworks*) tmake_file=t-vxworks xm_defines=POSIX -@@ -1635,6 +1647,9 @@ i[34567]86-*-elfiamcu) +@@ -1635,6 +1648,9 @@ i[34567]86-*-elfiamcu) i[34567]86-*-elf*) tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h" ;; diff --git a/cross/patch/gcc/gcc/config/jehanne.h b/cross/patch/gcc/gcc/config/jehanne.h index e760c28..afa2597 100644 --- a/cross/patch/gcc/gcc/config/jehanne.h +++ b/cross/patch/gcc/gcc/config/jehanne.h @@ -18,16 +18,30 @@ #undef TARGET_JEHANNE #define TARGET_JEHANNE 1 +/* +#undef DRIVER_SELF_SPECS +#define DRIVER_SELF_SPECS "%{-posixly}" +*/ + +/* GCC on Jehanne includes and link libraries from /sys and /arch. + * To ease the port of POSIX applications, we include a --posixly option + * to the GCC driver that will be substituted with proper options + */ +#undef CPP_SPEC +#define CPP_SPEC "%{-posixly:-isystem/posix/include}" + +#undef LINK_SPEC +#define LINK_SPEC "%{-posixly:-L/posix/lib}" -/* Default arguments you want when running x86_64-jehanne-gcc */ #undef LIB_SPEC -#define LIB_SPEC "-ljehanne" +#define LIB_SPEC "%{-posixly:%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}} -ljehanne" + #undef STANDARD_STARTFILE_PREFIX #define STANDARD_STARTFILE_PREFIX "/arch/amd64/lib/" -#undef MD_STARTFILE_PREFIX -#define MD_STARTFILE_PREFIX "/arch/amd64/lib/" +/* GCC include paths definition START + */ /* Architecture specific header (u.h) goes here (from config.gcc) */ #define ARCH_INCLUDE_DIR NATIVE_SYSTEM_HEADER_DIR @@ -35,14 +49,65 @@ /* The default include dir is /sys/include */ #define PORTABLE_INCLUDE_DIR "/sys/include" +#ifdef GPLUSPLUS_INCLUDE_DIR + /* Pick up GNU C++ generic include files. */ +# define ID_GPLUSPLUS { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, +#else +# define ID_GPLUSPLUS +#endif +#ifdef GPLUSPLUS_TOOL_INCLUDE_DIR + /* Pick up GNU C++ target-dependent include files. */ +# define ID_GPLUSPLUS_TOOL { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, +#else +# define ID_GPLUSPLUS_TOOL +#endif +#ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR + /* Pick up GNU C++ backward and deprecated include files. */ +# define ID_GPLUSPLUS_BACKWARD { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, +#else +# define ID_GPLUSPLUS_BACKWARD +#endif +#ifdef GCC_INCLUDE_DIR + /* This is the dir for gcc's private headers. */ +# define ID_GCC { GCC_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, +#else +# define ID_GCC +#endif +#ifdef PREFIX_INCLUDE_DIR +# define ID_PREFIX { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0 }, +#else +# define ID_PREFIX +#endif +#if defined (CROSS_INCLUDE_DIR) && defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT) +# define ID_CROSS { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, +#else +# define ID_CROSS +#endif +#ifdef TOOL_INCLUDE_DIR + /* Another place the target system's headers might be. */ +# define ID_TOOL { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0 }, +#else +# define ID_TOOL +#endif + #undef INCLUDE_DEFAULTS #define INCLUDE_DEFAULTS \ { \ + ID_GPLUSPLUS \ + ID_GPLUSPLUS_TOOL \ + ID_GPLUSPLUS_BACKWARD \ + ID_GCC \ + ID_PREFIX \ + ID_CROSS \ + ID_TOOL \ { PORTABLE_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ { ARCH_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ { 0, 0, 0, 0, 0, 0 } \ } +/* GCC include paths definition END + */ + /* Files that are linked before user code. The %s tells gcc to look for these files in the library directory. */ #undef STARTFILE_SPEC diff --git a/cross/patch/gcc/gcc/config/jehanne.opt b/cross/patch/gcc/gcc/config/jehanne.opt new file mode 100644 index 0000000..50a8c80 --- /dev/null +++ b/cross/patch/gcc/gcc/config/jehanne.opt @@ -0,0 +1,25 @@ +; Jehanne options. + +; This file is part of Jehanne. +; +; Copyright (C) 2016-2020 Giacomo Tesio +; +; Jehanne is free software: you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, version 2 of the License. +; +; Jehanne is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with Jehanne. If not, see . + +; Please try to keep this file in ASCII collating order. + +-posixly +C ObjC C++ ObjC++ Driver RejectNegative +Lookup for POSIX includes and libraries in /posix + +; This comment is to ensure we retain the blank line above.