summaryrefslogtreecommitdiffstats
path: root/build-aux/xdrgen
blob: 010df65637768008e78f985d62e4c00564556403 (plain)
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
#!/bin/sh

# error out if an error occurs
set -e

append_licence_header ()
{
    local src_file=$1;
    local dst_file=$2;

    cat >$dst_file <<EOF
/*
  Copyright (c) 2007-2016 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/

#include "compat.h"

#if defined(__GNUC__)
#if __GNUC__ >= 4
#if !defined(__clang__)
#if !defined(__NetBSD__)
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#else
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-value"
#endif
#endif
#endif

EOF

    cat $src_file >> $dst_file;

}

gen_sources ()
{
    local xfile="$1";

    local cfile="${1%.x}.c";
    local hfile="${1%.x}.h";

    local tmp_cfile="$1.c.tmp";
    local tmp_hfile="$1.h.tmp";

    rm -f $cfile;
    rpcgen -c -o $cfile $xfile;
    append_licence_header $cfile $tmp_cfile;
    mv $tmp_cfile $cfile;
    # remove unwanted temporary files (if any)
    rm -f $tmp_cfile;
    echo "Generated $cfile"
    return
}

gen_headers ()
{
    local xfile="$1";

    local cfile="${1%.x}.c";
    local hfile="${1%.x}.h";

    local tmp_cfile="$1.c.tmp";
    local tmp_hfile="$1.h.tmp";

    # no need for a temporary file here as there are no changes from glusterfs
    rm -f $hfile;
    rpcgen -h -o $hfile $xfile;
    # the '#ifdef' part of file should be fixed
    sed -r -e '/#(ifdef|ifndef|define)/s/-/_/g' $hfile > ${hfile}.new && mv ${hfile}.new $hfile;
    # Gen header to temp file and append generated file
    append_licence_header $hfile $tmp_hfile;
    # now move the destination file to actual original file
    mv $tmp_hfile $hfile;
    rm -f $tmp_hfile;
    echo "Generated $hfile";
    return
}

main ()
{
    if [ $# -ne 2 ]; then
        echo "wrong number of arguments given"
        echo " $0 [header|source] <XDR-definition-file>.x"
        exit 1;
    fi

    if [ $1 = "header" ]; then
        gen_headers $2
    fi

    if [ $1 = "source" ]; then
        gen_sources $2
    fi
}

main "$@";