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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
|
#!/bin/sh -e
top="`pwd`"
build="`pwd`/build"
bin="${build}/bin"
man="${build}/man"
lib="${build}/lib"
include="${build}/include"
log="${build}/log"
work="${build}/work"
contribdir="`pwd`/build-contrib"
rm -rf "${build}"
mkdir -p "${build}"
mkdir -p "${bin}"
mkdir -p "${man}"
mkdir -p "${lib}"
mkdir -p "${include}"
exec 5>"${log}"
exec 2>&5
exec </dev/null
log0() {
echo "=== `date` === $@" >&5
}
log1() {
echo "=== `date` === $@"
echo "=== `date` === $@" >&5
}
log2() {
echo "=== `date` === $@"
echo "=== `date` === $@" >&5
}
version=`head -1 "${top}/debian/changelog" | cut -d '(' -f2 | cut -d ')' -f1` #XXX
if [ x"${version}" = x ]; then
version=noversion
fi
LANG=C
export LANG
log0 "uname -a: `uname -a || :`"
log0 "uname -F: `uname -F || :`"
log0 "uname -M: `uname -M || :`"
log0 "ulimit -a: `echo; ulimit -a || :`"
log1 "obtaining compiler"
rm -rf "${work}"
mkdir -p "${work}"
(
cd "${work}"
(
if [ x"${CC}" != x ]; then
echo "${CC} "
fi
cat "${top}/conf-cc"
) | while read compiler
do
echo 'int main(void) { return 0; }' > try.c
${compiler} -o try try.c || { log2 "${compiler} failed"; continue; }
log2 "${compiler} ok"
echo "${compiler}" > compiler
break
done
)
compiler=`head -1 "${work}/compiler"`
log1 "finishing"
log1 "checking compiler options"
rm -rf "${work}"
mkdir -p "${work}"
(
cd "${work}"
cflags=`cat "${top}/conf-cflags" || :`
cflags="${CPPFLAGS} ${CFLAGS} ${LDFLAGS} ${cflags}"
for i in ${cflags}; do
echo 'int main(void) { return 0; }' > try.c
${compiler} ${options} "${i}" -o try try.c || { log2 "${i} failed"; continue; }
options="${options} ${i}"
log2 "${i} ok"
done
echo ${options} > options
)
compilerorig=${compiler}
compiler="${compiler} `cat ${work}/options`"
log2 "${compiler}"
log1 "finishing"
log1 "checking libs"
rm -rf "${work}"
mkdir -p "${work}"
(
cd "${work}"
(
cat "${top}/conf-libs" || :
) | (
exec 9>syslibs
while read i; do
echo 'int main(void) { return 0; }' > try.c
${compiler} ${i} -o try try.c || { log2 "${i} failed"; continue; }
echo "${i}" >&9
log2 "${i} ok"
done
)
)
libs=`cat "${work}/syslibs"`
log1 "finishing"
log1 "checking \$LIBS"
if [ x"${LIBS}" != x ]; then
rm -rf "${work}"
mkdir -p "${work}"
(
cd "${work}"
for i in ${LIBS}; do
echo 'int main(void) { return 0; }' > try.c
${compiler} ${i} -o try try.c || { log2 "${i} failed"; continue; }
syslibs="${syslibs} ${i}"
log2 "${i} ok"
done
echo ${syslibs} > syslibs
)
fi
libsorig=${libs}
libs="${libs} `cat ${work}/syslibs`"
log1 "finishing"
log1 "building sysdep headers"
rm -rf "${work}"
mkdir -p "${work}"
cp -pr sysdep/* "${work}"
(
cd "${work}"
sh list | (
while read target source
do
[ -f "${include}/${target}" ] && continue
rm -f "${source}" "${target}.tmp"
${compiler} -O0 -o "${source}" "${source}.c" ${libs} || continue
"./${source}" > "${target}.tmp" 2>/dev/null || continue
if [ -f "${source}.out" ]; then
cp "${source}.out" "${include}/${target}"
else
#runtime
cp "${target}.tmp" "${include}/${target}"
fi
log2 "${target} ${source}"
done
)
)
log1 "finishing"
log1 "starting crypto lib"
rm -rf "${work}"
mkdir -p "${work}"
cp -pr crypto/* "${work}"
(
cd "${work}"
cat CRYPTOSOURCES\
| while read x
do
${compiler} -I"${include}" -c "${x}.c" || { log2 "libtinysshcrypto.a failed ... see the log ${log}"; exit 111; }
done || exit 111
ar cr "${lib}/libtinysshcrypto.a" `cat CRYPTOLIBS` || exit 0
)
log2 "libtinysshcrypto.a ok"
log1 "finishing"
origlibs="${lib}/libtinysshcrypto.a ${origlibs}"
libs="${lib}/libtinysshcrypto.a ${libs}"
log1 "starting crypto headers"
rm -rf "${work}"
mkdir -p "${work}"
cp -p crypto/CRYPTOPRIMITIVES "${work}"
cp -pr crypto-tests/*test.c "${work}"
cp -pr crypto-tests/*.h "${work}"
cp -pr crypto-tests/*.data "${work}" 2>/dev/null || :
(
cd "${work}"
cat CRYPTOPRIMITIVES\
| while read primitive checkflag
do
if [ "x${checkflag}" = x0 ]; then
cp -p "${top}/crypto/${primitive}.h" "${include}"
continue;
fi
testf=`echo "${primitive}" | sed 's/$/test/'`
(
echo '#include <stdio.h>'
echo "#include <${primitive}.h>"
echo 'int main(void) {'
echo "#ifdef ${primitive}_PRIMITIVE"
echo "printf(\"%s\\\\n\", ${primitive}_PRIMITIVE);"
echo '#else'
echo "#ifdef ${primitive}_IMPLEMENTATION"
echo "printf(\"%s\\\\n\", ${primitive}_IMPLEMENTATION);"
echo '#endif'
echo "#ifdef ${primitive}_implementation"
echo "printf(\"%s\\\\n\", ${primitive}_implementation);"
echo '#endif'
echo '#endif'
echo 'return 0; }'
) > try.c
#try ext. crypto library
log0 "trying: ext. ${primitive}:"
if ${compiler} -c "${testf}.c" ${libs}; then
if ${compiler} -o "${testf}" "${testf}.o" ${libs}; then
if ${compiler} -o try try.c; then
if /bin/sh -ec "./${testf}"; then
log2 "${primitive}.h (`./try`) ok"
echo "#include <${primitive}.h>" >> crypto.h
continue
else
log2 "${primitive}.h (`./try`) failed"
fi
fi
fi
fi
#try int. crypto library
log0 "trying: int. ${primitive}:"
if cp -p "${top}/crypto/${primitive}.h" . ; then
if ${compilerorig} -I. -I"$include" -o "${testf}" "${testf}.c" ${origlibs}; then
if ${compilerorig} -I. -I"$include" -o try try.c; then
if /bin/sh -ec "./${testf}"; then
log2 "${primitive}.h (`./try`) ok"
echo "#include \"${primitive}.h\"" >> crypto.h
cp -p "${primitive}.h" "${include}"
continue
fi
fi
fi
fi
log2 "${primitive}.h failed ... see the log ${log}"
exit 111
done || exit 111
cp crypto.h "${include}/crypto.h"
)
log1 "finishing"
rm -rf "${work}"
mkdir -p "${work}"
cp -pr tinyssh/* "${work}"
cp -pr tinyssh-tests/*test.c "${work}"
cp -pr tinyssh-tests/*.h "${work}"
cp -pr _tinyssh/* "${work}" 2>/dev/null || :
(
cd "${work}"
log1 "starting tinyssh objects"
touch SOURCES TARGETS _TARGETS
cat SOURCES TARGETS _TARGETS\
| while read x
do
${compiler} "-DCOMPILER=\"${compilerorig}\"" "-DVERSION=\"${version}\"" -I"${include}" -c "${x}.c" || { log2 "${x}.o failed ... see the log ${log}"; exit 111; }
log2 "${x}.o ok"
done || exit 111
ar cr libtinyssh.a `cat LIBS` || exit 111
log1 "finishing"
#tests
log1 "starting tinyssh-tests"
cat LIBS \
| while read x
do
t=`echo ${x} | sed 's/.o$/test/'`
if [ ! -h "${t}.c" ]; then
${compiler} -I"${include}" -c "${t}.c" || { log2 "${t} failed ... see the log ${log}"; exit 111; }
${compiler} -I"${include}" -o "${t}" "${t}.o" libtinyssh.a ${libs} || { log2 "${t} failed ... see the log ${log}"; exit 111; }
"./${t}" || { log2 "${t} failed ... see the log ${log}"; exit 111; }
log2 "${t} ok"
fi
done || exit 111
log1 "finishing"
log1 "starting _tinyssh"
cat _TARGETS \
| while read x
do
${compiler} -I"${include}" -o "${x}" "${x}.o" libtinyssh.a ${libs} || { log2 "${x} failed ... see the log ${log}"; exit 111; }
log2 "${x} ok"
cp -p "${x}" "${bin}/${x}";
done || exit 111
log1 "finishing"
log1 "starting tinyssh"
cat TARGETS \
| while read x
do
${compiler} -I"${include}" -o "${x}" "${x}.o" libtinyssh.a ${libs} || { log2 "${x} failed ... see the log ${log}"; exit 111; }
log2 "${x} ok"
done || exit 111
log1 "finishing"
log1 "starting tinyssh regression tests"
cat TARGETS \
| while read x
do
sh ${x}.rts > ${x}.out
cmp "${x}.out" "${x}.exp" || { log2 "${x} regression test failed ... see the difference `pwd`/${x}.out `pwd`/${x}.exp"; exit 111; }
log2 "${x} ok"
cp -p "${x}" "${bin}/${x}";
done || exit 111
log1 "finishing"
) || exit 111
log1 "starting manpages"
cp -pr man/* "${man}"
log1 "finishing"
log1 "counting words of code - tests"
rm -rf "${work}"
mkdir -p "${work}"
for dir in tinyssh-tests crypto-tests _tinyssh; do
(
touch "${work}/${dir}"
[ -d "${dir}" ] || exit 0
cd "${dir}"
cat *.c *.h > "${work}/${dir}" || :
)
(
cd "${work}"
cat "${dir}" \
| (
cpp -fpreprocessed || gcpp -fpreprocessed
) | (
x=`sed 's/[_a-zA-Z0-9][_a-zA-Z0-9]*/x/g' | tr -d ' \012' | wc -c | tr -d ' '`
log2 "${dir} ${x}"
)
)
done
(
cd "${work}"
cat * \
| (
cpp -fpreprocessed || gcpp -fpreprocessed
) | (
x=`sed 's/[_a-zA-Z0-9][_a-zA-Z0-9]*/x/g' | tr -d ' \012' | wc -c | tr -d ' '`
log2 "$x words of code"
)
)
log1 "finishing"
echo "=== `date` === counting words of code"
rm -rf "${work}"
mkdir -p "${work}"
for dir in sysdep tinyssh crypto; do
(
cd "${dir}"
cat *.c *.h > "${work}/${dir}" || :
)
(
cd "${work}"
cat "${dir}" \
| (
cpp -fpreprocessed || gcpp -fpreprocessed
) | (
x=`sed 's/[_a-zA-Z0-9][_a-zA-Z0-9]*/x/g' | tr -d ' \012' | wc -c | tr -d ' '`
log2 "${dir} ${x}"
)
)
done
(
cd "${work}"
cat * \
| (
cpp -fpreprocessed || gcpp -fpreprocessed
) | (
x=`sed 's/[_a-zA-Z0-9][_a-zA-Z0-9]*/x/g' | tr -d ' \012' | wc -c | tr -d ' '`
log2 "${x} words of code"
)
)
log1 "finishing"
exit 0
|