1 | #!/bin/ksh |
---|
2 | # $Id: depend.sh,v 1.10.16.2 2006/10/06 22:33:17 yuri Exp $ |
---|
3 | ## ###################################################################### ## |
---|
4 | ## Copyright IBM 1993 ## |
---|
5 | ## ###################################################################### ## |
---|
6 | |
---|
7 | #set nonomatch |
---|
8 | ################################################ |
---|
9 | if [ $# -lt 2 ] || [ $# -gt 5 ]; then |
---|
10 | echo 'usage: depends $DEPEND $INCLUDES [$DEFINES [$KDEFINES [$PKDEFINES]]]' |
---|
11 | exit 1 |
---|
12 | fi |
---|
13 | ################################################ |
---|
14 | DEPEND="$1" |
---|
15 | INCLUDES="$2" |
---|
16 | DEFINES="$3" |
---|
17 | KDEFINES="$4" |
---|
18 | PKDEFINES="$5" |
---|
19 | |
---|
20 | ################################################ |
---|
21 | CFILES=$(/bin/ls *.[cC]) |
---|
22 | if [ "$CFILES" = "" ]; then |
---|
23 | echo "No Dependencies to Check ...continuing...." |
---|
24 | exit 0 |
---|
25 | fi |
---|
26 | ################################################ |
---|
27 | CDEPENDS=/tmp/Dep1_$$ |
---|
28 | DEPENDERR=/tmp/Dep2_$$ |
---|
29 | DEPENDS=.depends |
---|
30 | ################################################ |
---|
31 | |
---|
32 | # make backup copy of makefile and remove old dependencies |
---|
33 | mv makefile makefile.BAK |
---|
34 | sed -n -e '1,/##### DEPENDENCY LINE - DO NOT DELETE #####/p' makefile.BAK > makefile |
---|
35 | |
---|
36 | # run the compiler with option to generate dependencies |
---|
37 | # output goes into $CDEPENDS, error messages go into $DEPENDERR |
---|
38 | if [[ $DEFINES = *GPFS_LINUX* ]] |
---|
39 | then |
---|
40 | rm -f *.d >/dev/null 2>&1 |
---|
41 | $DEPEND -w -MD -E >/dev/null $DEFINES $INCLUDES $CFILES 2> $DEPENDERR |
---|
42 | echo "" > $CDEPENDS |
---|
43 | cat *.d >> $CDEPENDS |
---|
44 | rm -f *.d >/dev/null 2>&1 |
---|
45 | else |
---|
46 | rm -f *.u >/dev/null 2>&1 |
---|
47 | $DEPEND -qonce -M -E >/dev/null $DEFINES $INCLUDES $CFILES 2> $DEPENDERR |
---|
48 | echo "" > $CDEPENDS |
---|
49 | cat *.u >> $CDEPENDS |
---|
50 | rm -f *.u >/dev/null 2>&1 |
---|
51 | fi |
---|
52 | |
---|
53 | # show error messages, but filter out certain uninteresting messages |
---|
54 | fgrep -v -e 'unknown directive == "#error' \ |
---|
55 | -e 'Option lm is not valid' \ |
---|
56 | -e 'Suboption compat is not valid for option langlvl' $DEPENDERR |
---|
57 | |
---|
58 | # Copy output to $DEPENDS |
---|
59 | "cp" $CDEPENDS $DEPENDS |
---|
60 | |
---|
61 | # remove temporary output files |
---|
62 | for i in $CDEPENDS $DEPENDERR |
---|
63 | do |
---|
64 | rm -f $i $i.bak |
---|
65 | done |
---|
66 | |
---|
67 | # If $KDEFINES is non-empty, certain files need to be compiled |
---|
68 | # twice: once without and once with $KDEFINES to generate .ko file to |
---|
69 | # be linked into kernel code. If this is the case, we need to generate |
---|
70 | # dependencies for the .ko files. |
---|
71 | if [[ "$KDEFINES" != "" ]] |
---|
72 | then |
---|
73 | # generate dependencies with $KDEFINES |
---|
74 | if [[ $DEFINES = *GPFS_LINUX* ]]; then |
---|
75 | rm -f *.d >/dev/null 2>&1 |
---|
76 | $DEPEND -w -MD -E >/dev/null $KDEFINES $INCLUDES $CFILES 2> $DEPENDERR |
---|
77 | echo "" > $CDEPENDS |
---|
78 | cat *.d >> $CDEPENDS |
---|
79 | rm -f *.d >/dev/null 2>&1 |
---|
80 | else |
---|
81 | rm -f *.u >/dev/null 2>&1 |
---|
82 | $DEPEND -qonce -M -E >/dev/null $KDEFINES $INCLUDES $CFILES 2> $DEPENDERR |
---|
83 | echo "" > $CDEPENDS |
---|
84 | cat *.u >> $CDEPENDS |
---|
85 | rm -f *.u >/dev/null 2>&1 |
---|
86 | fi |
---|
87 | |
---|
88 | # show error messages, but filter out certain uninteresting messages |
---|
89 | fgrep -v -e 'unknown directive == "#error' \ |
---|
90 | -e 'Suboption compat is not valid for option langlvl' $DEPENDERR |
---|
91 | |
---|
92 | # Append output to $DEPENDS, but change ".o:" to ".ko:" |
---|
93 | sed -e 's/\.o:/.ko:/g' $CDEPENDS >> $DEPENDS |
---|
94 | |
---|
95 | # remove temporary output files |
---|
96 | for i in $CDEPENDS $DEPENDERR |
---|
97 | do |
---|
98 | rm -f $i $i.bak |
---|
99 | done |
---|
100 | fi |
---|
101 | |
---|
102 | # On Linux, if $PKDEFINES is non-empty, also generate dependencies |
---|
103 | # for .pko files. |
---|
104 | if [[ "$PKDEFINES" != "" ]] |
---|
105 | then |
---|
106 | # generate dependencies with $KDEFINES and $PKDEFINES |
---|
107 | if [[ $DEFINES = *GPFS_LINUX* ]]; then |
---|
108 | rm -f *.d >/dev/null 2>&1 |
---|
109 | $DEPEND -w -MD -E >/dev/null $KDEFINES $PKDEFINES $INCLUDES $CFILES 2> $DEPENDERR |
---|
110 | echo "" > $CDEPENDS |
---|
111 | cat *.d >> $CDEPENDS |
---|
112 | rm -f *.d >/dev/null 2>&1 |
---|
113 | else |
---|
114 | rm -f *.u >/dev/null 2>&1 |
---|
115 | $DEPEND -qonce -M -E >/dev/null $PKDEFINES $INCLUDES $CFILES 2> $DEPENDERR |
---|
116 | echo "" > $CDEPENDS |
---|
117 | cat *.u >> $CDEPENDS |
---|
118 | rm -f *.u >/dev/null 2>&1 |
---|
119 | fi |
---|
120 | |
---|
121 | # show error messages, but filter out certain uninteresting messages |
---|
122 | fgrep -v -e 'unknown directive == "#error' \ |
---|
123 | -e 'Suboption compat is not valid for option langlvl' $DEPENDERR |
---|
124 | |
---|
125 | # Append output to $DEPENDS, but change ".o:" to ".pko:" |
---|
126 | sed -e 's/\.o:/.pko:/g' $CDEPENDS >> $DEPENDS |
---|
127 | |
---|
128 | # remove temporary output files |
---|
129 | for i in $CDEPENDS $DEPENDERR |
---|
130 | do |
---|
131 | rm -f $i $i.bak |
---|
132 | done |
---|
133 | fi |
---|
134 | |
---|
135 | # append all the dependencies to the makefile |
---|
136 | cat $DEPENDS >> makefile |
---|