Hi,
This patch adds necessary backend support for MinGW/Cygwin targets so
that all relevant predefined version conditions are available, a
prerequesite for building most parts of libphobos.
Tested gdc by building x86_64-pc-mingw64 as a cross compiler, before I
commit it to mainline, is there anything glaringly missing in the
configure file changes?
Regards
Iain
---
gcc/ChangeLog:
PR d/91595
* config.gcc (*-*-cygwin*): Add winnt-d.o
(*-*-mingw*): Likewise.
* config/i386/cygwin.h (EXTRA_TARGET_D_OS_VERSIONS): New macro.
* config/i386/mingw32.h (EXTRA_TARGET_D_OS_VERSIONS): Likewise.
* config/t-winnt: Add winnt-d.o.
* config/winnt-d.c: New file.
---
gcc/config.gcc | 6 ++++++
gcc/config/i386/cygwin.h | 8 ++++++++
gcc/config/i386/mingw32.h | 11 ++++++++++
gcc/config/t-winnt | 4 ++++
gcc/config/winnt-d.c | 43 +++++++++++++++++++++++++++++++++++++++
5 files changed, 72 insertions(+)
create mode 100644 gcc/config/winnt-d.c
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 9cecc140c83..b3b84374fd0 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2121,6 +2121,8 @@ i[34567]86-*-cygwin*)
extra_objs="${extra_objs} winnt.o winnt-stubs.o"
c_target_objs="${c_target_objs} msformat-c.o"
cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
+ d_target_objs="${d_target_objs} winnt-d.o"
+ target_has_targetdm="yes"
if test x$enable_threads = xyes; then
thread_file='posix'
fi
@@ -2137,6 +2139,8 @@ x86_64-*-cygwin*)
extra_objs="${extra_objs} winnt.o winnt-stubs.o"
c_target_objs="${c_target_objs} msformat-c.o"
cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
+ d_target_objs="${d_target_objs} winnt-d.o"
+ target_has_targetdm="yes"
if test x$enable_threads = xyes; then
thread_file='posix'
fi
@@ -2149,7 +2153,9 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
xm_file=i386/xm-mingw32.h
c_target_objs="${c_target_objs} winnt-c.o"
cxx_target_objs="${cxx_target_objs} winnt-c.o"
+ d_target_objs="${d_target_objs} winnt-d.o"
target_has_targetcm="yes"
+ target_has_targetdm="yes"
case ${target} in
x86_64-*-* | *-w64-*)
need_64bit_isa=yes
diff --git a/gcc/config/i386/cygwin.h b/gcc/config/i386/cygwin.h
index db0a3cc0b35..f28c6974cdc 100644
--- a/gcc/config/i386/cygwin.h
+++ b/gcc/config/i386/cygwin.h
@@ -29,6 +29,14 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#define EXTRA_TARGET_D_OS_VERSIONS() \
+ do \
+ { \
+ builtin_version ("Cygwin"); \
+ builtin_version ("Posix"); \
+ } \
+ while (0)
+
#undef CPP_SPEC
#define CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} \
%{!ansi:-Dunix} \
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index 1a6a3a07ca6..0589d39230d 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -53,6 +53,17 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#define EXTRA_TARGET_D_OS_VERSIONS() \
+ do \
+ { \
+ builtin_version ("MinGW"); \
+ if (TARGET_64BIT && ix86_abi == MS_ABI) \
+ builtin_version ("Win64"); \
+ else if (!TARGET_64BIT) \
+ builtin_version ("Win32"); \
+ } \
+ while (0)
+
#ifndef TARGET_USE_PTHREAD_BY_DEFAULT
#define SPEC_PTHREAD1 "pthread"
#define SPEC_PTHREAD2 "!no-pthread"
diff --git a/gcc/config/t-winnt b/gcc/config/t-winnt
index 9587f66b3db..00bd3c348b4 100644
--- a/gcc/config/t-winnt
+++ b/gcc/config/t-winnt
@@ -20,3 +20,7 @@ winnt-c.o: config/winnt-c.c $(CONFIG_H) $(SYSTEM_H)
coretypes.h \
$(C_TARGET_H) $(C_TARGET_DEF_H)
$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \
$< $(OUTPUT_OPTION)
+
+winnt-d.o: config/winnt-d.c
+ $(COMPILE) $<
+ $(POSTCOMPILE)
diff --git a/gcc/config/winnt-d.c b/gcc/config/winnt-d.c
new file mode 100644
index 00000000000..f3a36c28293
--- /dev/null
+++ b/gcc/config/winnt-d.c
@@ -0,0 +1,43 @@
+/* Windows support needed only by D front-end.
+ Copyright (C) 2021 Free Software Foundation, Inc.
+
+GCC 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; either version 3, or (at your option) any later
+version.
+
+GCC 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 GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "target.h"
+#include "d/d-target.h"
+#include "d/d-target-def.h"
+#include "tm_p.h"
+
+/* Implement TARGET_D_OS_VERSIONS for Windows targets. */
+
+static void
+winnt_d_os_builtins (void)
+{
+ d_add_builtin_version ("Windows");
+
+#define builtin_version(TXT) d_add_builtin_version (TXT)
+
+#ifdef EXTRA_TARGET_D_OS_VERSIONS
+ EXTRA_TARGET_D_OS_VERSIONS ();
+#endif
+}
+
+#undef TARGET_D_OS_VERSIONS
+#define TARGET_D_OS_VERSIONS winnt_d_os_builtins
+
+struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
--
2.27.0