John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | ## Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | ## |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | ## This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | ## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | ## was not distributed with this source code in the LICENSE file, you can |
| 7 | ## obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | ## Media Patent License 1.0 was not distributed with this source code in the |
| 9 | ## PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 10 | ## |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 11 | |
| 12 | self=$0 |
| 13 | self_basename=${self##*/} |
| 14 | EOL=$'\n' |
| 15 | |
| 16 | show_help() { |
| 17 | cat <<EOF |
| 18 | Usage: ${self_basename} [options] file1 [file2 ...] |
| 19 | |
| 20 | This script generates a MSVC module definition file containing a list of symbols |
| 21 | to export from a DLL. Source files are technically bash scripts (and thus may |
| 22 | use #comment syntax) but in general, take the form of a list of symbols: |
| 23 | |
| 24 | <kind> symbol1 [symbol2, symbol3, ...] |
| 25 | |
| 26 | where <kind> is either 'text' or 'data' |
| 27 | |
| 28 | |
| 29 | Options: |
| 30 | --help Print this message |
| 31 | --out=filename Write output to a file [stdout] |
| 32 | --name=project_name Name of the library (required) |
| 33 | EOF |
| 34 | exit 1 |
| 35 | } |
| 36 | |
| 37 | die() { |
| 38 | echo "${self_basename}: $@" |
| 39 | exit 1 |
| 40 | } |
| 41 | |
| 42 | die_unknown(){ |
| 43 | echo "Unknown option \"$1\"." |
| 44 | echo "See ${self_basename} --help for available options." |
| 45 | exit 1 |
| 46 | } |
| 47 | |
| 48 | text() { |
| 49 | for sym in "$@"; do |
| 50 | echo " $sym" >> ${outfile} |
| 51 | done |
| 52 | } |
| 53 | |
| 54 | data() { |
| 55 | for sym in "$@"; do |
| 56 | printf " %-40s DATA\n" "$sym" >> ${outfile} |
| 57 | done |
| 58 | } |
| 59 | |
| 60 | # Process command line |
| 61 | for opt in "$@"; do |
| 62 | optval="${opt#*=}" |
| 63 | case "$opt" in |
| 64 | --help|-h) show_help |
| 65 | ;; |
| 66 | --out=*) outfile="$optval" |
| 67 | ;; |
| 68 | --name=*) name="${optval}" |
| 69 | ;; |
| 70 | -*) die_unknown $opt |
| 71 | ;; |
| 72 | *) file_list[${#file_list[@]}]="$opt" |
| 73 | esac |
| 74 | done |
| 75 | outfile=${outfile:-/dev/stdout} |
| 76 | [ -n "$name" ] || die "Library name (--name) must be specified!" |
| 77 | |
| 78 | echo "LIBRARY ${name}" > ${outfile} |
| 79 | echo "EXPORTS" >> ${outfile} |
| 80 | for f in "${file_list[@]}"; do |
| 81 | . $f |
| 82 | done |