vpl_evaluate_setup.pl 1.2 KB
Newer Older
Guillaume Huard's avatar
Guillaume Huard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
my $compilation_code = q{
search() {
    needle=$1
    shift
    for hay in $*
    do
        if [ "$needle" = "$hay" ]
        then
            return 0
        fi
    done
    return 1
}

end() {
16
    if [ $(expr "$-" : '.*x') -eq 0 -a -n "$REMOVE$GENERATED_FILES" ]
Guillaume Huard's avatar
Guillaume Huard committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    then
        rm -r $REMOVE $GENERATED_FILES
    fi
    exit $1
}

exit_code=0
if [ -z "$FILES" ]
then
    FILES=*.c
fi
for file in $FILES
do
    base=$(basename $file .c)
31
    $CC $CPPFLAGS $CFLAGS -c $file || end $?
Guillaume Huard's avatar
Guillaume Huard committed
32
    GENERATED_FILES="$GENERATED_FILES $base.o"
33
34
35
36
37
38
39
40
41
    if [ -n "$WEAKEN_SYMBOLS" ] && search $file $VPL_SUBFILES
    then
        weaken_list=""
        for symbol in $WEAKEN_SYMBOLS
        do
            weaken_list="$weaken_list -W $symbol"
        done
        objcopy $weaken_list $base.o
    fi
Guillaume Huard's avatar
Guillaume Huard committed
42
done
43
$CC $LDFLAGS $GENERATED_FILES $LDLIBS -o $NAME || end $?
Guillaume Huard's avatar
Guillaume Huard committed
44
45
46
end 0
};

47
48
sub C_compilation(@) {
    return "#!/bin/bash\n".join('\n',@_)."\n".$compilation_code;
Guillaume Huard's avatar
Guillaume Huard committed
49
50
51
52
}

sub C_function_call($) {
    my $name = shift;
Guillaume Huard's avatar
Guillaume Huard committed
53
    return "#!/bin/bash\nfunction=$name\n".q{
Guillaume Huard's avatar
Guillaume Huard committed
54
55
56
57
58
59
60
61
62
63
64
65
66
dir=$(mktemp -d /tmp/programXXXXXX)
FILES="$FILES $dir/main.c"
REMOVE="$dir"
cat >$dir/main.c <<END
void $function();

int main() {
    $function();
    return 0;
}
END
}.$compilation_code;
}