-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·140 lines (117 loc) · 3.52 KB
/
configure
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh -
die () {
echo "error: " $@
echo "pass --help for help"
exit 1
}
usage () {
cat <<EOF
Usage: $0 [OPTION]... [VAR=VALUE]
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
--plugdir=DIR directory to store/look for the plugins during operation [/tmp/gccwrap]
--auxdir=DIR directory to store/look for the auxiliary files during operations [/tmp/gccwrap]
--elfclass=VAL ELF bitness (either 32 or 64) [auto]
--debug[=yes] debug build [no]
--release[=yes] release build [no]
Some influential environment variables:
CC C compiler command [detected: gcc/c99/cc]
CFLAGS C compiler flags
CPPFLAGS C preprocessor flags [-I. -DSECTIONS]
CXX C++ compiler command [detected: g++/c++]
CXXFLAGS C++ compiler flags
LDFLAGS linker flags
EOF
exit 0
}
cmdexists () { type "$1" >/dev/null 2>&1 ; }
trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
trycxx () { test -z "$CXX" && cmdexists "$1" && CXX=$1 ; }
debug=no
release=no
elfclass=
plugdir=/tmp/gccwrap
auxdir=/tmp/gccwrap
for arg ; do
case "$arg" in
--help|-h) usage ;;
--debug|--debug=yes) debug=yes ;;
--release|--release=yes) release=yes ;;
--plugdir=*) plugdir=${arg#*=} ;;
--auxdir=*) auxdir=${arg#*=} ;;
--elfclass=*)
elfclass=${arg#*=}
test "$elfclass" != "32" -a "$elfclass" != "64" &&
die "$0: elfclass must be eihter 32 or 64."
;;
-* ) echo "$0: unknown option $arg. Skipping." ;;
CC=*) CC=${arg#*=} ;;
CFLAGS=*) CFLAGS=${arg#*=} ;;
CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
CXX=*) CXX=${arg#*=} ;;
CXXFLAGS=*) CXXFLAGS=${arg#*=} ;;
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
*) echo "$0: unrecognized argument '$arg'. Skipping." ;;
esac
done
if test "$release" = yes -a "$debug" = yes; then
die "$0: incompatible options --release and --debug"
fi
if test "$release" = no -a "$debug" = no; then
die "$0: either --release or --debug must be specified"
fi
# TODO: consider putting privatized symbols into seperate sections (in the
# compiler plugin) instead of always having to build the wrapper with -DSECTIONS.
CPPFLAGS="$CPPFLAGS -I. -DSECTIONS"
if test "$debug" = yes; then
CFLAGS="$CFLAGS -g -fno-inline-functions"
fi
if test "$release" = yes; then
CFLAGS="$CFLAGS -O2"
fi
printf "checking for a C compiler... "
trycc gcc
trycc c99
trycc cc
printf "%s\n" "$CC"
test -n "$CC" || die "$0: cannot find a C compiler"
printf "checking for a C++ compiler... "
trycxx g++
trycxx c++
printf "%s\n" "$CXX"
test -n "$CXX" || die "$0: cannot find a C++ compiler"
exec 3>&1 1>confdef.h
cat << EOF
/* This file was generated by:
* $0
* Any changes made here will be lost if configure is re-run. */
#ifndef CONFDEF_H
#define CONFDEF_H
#define PLUGDIR "$plugdir/"
#define AUXDIR "$auxdir/"
EOF
if test -n "$elfclass"; then
cat <<- EOF
#define PLUG_TARGET_ELFCLASS $elfclass
EOF
fi
cat << EOF
#endif // CONFDEF_H
EOF
exec 1>config.mak
cat << EOF
# This version of config.mak was generated by:
# $0
# Any changes made here will be lost if configure is re-run.
CC = $CC
CFLAGS = $CFLAGS
CPPFLAGS = $CPPFLAGS
CXX = $CXX
CXXFLAGS = $CXXFLAGS
LDFLAGS = $LDFLAGS
plugdir = $plugdir
auxdir = $auxdir
EOF
exec 1>&3 3>&-