generate_bench.sh 3.09 KB
Newer Older
1
2
#!/bin/sh

3
# Vaucanson, a generic library for finite state machines.
4
# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008 The Vaucanson Group.
5
6
7
8
9
10
11
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# The complete GNU General Public Licence Notice can be found as the
12
# `COPYING' file in the root directory.
13
14
#
# The Vaucanson Group consists of people listed in the `AUTHORS' file.
15

16
17
18
19
# generate_bench DIR
generate_bench ()
{
    BENCH_DIR=$1
20
21
22

    # Initialize Makefile.am.
    cat > $BENCH_DIR/Makefile.am <<EOF
Nicolas Desprès's avatar
Nicolas Desprès committed
23
24
25
#
# DO NOT EDIT BY HAND - Generated by $0
#
26
include \$(srcdir)/../common/bench.mk
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
27
noinst_PROGRAMS =
28
29
30
31
32
33
EOF

    for BENCH in $(ls $BENCH_DIR/*_bench.hh 2> /dev/null); do
	BENCH_HEADER="$(basename $BENCH)"
	BENCH_NAME="$(echo $BENCH_HEADER | sed 's/_bench\.hh$//')"

34
        # Claim that we are under GPL.
35
	cat > $BENCH_DIR/$BENCH_NAME-bench.cc <<EOF
Nicolas Desprès's avatar
Nicolas Desprès committed
36
37
38
//
// DO NOT EDIT BY HAND - Generated by $0
//
39
// Vaucanson, a generic library for finite state machines.
40
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
41
//
42
43
44
45
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
Nicolas Desprès's avatar
Nicolas Desprès committed
46
//
47
// The complete GNU General Public Licence Notice can be found as the
48
// \`COPYING' file in the root directory.
Nicolas Desprès's avatar
Nicolas Desprès committed
49
//
50
// The Vaucanson Group consists of people listed in the \`AUTHORS' file.
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
EOF

        # Include necessary tools
	cat >> $BENCH_DIR/$BENCH_NAME-bench.cc <<EOF

#include <iostream>

#include <vaucanson/tools/bencher.hh>
EOF

        # Precise this-bench related things
	cat >> $BENCH_DIR/$BENCH_NAME-bench.cc <<EOF
#define BENCHNAME		$BENCH_NAME
#include "$BENCH"
EOF

	cat >> $BENCH_DIR/$BENCH_NAME-bench.cc <<EOF
#define BENCHFUN		BENCHFUN_layer1(BENCHNAME)
#define BENCHFUN_layer1(NAME)	BENCHFUN_layer2(NAME)
#define BENCHFUN_layer2(NAME)	NAME ## _bench

#define BENCHTEXT		BENCHTEXT_layer1(BENCHNAME)
#define BENCHTEXT_layer1(NAME)	BENCHTEXT_layer2(NAME)
#define BENCHTEXT_layer2(NAME)  # NAME

int main(int argc, char* argv[])
{
78
  std::cerr << BENCHTEXT << ":" << std::endl;
79
80
81
82
83
84
85
  if (argc == 2)
    BENCHFUN(atoi(argv[1]));
}
EOF

	# Add the bench to the Makefile.am.
	cat >> $BENCH_DIR/Makefile.am <<EOF
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
86
noinst_PROGRAMS += $BENCH_NAME-bench
87
88
89
90
91
92
$(echo "$BENCH_NAME" | sed 's/-/_/g')_bench_SOURCES = $BENCH_NAME-bench.cc \
						      $BENCH_HEADER
EOF
    done
    if [ -r $BENCH_DIR/Makefile.bench ]; then
	cat >> $BENCH_DIR/Makefile.am <<EOF
93
include \$(srcdir)/Makefile.bench
94
95
EOF
    fi
96
97
98
99
100
101
}

case $1:$# in
    --all:1)
	BENCH_DIRS="determinization 				\
	 minimization_debruijn derived_terms minimization_2n	\
102
         quotient composition eps_removal iterators"
103
104
105
106
107
108
109
110
111
112
	;;
    --all:* | *:0)
	echo >&2 "invalid arguments: $@"
	exit 1
	;;
    *)
	BENCH_DIRS=$@
	;;
esac

113
# Go through all benchmarks
114
115
for BENCH_DIR in $BENCH_DIRS; do
    generate_bench $BENCH_DIR
116
done