Annotation of src/usr.bin/mkdep/mkdep.gcc.sh, Revision 1.17
1.1 deraadt 1: #!/bin/sh -
2: #
1.17 ! halex 3: # $OpenBSD: mkdep.gcc.sh,v 1.16 2012/08/29 16:51:12 guenther Exp $
1.1 deraadt 4: # $NetBSD: mkdep.gcc.sh,v 1.9 1994/12/23 07:34:59 jtc Exp $
5: #
6: # Copyright (c) 1991, 1993
7: # The Regents of the University of California. All rights reserved.
8: #
9: # Redistribution and use in source and binary forms, with or without
10: # modification, are permitted provided that the following conditions
11: # are met:
12: # 1. Redistributions of source code must retain the above copyright
13: # notice, this list of conditions and the following disclaimer.
14: # 2. Redistributions in binary form must reproduce the above copyright
15: # notice, this list of conditions and the following disclaimer in the
16: # documentation and/or other materials provided with the distribution.
1.12 millert 17: # 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 18: # may be used to endorse or promote products derived from this software
19: # without specific prior written permission.
20: #
21: # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: # SUCH DAMAGE.
32: #
33: # @(#)mkdep.gcc.sh 8.1 (Berkeley) 6/6/93
34: #
35:
1.13 otto 36: #
1.15 jmc 37: # Scan for a -o option in the arguments and record the filename given.
1.13 otto 38: # This is needed, since "cc -M -o out" writes to the file "out", not to
39: # stdout.
40: #
41: scanfordasho() {
42: while [ $# != 0 ]
43: do case "$1" in
44: -o)
45: file="$2"; shift; shift ;;
46: -o*)
47: file="${1#-o}"; shift ;;
48: *)
49: shift ;;
50: esac
51: done
52: }
53:
1.1 deraadt 54: D=.depend # default dependency file is .depend
55: append=0
56: pflag=
57:
58: while :
59: do case "$1" in
60: # -a appends to the depend file
61: -a)
62: append=1
63: shift ;;
64:
65: # -f allows you to select a makefile name
66: -f)
67: D=$2
68: shift; shift ;;
69:
70: # the -p flag produces "program: program.c" style dependencies
71: # so .o's don't get produced
72: -p)
73: pflag=p
74: shift ;;
75: *)
76: break ;;
77: esac
78: done
79:
80: if [ $# = 0 ] ; then
1.14 sobrado 81: echo 'usage: mkdep [-ap] [-f file] [flags] file ...'
1.1 deraadt 82: exit 1
83: fi
84:
1.13 otto 85: scanfordasho "$@"
1.11 pvalchev 86:
87: TMP=`mktemp /tmp/mkdep.XXXXXXXXXX` || exit 1
1.7 deraadt 88:
1.11 pvalchev 89: trap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
1.1 deraadt 90:
1.13 otto 91: if [ "x$file" = x ]; then
1.16 guenther 92: ${CC:-cc} -M "$@" > $TMP
1.13 otto 93: else
1.16 guenther 94: ${CC:-cc} -M "$@" && cat -- "$file" > $TMP
1.1 deraadt 95: fi
96:
97: if [ $? != 0 ]; then
98: echo 'mkdep: compile failed.'
1.11 pvalchev 99: rm -f $TMP
1.1 deraadt 100: exit 1
101: fi
102:
1.16 guenther 103: postproc() {
104: in=$1
105: if [ x$pflag = x ]; then
106: sed -e 's; \./; ;g' $in
107: else
108: sed -e 's;\.o[ ]*:; :;' -e 's; \./; ;g' $in
109: fi
110: }
111:
1.1 deraadt 112: if [ $append = 1 ]; then
1.16 guenther 113: postproc $TMP >> $D
1.7 deraadt 114: if [ $? != 0 ]; then
115: echo 'mkdep: append failed.'
1.11 pvalchev 116: rm -f $TMP
1.7 deraadt 117: exit 1
118: fi
1.1 deraadt 119: else
1.17 ! halex 120: postproc $TMP > $D
1.7 deraadt 121: if [ $? != 0 ]; then
122: echo 'mkdep: rename failed.'
1.11 pvalchev 123: rm -f $TMP
1.7 deraadt 124: exit 1
125: fi
1.1 deraadt 126: fi
1.7 deraadt 127:
1.11 pvalchev 128: rm -f $TMP
1.1 deraadt 129: exit 0