Debian Codegraph @

tools/mkdep.sh

raw
1 #!/bin/sh
2 # Copyright 2018 Google Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Generate make dependencies using C preprocessor.
17 # Usage:
18 # mkdep.sh cc cc_args_to_invoke_preprocessor... file.{[csh],cc} ...
19 # Output is written to stdout.
20
21 # Implemented with sh, expr, sed, and sort.
22
23 c_cmd=
24 cpp_cmd=
25 for x in ${1+"$@"}; do
26 case "$x" in
27 *.[chsCHS]|*.cc|*.CC) ;;
28 -c++=*) cpp_cmd="$cpp_cmd '`expr "$x" : '^.....\(.*\)$'`'";;
29 *) c_cmd="$c_cmd '$x'"
30 cpp_cmd="$cpp_cmd '$x'";;
31 esac
32 done
33
34 # Write to stdout dependencies obtained by running each source file through the
35 # C preprocessor using the command prefix from the command line.
36 for file in ${1+"$@"}; do
37 case "$file" in
38 *.[chsCHS]|*.cc|*.CC)
39 case "$file" in
40 *.cc|*.CC) cmd="$cpp_cmd";;
41 *) cmd="$c_cmd";;
42 esac
43
44 ext=`expr "$file" : '^.*[.]\([^.]*\)$'`
45 basename=`expr "$file" : '^\(.*\)[.][^.]*$'` # remove extension
46 case "$basename" in
47 */*) basename=`expr "$basename" : '.*/\([^/]*\)$'`;;
48 esac
49
50 eval "$cmd" "'$file'" |
51 sed '
52 s/^#line 1 "/# 1 "/
53 /^# 1 "[^<]/!d
54 s/^# 1 \(".*"\).*$/\1/
55 / /!s/^"\(.*\)"$/\1/
56 p
57 ' |
58 sort -u |
59 sed '1i\
60 '"$basename.o"': \\
61 s/^/ /
62 $!s/$/ \\/
63 '
64 ;;
65 esac
66 done