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 13 self=$0 14 show_help() { 15 echo "usage: $self [options] <srcfile>" 16 echo 17 echo "Generate Makefile dependency information from assembly code source" 18 echo 19 exit 1 20 } 21 die_unknown(){ 22 echo "Unknown option \"$1\"." 23 echo "See $0 --help for available options." 24 exit 1 25 } 26 for opt do 27 optval="${opt#*=}" 28 case "$opt" in 29 --build-pfx=*) pfx="${optval}" 30 ;; 31 --depfile=*) out="${optval}" 32 ;; 33 -I*) raw_inc_paths="${raw_inc_paths} ${opt}" 34 inc_path="${inc_path} ${opt#-I}" 35 ;; 36 -h|--help) show_help 37 ;; 38 *) [ -f "$opt" ] && srcfile="$opt" 39 ;; 40 esac 41 done 42 43 [ -n "$srcfile" ] || show_help 44 sfx=${sfx:-asm} 45 includes=$(LC_ALL=C egrep -i "include +\"?[a-z0-9_/]+\.${sfx}" $srcfile | 46 perl -p -e "s;.*?([a-z0-9_/]+.${sfx}).*;\1;") 47 #" restore editor state 48 for inc in ${includes}; do 49 found_inc_path= 50 for idir in ${inc_path}; do 51 [ -f "${idir}/${inc}" ] && found_inc_path="${idir}" && break 52 done 53 if [ -f `dirname $srcfile`/$inc ]; then 54 # Handle include files in the same directory as the source 55 $self --build-pfx=$pfx --depfile=$out ${raw_inc_paths} `dirname $srcfile`/$inc 56 elif [ -n "${found_inc_path}" ]; then 57 # Handle include files on the include path 58 $self --build-pfx=$pfx --depfile=$out ${raw_inc_paths} "${found_inc_path}/$inc" 59 else 60 # Handle generated includes in the build root (which may not exist yet) 61 echo ${out} ${out%d}o: "${pfx}${inc}" 62 fi 63 done 64 echo ${out} ${out%d}o: $srcfile 65