| 1 |
# Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 2 |
# |
| 3 |
# This file is part of GCC. |
| 4 |
# |
| 5 |
# GCC is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3, or (at your option) |
| 8 |
# any later version. |
| 9 |
# |
| 10 |
# GCC is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with GCC; see the file COPYING3. If not see |
| 17 |
# <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
# |
| 20 |
# For mingw Windows hosts, embed a manifest that sets the active |
| 21 |
# code page of the driver and compiler proper processes to utf8. |
| 22 |
# This only has an effect when gcc is hosted on Windows version |
| 23 |
# 1903 (May 2019 Update) or later. |
| 24 |
|
| 25 |
# The resource .rc file references the utf8 .manifest file. |
| 26 |
# Compile it into an object file using windres. |
| 27 |
# The resulting .o file gets added to host_extra_gcc_objs in |
| 28 |
# config.host for mingw hosts and gets linked into |
| 29 |
# the driver as a .o file, so it's lack of symbols is OK. |
| 30 |
utf8rc-mingw32.o : $(srcdir)/config/i386/utf8-mingw32.rc \ |
| 31 |
$(srcdir)/config/i386/winnt-utf8.manifest |
| 32 |
$(WINDRES) $< $@ |
| 33 |
|
| 34 |
# Create an object file that just exports the global symbol |
| 35 |
# HOST_EXTRA_OBJS_SYMBOL |
| 36 |
sym-mingw32.o : $(srcdir)/config/i386/sym-mingw32.cc |
| 37 |
$(COMPILER) -c $< |
| 38 |
|
| 39 |
# Combine the two object files into one which has both the |
| 40 |
# compiled utf8 resource and the HOST_EXTRA_OBJS_SYMBOL symbol. |
| 41 |
# The resulting .o file gets added to host_extra_objs in |
| 42 |
# config.host for mingw hosts and gets archived into |
| 43 |
# libbackend.a which gets linked into the compiler proper. |
| 44 |
# If nothing references it into libbackend.a, it will not |
| 45 |
# get linked into the compiler proper eventually. |
| 46 |
# Therefore we need to request the symbol at compiler link time. |
| 47 |
# -nostdlib is required for supporting old gcc versions that |
| 48 |
# don't apply it automatically with -r. |
| 49 |
utf8-mingw32.o : utf8rc-mingw32.o sym-mingw32.o |
| 50 |
$(COMPILER) -r -nostdlib utf8rc-mingw32.o sym-mingw32.o -o $@ |
| 51 |
|
| 52 |
# Force compilers to link against the utf8 resource by |
| 53 |
# requiring the symbol to be defined. |
| 54 |
# Otherwise the object file won't get linked in the compilers |
| 55 |
# because nothing is referencing it in libbackend.a |
| 56 |
# This is expected because the resource object is not supposed |
| 57 |
# to have any symbols, it just has to be linked into the |
| 58 |
# executable in order for Windows to use the utf8 code page. |
| 59 |
# Some build environments are passing these flags to other |
| 60 |
# programs as well, so make the symbol definition optional |
| 61 |
# such that these programs don't fail to build when they |
| 62 |
# don't find it. |
| 63 |
$(COMPILERS) : override LDFLAGS += -Wl,--undefined=HOST_EXTRA_OBJS_SYMBOL |