Annotation of src/usr.bin/mkdep/mkdep.gcc.sh, Revision 1.13
1.1 deraadt 1: #!/bin/sh -
2: #
1.13 ! otto 3: # $OpenBSD: mkdep.gcc.sh,v 1.12 2003/06/03 02:56:13 millert 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: #
! 37: # Scan for a -o option in the arguments are record the filename given.
! 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
81: echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...'
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
! 92: ${CC:-cc} -M "$@"
! 93: else
! 94: ${CC:-cc} -M "$@" && cat "$file"
! 95: fi |
1.1 deraadt 96: if [ x$pflag = x ]; then
1.13 ! otto 97: sed -e 's; \./; ;g' > $TMP
1.1 deraadt 98: else
1.13 ! otto 99: sed -e 's;\.o[ ]*:; :;' -e 's; \./; ;g' > $TMP
1.1 deraadt 100: fi
101:
102: if [ $? != 0 ]; then
103: echo 'mkdep: compile failed.'
1.11 pvalchev 104: rm -f $TMP
1.1 deraadt 105: exit 1
106: fi
107:
108: if [ $append = 1 ]; then
109: cat $TMP >> $D
1.7 deraadt 110: if [ $? != 0 ]; then
111: echo 'mkdep: append failed.'
1.11 pvalchev 112: rm -f $TMP
1.7 deraadt 113: exit 1
114: fi
1.1 deraadt 115: else
1.10 millert 116: mv -f $TMP $D
1.7 deraadt 117: if [ $? != 0 ]; then
118: echo 'mkdep: rename failed.'
1.11 pvalchev 119: rm -f $TMP
1.7 deraadt 120: exit 1
121: fi
1.1 deraadt 122: fi
1.7 deraadt 123:
1.11 pvalchev 124: rm -f $TMP
1.1 deraadt 125: exit 0