1#!/bin/bash
2##
3##  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4##
5##  Use of this source code is governed by a BSD-style license
6##  that can be found in the LICENSE file in the root of the source
7##  tree. An additional intellectual property rights grant can be found
8##  in the file PATENTS.  All contributing project authors may
9##  be found in the AUTHORS file in the root of the source tree.
10##
11
12
13self=$0
14self_basename=${self##*/}
15EOL=$'\n'
16
17show_help() {
18    cat <<EOF
19Usage: ${self_basename} [options] file1 [file2 ...]
20
21This script generates a MSVC module definition file containing a list of symbols
22to export from a DLL. Source files are technically bash scripts (and thus may
23use #comment syntax) but in general, take the form of a list of symbols:
24
25  <kind> symbol1 [symbol2, symbol3, ...]
26
27where <kind> is either 'text' or 'data'
28
29
30Options:
31    --help                      Print this message
32    --out=filename              Write output to a file [stdout]
33    --name=project_name         Name of the library (required)
34EOF
35    exit 1
36}
37
38die() {
39    echo "${self_basename}: $@"
40    exit 1
41}
42
43die_unknown(){
44    echo "Unknown option \"$1\"."
45    echo "See ${self_basename} --help for available options."
46    exit 1
47}
48
49text() {
50    for sym in "$@"; do
51        echo "  $sym" >> ${outfile}
52    done
53}
54
55data() {
56    for sym in "$@"; do
57        printf "  %-40s DATA\n" "$sym" >> ${outfile}
58    done
59}
60
61# Process command line
62for opt in "$@"; do
63    optval="${opt#*=}"
64    case "$opt" in
65    --help|-h) show_help
66    ;;
67    --out=*) outfile="$optval"
68    ;;
69    --name=*) name="${optval}"
70    ;;
71     -*) die_unknown $opt
72    ;;
73    *) file_list[${#file_list[@]}]="$opt"
74    esac
75done
76outfile=${outfile:-/dev/stdout}
77[ -n "$name" ] || die "Library name (--name) must be specified!"
78
79echo "LIBRARY ${name}" > ${outfile}
80echo "EXPORTS" >> ${outfile}
81for f in "${file_list[@]}"; do
82    . $f
83done
84