2005-09-22 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / tools / gensources.sh
1 #!/bin/sh
2
3 includefile=$1
4 excludefile=$2
5
6 ## input variables:
7 ##      $filelist:
8 ##              A colon (':') separated list of files already read.
9 ##              Must be initialized to ":".
10 ##      $excludelist:
11 ##              A newline separated of element (support Shell Patterns) to exclude.
12 ##      $separator:
13 ##              The separator used in list for the output
14 ##      
15 ## output variables:
16 ##      $list:
17 ##              A list of elements separated by the separator given in $separator.
18 ##              The new elements will be appended to the list.
19 readlist () {
20         local onelist
21         local onelistcontent
22         onelist=$1
23
24         if [ ":$onelist:" = "::" ] ; then return ; fi
25         if [ ! -f $onelist ] ; then return ; fi
26         if [ ":${filelist##*:$onelist:*}:" = "::" ]  ; then return ; fi
27         filelist=":$onelist$filelist"
28
29         onelistcontent=`cat $onelist | while read line ; do echo -n $line ; echo -n ":" ; done`
30
31         OFS="$IFS"
32         IFS=":"
33         for line in $onelistcontent ; do
34                 line2=${line##\#include }
35                 if [ ":$line:" = ":$line2:" ] ; then
36                         for linex in $excludelist ; do
37                                 if [ ":${line##$linex}:" = "::" ] ; then line="" ; fi
38                         done
39                         if [ ":$line:" != "::" ] ; then
40                                 if [ ":$list:" = "::" ] ; then
41                                         list="$line"
42                                 else
43                                         list="$list$separator$line"
44                                 fi
45                         fi
46                 elif [ ":$line2:" != "::" ] ; then
47                         readlist "$line2"
48                 fi
49         done
50         IFS="$OFS"
51 }
52
53 list=""
54 filelist=":"
55 excludelist=""
56 separator=":"
57 readlist "$excludefile"
58
59 excludelist="$list"
60 list=""
61 filelist=":"
62 separator="
63 "
64 readlist "$includefile"
65 echo "$list" | sort | uniq