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