forked from B-Lang-org/bsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.sh
executable file
·182 lines (155 loc) · 4.74 KB
/
platform.sh
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/sh
set -u
usage()
{
echo "Usage: $0 <option>"
echo ""
echo "Display canonical platform information"
echo "Valid options are:"
echo " ostype "
echo " machtype "
echo " tclsh "
echo " tclinc "
echo " tcllibs "
echo " c++_shared_flags"
}
if [ $# -ne 1 ] ; then
usage
exit 1;
fi
## =========================
## OSTYPE
## Account for values like "linux-gnu" by removing extra fields
OSTYPE=$(echo ${OSTYPE:=$(uname -s)} | cut -d'-' -f1)
## Account for values like "Darwin10.0" by removing the version number
OSTYPE=$(echo ${OSTYPE} | egrep -o "^[A-Za-z]+")
## Account for lowercase values like "linux" when we want "Linux"
OSTYPE=$(echo ${OSTYPE} | cut -c1 | tr a-z A-Z)$(echo $OSTYPE | cut -c2- | tr A-Z a-z)
if [ "$1" = "ostype" ] ; then
echo ${OSTYPE}
exit 0
fi
## =========================
## MACHTYPE
## Account for values like "x86_64-pc-linux-gnu" when all we want is
## "x86_64", "i386", etc
MACHTYPE=$(echo ${MACHTYPE:=$(uname -m)} | cut -d'-' -f1)
# If we see a BSD-style amd64 instead of x86_64, rewrite it to the more generic
# version.
if [ ${MACHTYPE} = "amd64" ] ; then
MACHTYPE=x86_64
fi
if [ "$1" = "machtype" ] ; then
echo ${MACHTYPE}
exit 0
fi
## =========================
## C++ SHARED FLAGS
if [ "$1" = "c++_shared_flags" ] ; then
if [ "${OSTYPE}" = "Darwin" ]
then
echo "-dynamiclib -Wl,-undefined,dynamic_lookup"
else
echo "-shared"
fi
exit 0
fi
## =========================
## Find the TCL shell command
if [ ${OSTYPE} = "Darwin" ] ; then
# Have Makefile avoid Homebrew's install of tcl on Mac
TCLSH=/usr/bin/tclsh
else
TCLSH=`which tclsh`
fi
if [ "$1" = "tclsh" ] ; then
echo ${TCLSH}
exit 0
fi
PKG_CONFIG=`which pkg-config`
if [ -z "${PKG_CONFIG}" ] ; then
PKG_CONFIG='false'
fi
TCL_SUFFIX=$(echo 'catch { puts [info tclversion]; exit 0}; exit 1' | ${TCLSH})
TCL_ALT_SUFFIX=$(echo ${TCL_SUFFIX} | sed 's/\.//')
if [ "$1" = "tclinc" ] ; then
# Avoid Homebrew's install of Tcl on Mac
if [ ${OSTYPE} = "Darwin" ] ; then
# no flags needed
exit 0
fi
# Try pkg-config
TCL_INC_FLAGS=$(${PKG_CONFIG} --silence-errors --cflags-only-I tcl${TCL_SUFFIX})
# If pkg-config didn't work with the first prefix, try the alternative version.
# For example, on FreeBSD, the tcl87 package installs tclsh8.7, but tcl87.pc
if [ $? -ne 0 ] ; then
TCL_INC_FLAGS=$(${PKG_CONFIG} --silence-errors --cflags-only-I tcl${TCL_ALT_SUFFIX})
fi
# The tcl package may also not have a suffix at all, e.g. on Arch Linux.
if [ $? -ne 0 ] ; then
TCL_INC_FLAGS=$(${PKG_CONFIG} --silence-errors --cflags-only-I tcl)
fi
# If pkg-config doesn't work, try some well-known locations
if [ $? -ne 0 ] ; then
if [ -f "/usr/local/include/tcl${TCL_SUFFIX}/tcl.h" ] ; then
TCL_INC_FLAGS="-I/usr/local/include/tcl${TCL_SUFFIX}"
elif [ -f "/usr/include/tcl${TCL_SUFFIX}/tcl.h" ] ; then
TCL_INC_FLAGS="-I/usr/include/tcl${TCL_SUFFIX}"
elif [ -f "/usr/include/tcl.h" ] ; then
TCL_INC_FLAGS=""
else
exit 1
fi
fi
echo ${TCL_INC_FLAGS}
exit 0
fi
if [ "${OSTYPE}" = "Darwin" ] ; then
LIB_SUFFIX=dylib
else
LIB_SUFFIX=so
fi
if [ "$1" = "tcllibs" ] ; then
TCL_VER=`echo 'catch { puts [info tclversion]; exit 0}; exit 1' | ${TCLSH}`
# Avoid Homebrew's install of Tcl on Mac
if [ ${OSTYPE} = "Darwin" ] ; then
echo -ltcl$(TCL_VER)
exit 0
fi
# Try pkg-config
TCL_LIB_FLAGS=`${PKG_CONFIG} --silence-errors --libs tcl${TCL_SUFFIX}`
# If pkg-config didn't work with the first prefix, try the alternative version.
# For example, on FreeBSD, the tcl87 package installs tclsh8.7, but tcl87.pc
if [ $? -ne 0 ] ; then
TCL_LIB_FLAGS=`${PKG_CONFIG} --silence-errors --libs tcl${TCL_ALT_SUFFIX}`
fi
# The tcl package may also not have a suffix at all, e.g. on Arch Linux.
if [ $? -ne 0 ] ; then
TCL_LIB_FLAGS=`${PKG_CONFIG} --silence-errors --libs tcl`
fi
if [ $? -eq 0 ] ; then
echo ${TCL_LIB_FLAGS}
exit 0
fi
# If pkg-config doesn't work, try some well-known locations
for L in /usr/lib /usr/lib64 /usr/local/lib ; do
for V in ${TCL_VER} ${TCL_SUFFIX} ${TCL_ALT_SUFFIX} ; do
if [ -f "${L}/libtcl${V}.${LIB_SUFFIX}" ] ; then
echo -L${L} -ltcl${V}
exit 0
fi
done
done
# If we're Linux, look for multiarch things
if [ "${OSTYPE}" = "Linux" ] ; then
for V in ${TCL_VER} ${TCL_SUFFIX} ${TCL_ALT_SUFFIX} ; do
if [ -f "/usr/lib/${MACHTYPE}-linux-gnu/libtcl${V}.${LIB_SUFFIX}" ] ; then
echo -ltcl${V}
exit 0
fi
done
fi
exit 1
fi
usage
exit 1