Guillaume Martres | 3526f1c | 2013-08-13 18:46:58 -0700 | [diff] [blame] | 1 | #!/bin/sh |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2 | ## |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 3 | ## Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 4 | ## |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 5 | ## This source code is subject to the terms of the BSD 2 Clause License and |
| 6 | ## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 7 | ## was not distributed with this source code in the LICENSE file, you can |
| 8 | ## obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 9 | ## Media Patent License 1.0 was not distributed with this source code in the |
| 10 | ## PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 11 | ## |
| 12 | |
| 13 | |
| 14 | self=$0 |
| 15 | show_help() { |
| 16 | echo "usage: $self [options] <srcfile>" |
| 17 | echo |
| 18 | echo "Generate Makefile dependency information from assembly code source" |
| 19 | echo |
| 20 | exit 1 |
| 21 | } |
| 22 | die_unknown(){ |
| 23 | echo "Unknown option \"$1\"." |
| 24 | echo "See $0 --help for available options." |
| 25 | exit 1 |
| 26 | } |
| 27 | for opt do |
| 28 | optval="${opt#*=}" |
| 29 | case "$opt" in |
| 30 | --build-pfx=*) pfx="${optval}" |
| 31 | ;; |
| 32 | --depfile=*) out="${optval}" |
| 33 | ;; |
| 34 | -I*) raw_inc_paths="${raw_inc_paths} ${opt}" |
| 35 | inc_path="${inc_path} ${opt#-I}" |
| 36 | ;; |
| 37 | -h|--help) show_help |
| 38 | ;; |
| 39 | *) [ -f "$opt" ] && srcfile="$opt" |
| 40 | ;; |
| 41 | esac |
| 42 | done |
| 43 | |
| 44 | [ -n "$srcfile" ] || show_help |
| 45 | sfx=${sfx:-asm} |
John Koleszar | 4e06b0c | 2012-06-25 10:09:05 -0700 | [diff] [blame] | 46 | includes=$(LC_ALL=C egrep -i "include +\"?[a-z0-9_/]+\.${sfx}" $srcfile | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 47 | perl -p -e "s;.*?([a-z0-9_/]+.${sfx}).*;\1;") |
| 48 | #" restore editor state |
| 49 | for inc in ${includes}; do |
| 50 | found_inc_path= |
| 51 | for idir in ${inc_path}; do |
| 52 | [ -f "${idir}/${inc}" ] && found_inc_path="${idir}" && break |
| 53 | done |
| 54 | if [ -f `dirname $srcfile`/$inc ]; then |
| 55 | # Handle include files in the same directory as the source |
| 56 | $self --build-pfx=$pfx --depfile=$out ${raw_inc_paths} `dirname $srcfile`/$inc |
| 57 | elif [ -n "${found_inc_path}" ]; then |
| 58 | # Handle include files on the include path |
| 59 | $self --build-pfx=$pfx --depfile=$out ${raw_inc_paths} "${found_inc_path}/$inc" |
| 60 | else |
| 61 | # Handle generated includes in the build root (which may not exist yet) |
| 62 | echo ${out} ${out%d}o: "${pfx}${inc}" |
| 63 | fi |
| 64 | done |
| 65 | echo ${out} ${out%d}o: $srcfile |