-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnorm_common.prefix
92 lines (75 loc) · 3.72 KB
/
norm_common.prefix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
DEFAULT_PREFIX="$HOME/norm.$MACHINEID"
addpath() {
[ -z "$1" -o -z "$2" ] && return
local value VARNAME=$1
shift
for value; do
[ -z "${!VARNAME}" ] && export $VARNAME="$value" && continue || true
[[ ! "${!VARNAME}" =~ (^|:)$value(:|$) ]] && export $VARNAME="$value:${!VARNAME}" || true
done
}
setup_prefix() {
PREFIX="$1"
DESTDIR="$PREFIX/tmp/stage"
STAGE="$DESTDIR/$PREFIX"
COMPILEDIR="$PREFIX/tmp/compile"
printf -v ESCAPED_PREFIX "%q" "$PREFIX"
## default flags, if compiler doesn't support these, we can't operate
default_ldflags="-L$ESCAPED_PREFIX/lib"
default_cppflags="-I$ESCAPED_PREFIX/include"
## set compile flags
cc_addflags LDFLAGS $default_ldflags
cc_addflags CPPFLAGS $default_cppflags
## set optimization flags
cc_addflags CFLAGS -g -O2 -O3 -Ofast
cc_addflags CXXFLAGS -g -O2 -O3 -Ofast
## also try other flags if compiler supports them
[[ $OSTYPE == *darwin* ]] && cc_addflags CPPFLAGS -fno-stack-check
[[ $OSTYPE == *darwin* ]] && cc_addflags LDFLAGS -Wl,-rpath,$ESCAPED_PREFIX/lib -Wl,-x -Wl,-dead_strip -Wl,-dead_strip_dylibs
[[ $OSTYPE == *linux* ]] && cc_addflags LDFLAGS -Wl,-rpath,$ESCAPED_PREFIX/lib -Wl,-rpath-link,$ESCAPED_PREFIX/lib -Wl,-O1 -Wl,--as-needed -Wl,--gc-sections -Wl,--relax
[[ $OSTYPE == *darwin* ]] && export MACOSX_DEPLOYMENT_TARGET="$NORM_OSX_VERSION" ## needed for -rpath to work in CLT-only installs without xcode
# [[ $OSTYPE == *darwin* ]] && cc_addflags CPPFLAGS -mmacosx-version-min="$NORM_OSX_VERSION" ## needed for -rpath to work in CLT-only installs without xcode
is_cc_clang && cc_addflags CPPFLAGS -Qunused-arguments
## since we're building for this specific machine, we can do -march=native
cc_addflags CPPFLAGS "-march=native"
## try to make reproducible builds by removing path-specific debug sections
cc_addflags CPPFLAGS "-fdebug-prefix-map=$ESCAPED_PREFIX/tmp/compile=/build"
## let linker be more aggressive with removing unused functions and data
cc_addflags CPPFLAGS -ffunction-sections -fdata-sections
## disable warnings as errors, apple clang v12 seems to default to -Werror=implicit-function-declaration
## caught when building pinentry 1.1.0
cc_addflags CPPFLAGS -Wno-error=implicit-function-declaration
## clang 15, this breaks glib 2.58.2
cc_addflags CPPFLAGS -Wno-error=int-conversion
## -Wnarrowing breaks gcc-9.1
cc_addflags CPPFLAGS -Wno-error=narrowing
## set runtime flags
addpath PATH "$PREFIX/bin" "$PREFIX/sbin" "$PREFIX/bin/ccache_wrap"
addpath LD_RUN_PATH "$PREFIX/lib"
addpath PKG_CONFIG_PATH "$PREFIX/share/pkgconfig" "$PREFIX/lib/pkgconfig"
addpath PERL5LIB "$PREFIX/lib/perl5"
## create files if they don't exist
[ ! -e "$PREFIX/bin" ] && mkdir -p "$PREFIX/bin" || true
[ ! -e "$PREFIX/share/man" ] && mkdir -p "$PREFIX/share/man" || true
[ ! -e "$PREFIX/share/pkgconfig" ] && mkdir -p "$PREFIX/share/pkgconfig" || true
[ ! -e "$PREFIX/lib/pkgconfig" ] && mkdir -p "$PREFIX/lib/pkgconfig" || true
[ ! -e "$PREFIX/man" ] && ln -s share/man $PREFIX/man || true
[ ! -e "$PREFIX/include" ] && mkdir -p "$PREFIX/include" || true
[ ! -e "$PREFIX/lib" ] && mkdir -p "$PREFIX/lib" || true
[ ! -e "$PREFIX/lib64" ] && ln -s lib "$PREFIX/lib64" || true ## some packages insist on installing into lib64 when on 64-bit OS
[ ! -e "$PREFIX/share/config.site" ] && generate_config_site || true
}
use_clang() {
export CC=clang
export CXX=clang++
}
generate_config_site() {
## generate config.site
mkdir -p $PREFIX/share
cat << EOF > $PREFIX/share/config.site
[ -z "\$CPPFLAGS" ] && CPPFLAGS="$default_cppflags"
[ -z "\$LDFLAGS" ] && LDFLAGS="$default_ldflags"
true
EOF
}