blob: 1486b185aa4341c22f88fbc60755284b6ac25442 [file] [log] [blame]
The Android Open Source Project478ab6c2009-03-03 19:30:05 -08001#!/bin/sh -
2#
3# Copyright (c) 1994, 1996
4# The Regents of the University of California. All rights reserved.
5#
6# Redistribution and use in source and binary forms are permitted
7# provided that this notice is preserved and that due credit is given
8# to the University of California at Berkeley. The name of the University
9# may not be used to endorse or promote products derived from this
10# software without specific prior written permission. This software
11# is provided ``as is'' without express or implied warranty.
12#
13# @(#)mkdep.sh 5.11 (Berkeley) 5/5/88
14#
15
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080016MAKE=Makefile # default makefile name is "Makefile"
17CC=cc # default C compiler is "cc"
JP Abgrall511eca32014-02-12 13:46:45 -080018DEPENDENCY_CFLAG=-M # default dependency-generation flag is -M
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080019
20while :
21 do case "$1" in
22 # -c allows you to specify the C compiler
23 -c)
24 CC=$2
25 shift; shift ;;
26
27 # -f allows you to select a makefile name
28 -f)
29 MAKE=$2
30 shift; shift ;;
31
JP Abgrall511eca32014-02-12 13:46:45 -080032 # -m allows you to specify the dependency-generation flag
33 -m)
34 DEPENDENCY_CFLAG=$2
35 shift; shift ;;
36
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080037 # the -p flag produces "program: program.c" style dependencies
38 # so .o's don't get produced
39 -p)
40 SED='s;\.o;;'
41 shift ;;
42 *)
43 break ;;
44 esac
45done
46
47if [ $# = 0 ] ; then
JP Abgrall511eca32014-02-12 13:46:45 -080048 echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [flags] file ...'
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080049 exit 1
50fi
51
52if [ ! -w $MAKE ]; then
53 echo "mkdep: no writeable file \"$MAKE\""
54 exit 1
55fi
56
57TMP=/tmp/mkdep$$
58
59trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
60
61cp $MAKE ${MAKE}.bak
62
63sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
64
65cat << _EOF_ >> $TMP
66# DO NOT DELETE THIS LINE -- mkdep uses it.
67# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
68
69_EOF_
70
71# If your compiler doesn't have -M, add it. If you can't, the next two
72# lines will try and replace the "cc -M". The real problem is that this
73# hack can't deal with anything that requires a search path, and doesn't
74# even try for anything using bracket (<>) syntax.
75#
76# egrep '^#include[ ]*".*"' /dev/null $* |
77# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
78
79# XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
JP Abgrall511eca32014-02-12 13:46:45 -080080$CC $DEPENDENCY_CFLAG $* |
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080081sed "
82 s; \./; ;g
83 $SED" |
84awk '{
85 if ($1 != prev) {
86 if (rec != "")
87 print rec;
88 rec = $0;
89 prev = $1;
90 }
91 else {
92 if (length(rec $2) > 78) {
93 print rec;
94 rec = $0;
95 }
96 else
97 rec = rec " " $2
98 }
99}
100END {
101 print rec
102}' >> $TMP
103
104cat << _EOF_ >> $TMP
105
106# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
107_EOF_
108
109# copy to preserve permissions
110cp $TMP $MAKE
111rm -f ${MAKE}.bak $TMP
112exit 0