-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·116 lines (91 loc) · 2.59 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
#! /bin/bash
# Run this file to recreate the current configuration.
CFLAGSS=("-O" "-O3" "-g")
CCS=("gcc" "cc")
OPTS=("-fPIC" "-I." )
# specify a temporary directory
TEMP=/tmp
# see
# https://askubuntu.com/questions/674333/how-to-pass-an-array-as-function-argument
# for help on syntax here -- sh is *horrible* syntax
# run a test over a loop
# and return the first that works
# eg
# LS=$(test_cmd which "lss ls")
function test_cmd () {
declare c="$1"; shift 1
rest=("$@")
for arg in "${rest[@]}";
do
if eval $c $arg > /dev/null 2>&1
then
echo $arg
echo "Type1" $c $arg 1>&2
return $?
elif eval $arg $c > /dev/null 2>&1
then
echo $arg
echo "Type1" $arg $c 1>&2
return $?
else
echo "Not" $c $arg 1>&2
echo "Nor" $arg $c 1>&2
eval $arg $c
fi
done
return $?
}
ARCH=$(uname -m)
HERE=$(pwd)
BPMS=${BPMS-$HERE}
ASYSTEM=$(uname -s)
# set OS to arch unless MSYSTEM already set
MSYSTEM=${MSYSTEM-$ARCH}
OS=$MSYSTEM
WINDOWS=MINGW64
echo ">>>> $OS : $MSYSTEM : $ASYSTEM : $HERE : $BPMS"
if [ "$MSYSTEM" = "MINGW64" ] || [ "$ImageOS" = "win19" ]
then
echo "..." "$MSYSTEM"=="MINGW64" "$OS"=="win19" ": $OS : $MSYSTEM"
LIBEXT='dll'
LIBC='-lmsvcrt -lm'
else
echo ".. $MSYSTEM : $OS"
LIBEXT='so'
LIBC='-lc -lm'
fi
##################
# test codes
##################
##################
# makefile
##################
# fixers
q='\/'
BPMS_=$(echo $BPMS | sed 's/\//Qq/g')
# initialise makefile
sed < $BPMS/src/Makefile.in 's/@BPMS@/'$BPMS_'/' | sed 's/Qq/'$q'/g' | sed 's/@ASYSTEM@/'$ASYSTEM'/' |sed 's/@LIBEXT@/'$LIBEXT'/' |sed 's/@OS@/'$OS'/' | sed 's/@ARCH@/'$ARCH'/' > $BPMS/src/makefile
mkdir -p bin/${OS}
PATH=".:c/MinGW/bin:bin:bin/${OS}:${PATH}"
# create test C code file
echo '#include <stdio.h>' > $TEMP/test_$$.c
echo 'int no_main(int argc,char ** argv){printf("hello world\\n");return(1);}' >> $TEMP/test_$$.c
echo '' >> $TEMP/test_$$.c
##################
# $CC
##################
CC=$(test_cmd "which" "${CCS[@]}")
sed < ${BPMS}/src/makefile 's/@CC@/'"$CC"'/' > $TEMP/tmp.$$; mv $TEMP/tmp.$$ ${BPMS}/src/makefile
##################
# $CFLAGS
##################
CFLAGS=$(test_cmd "${CC} $TEMP/test_$$.c -o $TEMP/test_$$.o -c" "${CFLAGSS[@]}")
sed < ${BPMS}/src/makefile 's/@CFLAGS@/'"$CFLAGS"'/' > $TEMP/tmp.$$; mv $TEMP/tmp.$$ ${BPMS}/src/makefile
##################
# $OPT
##################
OPT=$(test_cmd "${CC} ${CFLAGS} $TEMP/test_$$.c -o $TEMP/test_$$.o -c" "${OPTS[@]}")
sed < ${BPMS}/src/makefile 's/@OPT@/'"$OPT"'/' > $TEMP/tmp.$$; mv $TEMP/tmp.$$ ${BPMS}/src/makefile
# tidy up
rm -f $TEMP/test_$$.c
exit 0