-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·128 lines (117 loc) · 3.35 KB
/
configure.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
#!/bin/sh
# Makefile generator script by Laszlo Ashin <[email protected]>
# default settings for make
CC="gcc"
CFLAGS="-Wall"
LDFLAGS="-s -O2 -lSDL"
BDIR="build"
#CCPREFIX="ccache"
# programs to build, separated by one space
#PROGS="soko armsoko"
PROGS="soko"
# settings for each program listed in PROGS (above)
# FILES is required for each PROG (filenames must be separated by one space)
# CC, CFLAGS, LDFLAGS and BDIR is optional
# if not defined, the default setting is used for that variable
FILES_soko="main gr map field list player menu inval"
FILES_armsoko=${FILES_soko}
BDIR_armsoko="release"
CC_armsoko="arm-linux-gnu-gcc"
CFLAGS_armsoko="-Wall -I/home/laci/arm/include"
LDFLAGS_armsoko="-s -O2 -Wl,-rpath-link,/home/laci/arm/lib -L/home/laci/arm/lib -lSDL"
# don't edit below this line unless you know what you're doing.
# function to simplify the output process (output to Makefile)
put() {
echo "${1}" >> Makefile
}
# check the default compiler
${CC} &> /dev/null
if [ "x${?}" == "x127" ]; then
echo "ERROR: Default compiler is not available: ${CC}"
exit 1
fi
# check the compiler prefix if defined
if [ ${CCPREFIX} ]; then
${CCPREFIX} &> /dev/null
if [ "x${?}" == "x127" ]; then
echo "WARNING: compiler prefix is not available: ${CCPREFIX}"
CCPREFIX=
fi
fi
echo "Creating Makefile"
rm -f Makefile
put '.PHONY: all clean'
put
DESTS=""
SKIPTARGETS=" "
for PROG in ${PROGS}; do
_CC=$(eval echo \$$(echo "CC_${PROG}"))
[ "${_CC}" ] || _CC=${CC}
_BDIR=$(eval echo \$$(echo "BDIR_${PROG}"))
[ "${_BDIR}" ] || _BDIR=${BDIR}
# check the compiler
${_CC} &> /dev/null
if [ "x${?}" == "x127" ]; then
echo "WARNING: Compiler is not available: ${_CC}"
SKIPTARGETS=" ${PROG}${SKIPTARGETS}"
else
DESTS="${_BDIR}/${PROG} ${DESTS}"
fi
done
put "all: ${DESTS}"
put
BDIRS=" "
echo "Generating dependencies for:"
for PROG in ${PROGS}; do
if [ "$(echo "${SKIPTARGETS}" | grep " ${PROG} ")" ]; then
echo " ${PROG}: skipping"
continue
fi
echo " ${PROG} "
# try to load the actual PROG-specific settings
# fall back to default settings if the specific one is empty
_CC=$(eval echo \$$(echo "CC_${PROG}"))
[ "${_CC}" ] || _CC=${CC}
_CFLAGS=$(eval echo \$$(echo "CFLAGS_${PROG}"))
[ "${_CFLAGS}" ] || _CFLAGS=${CFLAGS}
_LDFLAGS=$(eval echo \$$(echo "LDFLAGS_${PROG}"))
[ "${_LDFLAGS}" ] || _LDFLAGS=${LDFLAGS}
_BDIR=$(eval echo \$$(echo "BDIR_${PROG}"))
[ "${_BDIR}" ] || _BDIR=${BDIR}
_FILES=$(eval echo \$$(echo "FILES_${PROG}"))
# FILES variable is required as i said in the config section
if [ -z "${_FILES}" ]; then
echo "No FILES defined for ${PROG}."
exit 1
fi
# use prefix if available
[ ${CCPREFIX} ] && _CC="${CCPREFIX} ${_CC}"
OBJS=""
for FILE in ${_FILES}; do
OBJS="${_BDIR}/${FILE}.o ${OBJS}"
done
put "${_BDIR}/${PROG}: ${_BDIR} ${OBJS}"
put " @echo \" LD ${PROG}\""
put " @${_CC} ${OBJS} ${_LDFLAGS} -o ${_BDIR}/${PROG}"
put ""
for FILE in ${_FILES}; do
echo " ${FILE}.c"
DEP="$(${_CC} -MM ${FILE}.c -MT ${_BDIR}/${FILE}.o)"
[ "x${?}" = "x0" ] || exit 1
put "${DEP}"
put " @echo \" CC ${FILE}.o\""
put " @${_CC} ${_CFLAGS} -c ${FILE}.c -o ${_BDIR}/${FILE}.o"
put
done
if [ -z "$(echo "${BDIRS}" | grep " ${_BDIR} ")" ]; then
BDIRS=" ${_BDIR}${BDIRS}"
put "${_BDIR}:"
put " @echo \" MKD ${_BDIR}\""
put " @mkdir -p ${_BDIR}"
put
fi
done
put "clean:"
put ' @echo " CLEAN"'
put " @rm -rf${BDIRS}"
echo "Makefile is ready."