1#!/bin/sh 2# Copyright (c) 2024 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15DIR="$(cd "$(dirname "$0")" && pwd)" 16BASENAME="$(basename "$0")" 17TARGET="${BASENAME%-*}" 18EXE="${BASENAME##*-}" 19DEFAULT_TARGET=x86_64-w64-mingw32 20if [ "$TARGET" = "$BASENAME" ]; then 21 TARGET=$DEFAULT_TARGET 22fi 23ARCH="${TARGET%%-*}" 24TARGET_OS="${TARGET##*-}" 25 26# Check if trying to compile Ada; if we try to do this, invoking clang 27# would end up invoking <triplet>-gcc with the same arguments, which ends 28# up in an infinite recursion. 29case "$*" in 30*-x\ ada*) 31 echo "Ada is not supported" >&2 32 exit 1 33 ;; 34*) 35 ;; 36esac 37 38# Allow setting e.g. CCACHE=1 to wrap all building in ccache. 39if [ -n "$CCACHE" ]; then 40 CCACHE=ccache 41fi 42 43# If changing this wrapper, change clang-target-wrapper.c accordingly. 44CLANG="$DIR/clang++" 45FLAGS="" 46case $EXE in 47clang++|g++|c++) 48 FLAGS="$FLAGS --driver-mode=g++" 49 ;; 50c99) 51 FLAGS="$FLAGS -std=c99" 52 ;; 53c11) 54 FLAGS="$FLAGS -std=c11" 55 ;; 56esac 57case $ARCH in 58i686) 59 # Dwarf is the default for i686. 60 ;; 61x86_64) 62 # SEH is the default for x86_64. 63 ;; 64armv7) 65 # SEH is the default for armv7. 66 ;; 67aarch64) 68 # SEH is the default for aarch64. 69 ;; 70esac 71case $TARGET_OS in 72mingw32uwp) 73 # the UWP target is for Windows 10 74 FLAGS="$FLAGS -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00" 75 # the UWP target can only use Windows Store APIs 76 FLAGS="$FLAGS -DWINAPI_FAMILY=WINAPI_FAMILY_APP" 77 # the Windows Store API only supports Windows Unicode (some rare ANSI ones are available) 78 FLAGS="$FLAGS -DUNICODE" 79 # add the minimum runtime to use for UWP targets 80 FLAGS="$FLAGS -Wl,-lwindowsapp" 81 # This still requires that the toolchain (in particular, libc++.a) has 82 # been built targeting UCRT originally. 83 FLAGS="$FLAGS -Wl,-lucrtapp" 84 # Force the Universal C Runtime 85 FLAGS="$FLAGS -D_UCRT" 86 ;; 87esac 88 89FLAGS="$FLAGS -target $TARGET" 90FLAGS="$FLAGS -rtlib=compiler-rt" 91FLAGS="$FLAGS -unwindlib=libunwind" 92FLAGS="$FLAGS -stdlib=libc++" 93FLAGS="$FLAGS -fuse-ld=lld" 94 95$CCACHE "$CLANG" $FLAGS "$@" 96