Debian Codegraph @

config/clang-flags

raw
1 # -*- shell-script -*-
2 #
3 # This file is part of the HDF4 build script. It is processed shortly
4 # after configure starts and defines, among other things, flags for
5 # the various compilation modes.
6
7 #
8 # Prepend `$srcdir/config/clang-warnings/` to the filename suffix(es) given as
9 # subroutine argument(s), remove comments starting with # and ending
10 # at EOL, replace spans of whitespace (including newlines) with spaces,
11 # and re-emit the file(s) thus filtered on the standard output stream.
12 #
13 load_clang_arguments()
14 {
15 set -- $(for arg; do
16 sed 's,#.*$,,' $srcdir/config/clang-warnings/${arg}
17 done)
18 IFS=' ' echo "$*"
19 }
20 # Get the compiler version in a way that works for clang
21 # unless a compiler version is already known
22 #
23 # cc_vendor: The compiler name: clang
24 # cc_version: Version number: 6.0.0, 7.3.0, ... 10.0.1
25 #
26 if test "X-" = "X-$cc_flags_set"; then
27 # clang -v will return version number following "clang" on Linux machines,
28 # but on Xcode the version number will follow "Apple LLVM version"
29 # Note that the Xcode reported LLVM version doesn't match the canonical
30 # LLVM version, so you'll need to do different version checks for
31 # Xcode.
32 cc_version="`$CC $CFLAGS -v 2>&1 |\
33 grep 'clang version' | sed 's/.*clang version \([-a-z0-9\.]*\).*/\1/'`"
34 if test -n "$cc_version"; then
35 cc_vendor="clang"
36 else
37 cc_version="`$CC $CFLAGS $H4_CFLAGS -v 2>&1 |\
38 grep 'Apple LLVM version' | sed 's/.*Apple LLVM version \([-a-z0-9\.]*\).*/\1/'`"
39 if test -n "$cc_version"; then
40 cc_vendor="Apple LLVM"
41 fi
42 fi
43 if test "X-" != "X-$cc_version"; then
44
45 # Get the compiler version numbers
46 cc_vers_major=`echo $cc_version | cut -f1 -d.`
47 cc_vers_minor=`echo $cc_version | cut -f2 -d.`
48 cc_vers_patch=`echo $cc_version | cut -f3 -d.`
49 test -n "$cc_vers_major" || cc_vers_major=0
50 test -n "$cc_vers_minor" || cc_vers_minor=0
51 test -n "$cc_vers_patch" || cc_vers_patch=0
52 fi
53 fi
54
55 if test "X-clang" = "X-$cc_vendor" -o "X-Apple LLVM" = "X-$cc_vendor"; then
56 echo "compiler '$CC' is $cc_vendor-$cc_version"
57
58 CFLAGS="$CFLAGS -Wno-error=implicit-function-declaration"
59 CFLAGS="$CFLAGS -std=c99"
60
61 DEBUG_CFLAGS="-g -ftrapv -fno-common"
62 # -Og is only understood by clang 4+ and Xcode 9+
63 # Otherwise use -O1 (which is what -Og usually equates to)
64 if test "X-clang" = "X-$cc_vendor" -a $cc_vers_major -ge 4 -o "X-Apple LLVM" = "X-$cc_vendor" -a $cc_vers_major -ge 9; then
65 DEBUG_CFLAGS="$DEBUG_CFLAGS -Og"
66 else
67 DEBUG_CFLAGS="$DEBUG_CFLAGS -O1"
68 fi
69 DEBUG_CPPFLAGS=
70
71 PROD_CFLAGS="-O3"
72 PROD_CPPFLAGS=
73
74 PROFILE_CFLAGS="-pg"
75 PROFILE_CPPFLAGS=
76
77 ###########
78 # General #
79 ###########
80
81 CFLAGS="$CFLAGS $(load_clang_arguments general)"
82 CFLAGS="$CFLAGS $(load_clang_arguments no-developer-general)"
83
84 #################
85 # Flags are set #
86 #################
87 cc_flags_set=yes
88 fi
89
90 # Clear cc info if no flags set
91 if test "X$cc_flags_set" = "X"; then
92 cc_vendor=
93 cc_version=
94 fi
95