build-sys: no need to install native-messages.h.
[profile/ivi/speech-recognition.git] / build-aux / gen-linker-script.ctags
1 #!/bin/bash
2
3 ###############
4 # Generate a linker script for GNU ld.
5 #
6 #
7 #
8
9
10
11 error () {
12     echo "error: $*" 1>&2
13 }
14
15 info () {
16     echo "$*" 1>&2
17 }
18
19 warning () {
20     echo "warning: $*" 1>&2
21 }
22
23 usage () {
24     info "usage: $0 [-p <pattern>] [-I <ignore-list>] -o <output> <inputs>"
25     exit ${1:-1}
26 }
27
28 emit () {
29     echo "$*" >> $OUTPUT
30 }
31
32
33 # set up defaults
34 PATTERN="^mrp_|^_mrp_"                # export everything prefixed with mrp_
35 IGNORE="MRP_PRINTF_LIKE,MRP_NULLTERM" # ignore these symbols/macros
36 IT=","                                # ignore-list is comma-separated
37 SOURCES=""                            # no default input, must be specified
38 OUTPUT=""                             # no default output, must be specified
39
40 # parse command line
41 while [ -n "${1#-}" ]; do
42     case $1 in
43         -o)
44             if [ -z "$OUTPUT" ]; then
45                 shift
46                 OUTPUT="$1"
47             else
48                 error "Multiple output files requested."
49                 usage
50             fi
51             ;;
52         -p)
53             shift;
54             PATTERN="$1"
55             ;;
56         -I)
57             shift
58             IGNORE="$IGNORE$IT$1"
59             IT=","
60             ;;
61         -h)
62             usage 0
63             ;;
64         -q)
65             QUIET="yes"
66             ;;
67         -c)
68             # This is only for command-line compatibility with collect-symbols
69             # to minimize the impact of switching back and forth (if needed).
70             # collect-symbols gets compilation flags passed using the -c
71             # option which we simply ignore here when using ctags.
72             shift
73             ;;
74         -*)
75             error "Unknown option '$1'."
76             usage
77             ;;
78         *)
79             SOURCES="$SOURCES $1"
80             ;;
81     esac
82     shift
83 done
84
85 # check that we've got everything mandatory
86 if [ -z "$OUTPUT" ]; then
87     error "No output file specified (use the -o option)."
88     usage
89 fi
90
91 if [ -z "$SOURCES" ]; then
92     warning "No input files, generating local-only linker script."
93     emit "{"
94     emit "    local:"
95     emit "        *;"
96     emit "};"
97     exit 0
98 fi
99
100 if [ -z "$PATTERN" ]; then
101     PATTERN="^mrp_"
102 fi
103
104 if [ -n "$IGNORE" ]; then
105     ignore_opts="-I $IGNORE"
106 else
107     ignore_opts=""
108 fi
109
110 # check that we have ctags
111 which ctags >& /dev/null
112 if [ "$?" != "0" ]; then
113     error "Needs ctags to regenerate linker script $OUTPUT..."
114     exit 1
115 fi
116
117 # generate the output
118 [ -n "$QUIET" ] || info "Generating linker script $OUTPUT..."
119 rm -f $OUTPUT
120 touch $OUTPUT
121
122 emit "{"
123 emit "    global:"
124 ctags $ignore_opts -f - --c-kinds=px $SOURCES | \
125     awk "/$PATTERN/ { print \$1; }" | \
126         sort | \
127             while read sym; do
128                 emit "        $sym;"
129             done
130
131 emit "    local:"
132 emit "        *;"
133 emit "};"