1 | |
---|
2 | #set -x |
---|
3 | #set -v |
---|
4 | #echo $* |
---|
5 | |
---|
6 | #-------------------------------------------------- |
---|
7 | build_deps () |
---|
8 | #-------------------------------------------------- |
---|
9 | # Build the dependency line. |
---|
10 | # |
---|
11 | # Globals : |
---|
12 | # |
---|
13 | # includes list of -I<path> preprocessor options |
---|
14 | # format_filter sed commands for cleaning up the cpp output |
---|
15 | # include_filter sed commands for formatting include statements |
---|
16 | # |
---|
17 | # Inputs : |
---|
18 | # |
---|
19 | # file Source file to apply |
---|
20 | # |
---|
21 | # Output : |
---|
22 | # |
---|
23 | # $(src)source $(inc)dep1 ... |
---|
24 | # |
---|
25 | #-------------------------------------------------- |
---|
26 | { |
---|
27 | # |
---|
28 | # $1 = source file |
---|
29 | # |
---|
30 | |
---|
31 | if test -d ../src ; then |
---|
32 | srcdir=../src |
---|
33 | else |
---|
34 | srcdir=./ |
---|
35 | fi |
---|
36 | |
---|
37 | file=$1 |
---|
38 | shift |
---|
39 | |
---|
40 | # echo "makedepend ${includes} ${srcdir}/${file}" >x$$ |
---|
41 | |
---|
42 | touch t$$ |
---|
43 | eval makedepend ${includes} ${srcdir}/${file} -ft$$ |
---|
44 | |
---|
45 | line=`cat t$$ | egrep -v '^#' | sed -e "$format_filter" -e "$include_filter"` |
---|
46 | |
---|
47 | /bin/rm -f t$$* |
---|
48 | |
---|
49 | line=`echo '$(src)'${file}; echo ${line}` |
---|
50 | |
---|
51 | line=`echo ${line} | sed 's#$(inc)#$(src)#'` |
---|
52 | |
---|
53 | echo $line |
---|
54 | } |
---|
55 | |
---|
56 | #-------------------------------------------------- |
---|
57 | genmake_package () |
---|
58 | #-------------------------------------------------- |
---|
59 | { |
---|
60 | |
---|
61 | if test -d ../src ; then |
---|
62 | srcdir=../src |
---|
63 | else |
---|
64 | srcdir=./ |
---|
65 | fi |
---|
66 | |
---|
67 | if test -d ../mgr ; then |
---|
68 | mgrdir=../mgr/ |
---|
69 | else |
---|
70 | mgrdir=`pwd`/ |
---|
71 | fi |
---|
72 | |
---|
73 | if test -d ../include ; then |
---|
74 | incdir=../include |
---|
75 | else |
---|
76 | if test -d ../src ; then |
---|
77 | incdir=../src |
---|
78 | else |
---|
79 | incdir=./ |
---|
80 | fi |
---|
81 | fi |
---|
82 | |
---|
83 | if test "$is_executable" = 1 ; then |
---|
84 | title='Executable' |
---|
85 | else |
---|
86 | title='Package' |
---|
87 | fi |
---|
88 | |
---|
89 | #---- Define output file. ----------------------------------------- |
---|
90 | |
---|
91 | package=$1 |
---|
92 | shift |
---|
93 | |
---|
94 | if test "$#" = 0 ; then |
---|
95 | sources=`(cd ../src; ls ${PACKTARGET}*.c)` |
---|
96 | else |
---|
97 | sources="$*" |
---|
98 | fi |
---|
99 | |
---|
100 | echo $title $PACKTARGET |
---|
101 | |
---|
102 | #---- Prepare the use context. ------------------------------------ |
---|
103 | |
---|
104 | uses=`${CMTROOT}/mgr/cmt includes` |
---|
105 | |
---|
106 | includes="-I${incdir} ${uses} ${PACKINCLUDES}" |
---|
107 | |
---|
108 | # echo "includes = [" ${includes} "]" |
---|
109 | |
---|
110 | # Remove trailing back-slashes |
---|
111 | # Remove target |
---|
112 | # Substitute ../src/ and ../include/ by $(inc) |
---|
113 | |
---|
114 | format_filter='s#\\##g |
---|
115 | s#[^:]*:## |
---|
116 | s#/usr/local/[^ ]*[ ]##g |
---|
117 | s#/usr/local/.*$##g |
---|
118 | s#/usr/include/[^ ]*[ ]##g |
---|
119 | s#/usr/include/.*$##g |
---|
120 | s#\.\./src/#$(inc)#g |
---|
121 | s#/src/#/OS9/#g' |
---|
122 | |
---|
123 | # Substitute all "<path>/<package>/<version>/" |
---|
124 | # by "$(<PACKAGE>ROOT)/" |
---|
125 | |
---|
126 | include_filter=`${CMTROOT}/mgr/cmt filter_includes -quiet | sed 's#//#/#g'` |
---|
127 | |
---|
128 | # |
---|
129 | # Other initializations. |
---|
130 | # |
---|
131 | |
---|
132 | src='$(src)' |
---|
133 | inc='$(inc)' |
---|
134 | bin='$(bin)' |
---|
135 | rels='$(rels)' |
---|
136 | mgr='$(mgr)' |
---|
137 | |
---|
138 | if test "$is_library" = 1 ; then |
---|
139 | lib='$(lib)lib'${PACKTARGET}'.l' |
---|
140 | libstamp='$('${PACKTARGET}'stamp)' |
---|
141 | shlibstamp='$('${PACKTARGET}'shstamp)' |
---|
142 | else |
---|
143 | linkopts='$('${PACKTARGET}'linkopts)' |
---|
144 | stamps='$('${PACKTARGET}'stamps)' |
---|
145 | fi |
---|
146 | |
---|
147 | unset ccs |
---|
148 | unset CCs |
---|
149 | unset yaccs |
---|
150 | unset lexs |
---|
151 | unset objs |
---|
152 | unset protos |
---|
153 | unset protonames |
---|
154 | unset protostamps |
---|
155 | unset cyaccs |
---|
156 | unset clexs |
---|
157 | unset os9sources |
---|
158 | unset linkmacro |
---|
159 | unset subdir |
---|
160 | |
---|
161 | # |
---|
162 | # Scan the sources. |
---|
163 | # |
---|
164 | |
---|
165 | for file in $sources ; do |
---|
166 | echo $file | grep '^-s=' |
---|
167 | if test "$?" = "0" ; then |
---|
168 | subdir=`echo $file | sed -e 's#^-s=##' -e 's#[/]*$#/#'` |
---|
169 | else |
---|
170 | suffix=`echo $file | sed 's/^.*\.//'` |
---|
171 | name=`echo $file | sed 's/\..*//'` |
---|
172 | oname="$name" |
---|
173 | |
---|
174 | if test "$linkmacro" = "" ; then |
---|
175 | if test "$suffix" = "f" ; then |
---|
176 | linkmacro='$(flink)' |
---|
177 | elif test "$suffix" = "F" ; then |
---|
178 | linkmacro='$(flink)' |
---|
179 | elif test "$suffix" = "c" ; then |
---|
180 | linkmacro='$(clink)' |
---|
181 | elif test "$suffix" = "C" ; then |
---|
182 | linkmacro='$(cpplink)' |
---|
183 | elif test "$suffix" = "cc" ; then |
---|
184 | linkmacro='$(cpplink)' |
---|
185 | elif test "$suffix" = "cxx" ; then |
---|
186 | linkmacro='$(cpplink)' |
---|
187 | else |
---|
188 | linkmacro='none' |
---|
189 | fi |
---|
190 | fi |
---|
191 | |
---|
192 | if test "$suffix" = "f" ; then |
---|
193 | fs="$fs ${subdir}$file" |
---|
194 | elif test "$suffix" = "F" ; then |
---|
195 | fs="$fs ${subdir}$file" |
---|
196 | elif test "$suffix" = "c" ; then |
---|
197 | ccs="$ccs ${subdir}$file" |
---|
198 | elif test "$suffix" = "C" ; then |
---|
199 | CCs="$CCs ${subdir}$file" |
---|
200 | elif test "$suffix" = "cc" ; then |
---|
201 | CCs="$CCs ${subdir}$file" |
---|
202 | elif test "$suffix" = "cxx" ; then |
---|
203 | CCs="$CCs ${subdir}$file" |
---|
204 | elif test "$suffix" = "y" ; then |
---|
205 | yaccs="$yaccs ${subdir}$file" |
---|
206 | name=`echo $name | sed 's/Parse$//'` |
---|
207 | ccs="$ccs ${subdir}${name}Parse.c" |
---|
208 | oname="${name}Parse" |
---|
209 | elif test "$suffix" = "l" ; then |
---|
210 | lexs="$lexs ${subdir}$file" |
---|
211 | name=`echo $name | sed 's/Lex$//'` |
---|
212 | ccs="$ccs ${subdir}${name}Lex.c" |
---|
213 | oname="${name}Lex" |
---|
214 | fi |
---|
215 | |
---|
216 | obj="${rels}${oname}.r" |
---|
217 | |
---|
218 | objs="$objs $obj" |
---|
219 | fi |
---|
220 | |
---|
221 | done |
---|
222 | |
---|
223 | #------------------------------------------- |
---|
224 | # |
---|
225 | # Start the output. |
---|
226 | # |
---|
227 | #------------------------------------------- |
---|
228 | |
---|
229 | d=`date` |
---|
230 | |
---|
231 | cat <<END >$output |
---|
232 | |
---|
233 | #==================================== |
---|
234 | # $title $PACKTARGET |
---|
235 | # |
---|
236 | # Generated $d by $USER |
---|
237 | # |
---|
238 | #==================================== |
---|
239 | |
---|
240 | END |
---|
241 | |
---|
242 | pobjs='$('${PACKTARGET}'OBJS)' |
---|
243 | |
---|
244 | if test "$is_library" = 1 ; then |
---|
245 | |
---|
246 | cat <<END >>${output} |
---|
247 | |
---|
248 | ${PACKTARGET}OBJS = ${objs} |
---|
249 | |
---|
250 | ${lib}: ${pobjs} |
---|
251 | libgen -c -o=${lib} ${pobjs} |
---|
252 | @echo ${PACKTARGET} : library ok |
---|
253 | |
---|
254 | END |
---|
255 | |
---|
256 | else |
---|
257 | |
---|
258 | cat <<END >>${output} |
---|
259 | |
---|
260 | ${PACKTARGET}OBJS = ${objs} |
---|
261 | |
---|
262 | \$(bin)${PACKTARGET}: ${pobjs} |
---|
263 | cc \$(LINKFLAGS) -olM=8 \$(CFLAGS) -fd=\$@ \$? |
---|
264 | |
---|
265 | END |
---|
266 | |
---|
267 | fi |
---|
268 | |
---|
269 | if test ! "$ccs" = "" ; then # C targets |
---|
270 | for file in $ccs ; do |
---|
271 | if test -f ${srcdir}/${file} ; then |
---|
272 | echo Source file $file |
---|
273 | |
---|
274 | line=`build_deps $file` |
---|
275 | |
---|
276 | if test "$line" != "" ; then |
---|
277 | source=`echo $line | sed 's/[ ].*//'` |
---|
278 | suffix=`echo ${file} | sed 's/^.*\.//'` |
---|
279 | target=`basename $source ".${suffix}" | sed 's#$(src)##'` |
---|
280 | |
---|
281 | cat <<END >>$output |
---|
282 | |
---|
283 | \$(rels)${target}.r : ${line} |
---|
284 | cc \$(CFLAGS) -e=as -fd=\$@ ${src}\$*.c |
---|
285 | |
---|
286 | END |
---|
287 | |
---|
288 | fi |
---|
289 | |
---|
290 | cat <<END >>$output |
---|
291 | |
---|
292 | END |
---|
293 | |
---|
294 | else |
---|
295 | echo "Warning : cannot build dependancies for file $file (not found)" |
---|
296 | fi |
---|
297 | done |
---|
298 | fi |
---|
299 | |
---|
300 | cat <<END >>$output |
---|
301 | |
---|
302 | END |
---|
303 | |
---|
304 | } |
---|
305 | |
---|
306 | #-------------------------------------------------- |
---|
307 | usage () |
---|
308 | #-------------------------------------------------- |
---|
309 | { |
---|
310 | echo "Usage :" |
---|
311 | echo "> genmakeos9.sh <Package> [ options ] <source files> " |
---|
312 | echo " options : -I <include-path>" |
---|
313 | echo " -L <Library>" |
---|
314 | echo " -E <Executable>" |
---|
315 | } |
---|
316 | |
---|
317 | #-------------------------------------------------- |
---|
318 | #main () |
---|
319 | #-------------------------------------------------- |
---|
320 | |
---|
321 | argcount=$# # |
---|
322 | |
---|
323 | if test $argcount = 0 ; then |
---|
324 | usage |
---|
325 | exit 0 |
---|
326 | fi |
---|
327 | |
---|
328 | package=$1 |
---|
329 | shift |
---|
330 | |
---|
331 | c=`echo "$package" | grep '^[-]'` |
---|
332 | |
---|
333 | if test "$c" = "$package" ; then |
---|
334 | usage |
---|
335 | exit 0 |
---|
336 | fi |
---|
337 | |
---|
338 | unset PACKINCLUDES |
---|
339 | unset is_executable |
---|
340 | unset PACKOS9 |
---|
341 | PACKTARGET=$package |
---|
342 | |
---|
343 | while test "$#" -gt 0 ; do |
---|
344 | |
---|
345 | command=$1 |
---|
346 | c=`echo "$command" | grep '^[-]'` |
---|
347 | |
---|
348 | if test "$c" = "$command" ; then |
---|
349 | # |
---|
350 | # Here we have a command (starting with -) |
---|
351 | # |
---|
352 | shift |
---|
353 | else |
---|
354 | # |
---|
355 | # The first non-command argument terminates the parsing. |
---|
356 | # |
---|
357 | break |
---|
358 | fi |
---|
359 | |
---|
360 | if test "$command" = "-I" ; then |
---|
361 | # |
---|
362 | # The include path is defined in the next argument. |
---|
363 | # |
---|
364 | include=$1 |
---|
365 | shift |
---|
366 | |
---|
367 | PACKINCLUDES="$PACKINCLUDES -I$include" |
---|
368 | |
---|
369 | unset include |
---|
370 | |
---|
371 | elif test "$command" = "-L" ; then |
---|
372 | is_library=1 |
---|
373 | is_executable=0 |
---|
374 | PACKTARGET=$1 |
---|
375 | shift |
---|
376 | elif test "$command" = "-E" ; then |
---|
377 | is_library=0 |
---|
378 | is_executable=1 |
---|
379 | PACKTARGET=$1 |
---|
380 | shift |
---|
381 | elif test "$command" = "-OS9" ; then |
---|
382 | PACKOS9=1 |
---|
383 | else |
---|
384 | echo "Usage :" |
---|
385 | echo "> genmakeos9.sh <Package> [ options ] <source files> " |
---|
386 | echo " options : -I <include-path>" |
---|
387 | echo " -L <Library>" |
---|
388 | echo " -E <Executable>" |
---|
389 | exit 0 |
---|
390 | fi |
---|
391 | done |
---|
392 | |
---|
393 | # |
---|
394 | # To get access to cpp |
---|
395 | # |
---|
396 | |
---|
397 | system=`uname` |
---|
398 | if test "$system" = "HP-UX" ; then |
---|
399 | v=`uname -r | cut -d. -f2` |
---|
400 | if test "$v" = 10 ; then |
---|
401 | PATH=$PATH:/usr/ccs/lbin |
---|
402 | else |
---|
403 | PATH=$PATH:/lib |
---|
404 | fi |
---|
405 | unset v |
---|
406 | elif test "$system" = "AIX" ; then |
---|
407 | PATH=$PATH:/usr/ccs/lib |
---|
408 | fi |
---|
409 | |
---|
410 | #---- Define old and output files. -------------------------------- |
---|
411 | |
---|
412 | if test -d ../mgr ; then |
---|
413 | mgrdir=../mgr/ |
---|
414 | else |
---|
415 | mgrdir=`pwd`/ |
---|
416 | fi |
---|
417 | |
---|
418 | old=${mgrdir}${PACKTARGET}.os9make |
---|
419 | backup=${old}sav |
---|
420 | output=${old}new |
---|
421 | |
---|
422 | genmake_package $package $* |
---|
423 | |
---|
424 | #---- Complete the operation -------------------------------------- |
---|
425 | |
---|
426 | if test -r $old ; then |
---|
427 | mv $old $backup |
---|
428 | fi |
---|
429 | |
---|
430 | mv $output $old |
---|
431 | |
---|
432 | |
---|
433 | |
---|