blob: c867cc2bf55c6bdf893c491713eaa7f661318685 [file] [log] [blame]
Guillaume Martres3526f1c2013-08-13 18:46:58 -07001#!/bin/sh
John Koleszar0ea50ce2010-05-18 11:58:33 -04002##
Yaowu Xu9c01aa12016-09-01 14:32:49 -07003## Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar0ea50ce2010-05-18 11:58:33 -04004##
Yaowu Xu9c01aa12016-09-01 14:32:49 -07005## 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 Koleszar0ea50ce2010-05-18 11:58:33 -040011##
12
13
14self=$0
15show_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}
22die_unknown(){
23 echo "Unknown option \"$1\"."
24 echo "See $0 --help for available options."
25 exit 1
26}
27for 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
42done
43
44[ -n "$srcfile" ] || show_help
45sfx=${sfx:-asm}
John Koleszar4e06b0c2012-06-25 10:09:05 -070046includes=$(LC_ALL=C egrep -i "include +\"?[a-z0-9_/]+\.${sfx}" $srcfile |
John Koleszar0ea50ce2010-05-18 11:58:33 -040047 perl -p -e "s;.*?([a-z0-9_/]+.${sfx}).*;\1;")
48#" restore editor state
49for 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
64done
65echo ${out} ${out%d}o: $srcfile