blob: 4cc874f1cafe38bf53b1a7b403d5075920e52685 [file] [log] [blame]
Brian Silverman84b22232019-01-25 20:29:29 -08001#!/bin/sh
2set -e
3
4PYCRC=`dirname $0`/../pycrc.py
5outdir_old="/tmp/pycrc_out"
6outdir_new="/tmp/pycrc_new"
7tarfile="pycrc_files.tar.gz"
8
9usage() {
10 echo >&2 "usage: $0 [OPTIONS]"
11 echo >&2 ""
12 echo >&2 "with OPTIONS in"
13 echo >&2 " -c check the generated output"
14 echo >&2 " -g generate the database"
15 echo >&2 " -n no cleanup: don't delete the directories with the generated code"
16 echo >&2 " -h this help message"
17}
18
19
20opt_check=off
21opt_no_cleanup=off
22opt_generate=off
23
24while getopts cgnh opt; do
25 case "$opt" in
26 c) opt_check=on;;
27 g) opt_generate=on;;
28 n) opt_no_cleanup=on;;
29 h) usage
30 exit 0
31 ;;
32 \?) usage # unknown flag
33 exit 1
34 ;;
35 esac
36done
37shift `expr $OPTIND - 1`
38
39if [ -e "$outdir_old" ]; then
40 echo >&2 "Output directory $outdir_old exists!"
41 exit 1
42fi
43if [ -e "$outdir_new" ]; then
44 echo >&2 "Output directory $outdir_new exists!"
45 exit 1
46fi
47
48
49cleanup() {
50 if [ "$opt_no_cleanup" = "on" ]; then
51 echo "No cleanup. Please delete $outdir_old and $outdir_new when you're done"
52 else
53 rm -rf "$outdir_old" "$outdir_new"
54 fi
55}
56
57trap cleanup 0 1 2 3 15
58
59
60generate() {
61 outfile="$1"
62 shift
63 $PYCRC "$@" -o "${outfile}"
64 sed -i -e 's/Generated on ... ... .. ..:..:.. ..../Generated on XXX XXX XX XX:XX:XX XXXX/; s/by pycrc v[0-9.]*/by pycrc vXXX/;' "${outfile}"
65}
66
67populate() {
68 outdir=$1
69 mkdir -p "$outdir"
70 models=`PYTHONPATH=.. python -c 'import pycrc.models as m; print(" ".join(m.CrcModels().names()))'`
71 for model in "undefined" $models; do
72 for algo in "bbb" "bbf" "tbl"; do
73 for cstd in c98 c99; do
74 if [ "$model" = "undefined" ]; then
75 mod_opt=
76 else
77 mod_opt="--model=${model}"
78 fi
79 generate "${outdir}/${model}_${algo}_${cstd}.h" --generate=h --algorithm=${algo} $mod_opt
80 generate "${outdir}/${model}_${algo}_${cstd}.c" --generate=c --algorithm=${algo} $mod_opt
81 done
82 done
83 done
84
85 algo=tbl
86 for model in crc-32; do
87 for slice in 4 8 16; do
88 for cstd in c98 c99; do
89 generate "${outdir}/${model}_${algo}_sb${slice}_${cstd}.h" --generate=h --algorithm=${algo} --model=${model} --slice-by ${slice}
90 generate "${outdir}/${model}_${algo}_sb${slice}_${cstd}.c" --generate=c --algorithm=${algo} --model=${model} --slice-by ${slice}
91 done
92 done
93 done
94}
95
96do_check() {
97 tar xzf "$tarfile" -C "`dirname $outdir_new`"
98 populate "$outdir_new"
99 diff -ru "$outdir_old" "$outdir_new"
100}
101
102
103if [ "$opt_check" = "on" ]; then
104 if [ ! -f "$tarfile" ]; then
105 echo >&2 "Can't find tarfile $tarfile"
106 exit 1
107 fi
108 do_check
109fi
110
111if [ "$opt_generate" = "on" ]; then
112 populate "$outdir_old"
113 dirname="`dirname $outdir_old`"
114 basename="`basename $outdir_old`"
115 tar czf "$tarfile" -C "$dirname" "$basename"
116fi