commit:     675421df42f5689e496af2b54dd2b20c2804af3a
Author:     Horodniceanu Andrei <a.horodniceanu <AT> protonmail <DOT> com>
AuthorDate: Fri Jul 22 11:20:23 2022 +0000
Commit:     Marco Leise <marco.leise <AT> gmx <DOT> de>
CommitDate: Fri Jul 22 11:20:23 2022 +0000
URL:        https://gitweb.gentoo.org/repo/user/dlang.git/commit/?id=675421df

Improve dmd.eclass support for gdc

Signed-off-by: Horodniceanu Andrei <a.horodniceanu <AT> protonmail.com>

 eclass/dlang.eclass | 31 +++++++++++++++++++++++++++++++
 eclass/dmd.eclass   |  6 ++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/eclass/dlang.eclass b/eclass/dlang.eclass
index 80dea3a..5c86088 100644
--- a/eclass/dlang.eclass
+++ b/eclass/dlang.eclass
@@ -234,6 +234,37 @@ dlang_convert_ldflags() {
        fi
 }
 
+# @FUNCTION: dlang_dmdw_dcflags
+# @DESCRIPTION:
+# Convertes compiler specific $DCFLAGS to something that can be passed to the
+# dmd wrapper of said compiler. Calls `die` if the flags could not be
+# converted.
+dlang_dmdw_dcflags() {
+       if [[ "${DLANG_VENDOR}" == "DigitalMars" ]]; then
+               # There's no translation that needs to be done.
+               echo "${DCFLAGS}"
+       elif [[ "${DLANG_VENDOR}" == "LDC" ]]; then
+               # ldmd2 passes all the arguments that it doesn't understand to 
ldc2.
+               echo "${DCFLAGS}"
+       elif [[ "${DLANG_VENDOR}" == "GNU" ]]; then
+               # From `gdmd --help`:   -q,arg1,...    pass arg1, arg2, etc. to 
gdc
+               if [[ "${DCFLAGS}" =~ .*,.* ]]; then
+                       eerror "DCFLAGS (${DCFLAGS}) contain a comma and can 
not be passed to gdmd."
+                       eerror "Please remove the comma, use a different 
compiler, or call gdc directly."
+                       die "DCFLAGS contain an unconvertable comma."
+               fi
+
+               local set flags=()
+               for set in ${DCFLAGS}; do
+                       flags+=("-q,${set}")
+               done
+               echo "${flags[@]}"
+       else
+               die "Set DLANG_VENDOR to DigitalMars, LDC or GNU prior to 
calling ${FUNCNAME}()."
+       fi
+}
+
+
 # @FUNCTION: dlang_system_imports
 # @DESCRIPTION:
 # Returns a list of standard system import paths (one per line) for the current

diff --git a/eclass/dmd.eclass b/eclass/dmd.eclass
index 3215f00..55f62e8 100644
--- a/eclass/dmd.eclass
+++ b/eclass/dmd.eclass
@@ -103,6 +103,8 @@ dmd_src_prepare() {
        ln -s ../druntime src/druntime || die "Failed to symlink 'druntime' to 
'src/druntime'"
        ln -s ../phobos   src/phobos   || die "Failed to symlink 'phobos' to 
'src/phobos'"
 
+       mkdir dmd/generated || die "Could not create output directory"
+
        # Convert line-endings of file-types that start as cr-lf and are 
installed later on
        for file in $( find . -name "*.txt" -o -name "*.html" -o -name "*.d" -o 
-name "*.di" -o -name "*.ddoc" -type f ); do
                edos2unix $file || die "Failed to convert DOS line-endings to 
Unix."
@@ -153,9 +155,9 @@ dmd_src_compile() {
        fi
        if dmd_ge 2.094; then
                einfo "Building dmd build script..."
-               DC="${DMD}" dlang_compile_bin dmd/generated/build 
dmd/src/build.d
+               dlang_compile_bin dmd/generated/build dmd/src/build.d
                einfo "Building dmd..."
-               env VERBOSE=1 ${HOST_DMD}="${DMD}" CXX="$(tc-getCXX)" 
${ENABLE_RELEASE}=1 ${LTO} dmd/generated/build dmd
+               env VERBOSE=1 ${HOST_DMD}="${DMD}" CXX="$(tc-getCXX)" 
${ENABLE_RELEASE}=1 ${LTO} dmd/generated/build DFLAGS="$(dlang_dmdw_dcflags)" 
dmd
        else
                einfo "Building dmd..."
                emake -C dmd/src -f posix.mak TARGET_CPU=X86 
${HOST_DMD}="${DMD}" ${HOST_CXX}="$(tc-getCXX)" ${ENABLE_RELEASE}=1 ${LTO}

Reply via email to