new rule: FileExists; better boiler generator
[k8jam.git] / defaults / Jambase.boiler
bloba976640d19af1cafb87d9f97814e5444104b9bc5
2 # 'boilerplate' code
4 rule -Generate-Boiler- {
5   local _f = $(FORCE) ;
6   NotFile gen-boiler ;
7   Always gen-boiler ;
8   if $(_f) {
9     _f = "_-boiler-target-force-_" ;
10   } else {
11     _f = "_-boiler-target-noforce-_" ;
12   }
13   NotFile $(_f) ;
14   NoCare $(_f) ;
15   AGenBoiler gen-boiler $(_f) ;
17 actions quietly AGenBoiler {
19 fregen="$(<[2])"
20 if [ "z$fregen" != "z_-boiler-target-force-_" ]; then
21   fregen="ona"
22 else
23   fregen="tan"
27 dirhassrc() {
28   local llist
29   llist=`find "$1" -mindepth 1 -maxdepth 1 -type f -name "*.cpp" -regex "^./[^._].*$"`
30   if [ "z$llist" = "z" ]; then
31     llist=`find "$1" -mindepth 1 -maxdepth 1 -type f -name "*.c" -regex "^./[^._].*$"`
32     if [ "z$llist" = "z" ]; then
33       return 0
34     fi
35   fi
36   return 1
40 dirhascpp() {
41   local llist
42   llist=`find "$1" -mindepth 1 -maxdepth 1 -type f -name "*.cpp" -regex "^./[^._].*$"`
43   if [ "z$llist" = "z" ]; then
44     return 0
45   fi
46   return 1
50 prjname="$(MAIN)"
51 if [ "z$prjname" = "z" ]; then
52   prjname="mainprj"
55 for dname in `find . -maxdepth 8 -type d -name "[^._]*" -regex "^./[^._].*$"`; do
56   fname="$dname/Jamfile"
57   xskip="ona"
58   if [ "$fregen" == "ona" ]; then
59     if [ -e "${fname}" ]; then
60       xskip="tan"
61     fi
62   fi
63   if [ "$xskip" != "tan" ]; then
64     dirhassrc "$dname"
65     if [ "$?" = "0" ]; then
66       xskip="tan"
67     fi
68   fi
69   if [ "$xskip" = "tan" ]; then
70     echo "SKIP: $fname"
71   else
72     echo "GENF: $fname"
73     dpp=`echo "$dname" | sed 's/^\.\//TOP /;' | sed 's/\// /g;'`
74     echo "SubDir $dpp ;" >"$fname"
75     echo "" >>"$fname"
76     echo "" >>"$fname"
77     if [ "$dname" != "./src" ]; then
78       dpp=`basename "$dname"`
79       fc=`echo "$dpp" | cut -c1-3`
80       if [ "z$fc" != "zlib" ]; then dpp="lib${dpp}"; fi
81       echo "Library ${dpp}.a :" >>"$fname"
82     else
83       dirhascpp "$dname"
84       if [ "$?" = "0" ]; then
85         echo "Main ${prjname} :" >>"$fname"
86       else
87         echo "C++Main ${prjname} :" >>"$fname"
88       fi
89     fi
90     llist=`find "$dname" -mindepth 1 -maxdepth 1 -type f -name "*.c" -regex "^./[^._].*$"`
91     for lname in $llist; do
92       dpp=`basename "$lname"`
93       echo "  $dpp" >>"$fname"
94     done
95     llist=`find "$dname" -mindepth 1 -maxdepth 1 -type f -name "*.cpp" -regex "^./[^._].*$"`
96     for lname in $llist; do
97       dpp=`basename "$lname"`
98       echo "  $dpp" >>"$fname"
99     done
100     echo ";" >>"$fname"
101     llist=`find "$dname" -mindepth 1 -maxdepth 8 -type d -name "[^._]*" -regex "^./[^._].*$"`
102     if [ "z$llist" != "z" ]; then
103       if [ "$dname" = "./src" ]; then
104         llibs=""
105         for lname in $llist; do
106           dpp=`basename "$lname"`
107           if [ "z$fc" != "zlib" ]; then dpp="lib${dpp}"; fi
108           llibs="${llibs} ${dpp}.a"
109         done
110         echo "LinkLibraries ${prjname} :${llibs} ;" >>"$fname"
111       fi
112       echo "" >>"$fname"
113       echo "" >>"$fname"
114       for lname in $llist; do
115         dirhassrc "$lname"
116         if [ "$?" = "1" ]; then
117           dpp=`echo "$lname" | sed 's/^\.\//TOP /;' | sed 's/\// /g;'`
118           echo "SubInclude $dpp ;" >>"$fname"
119         fi
120       done
121     fi
122   fi
123 done
126 fname="./Jamfile"
127 xskip="ona"
128 if [ "$fregen" == "ona" ]; then
129   if [ -e "$fname" ]; then
130     xskip="tan"
131   fi
133 if [ "$xskip" = "tan" ]; then
134   echo "SKIP: $fname"
135 else
136   echo "GENF: $fname"
137   echo "SubDir TOP ;" >"$fname"
138   echo "" >>"$fname"
139   echo "" >>"$fname"
140   for dname in `find . -maxdepth 8 -type d -name "[^._]*" -regex "^./[^._].*$"`; do
141     dirhassrc "$dname"
142     if [ "$?" = "1" ]; then
143       dpp=`echo "$dname" | sed 's/^\.\//TOP /;' | sed 's/\// /g;'`
144       echo "SubInclude $dpp ;" >>"$fname"
145     fi
146   done
149 fname="./Jamrules"
150 xskip="ona"
151 if [ "$fregen" == "ona" ]; then
152   if [ -e "$fname" ]; then
153     xskip="tan"
154   fi
156 if [ "$xskip" = "tan" ]; then
157   echo "SKIP: $fname"
158 else
159   echo "GENF: $fname"
160   echo "set-profile ;" >"$fname"
161   echo "set-target-locations ;" >>"$fname"
162   firsthdrs="tan"
163   for dname in `find . -maxdepth 8 -type d -name "[^._]*" -regex "^./[^._].*$"`; do
164     dirhassrc "$dname"
165     if [ "$?" = "0" ]; then
166       if [ "$firsthdrs" = "tan" ]; then
167         firsthdrs="ona"
168         echo "" >>"$fname"
169         echo "" >>"$fname"
170       fi
171       dpp=`echo "$dname" | sed 's/^\.\//\(TOP)\//;'`
172       echo "HDRS += \$$dpp ;" >>"$fname"
173     fi
174   done
175   if [ "$firsthdrs" = "ona" ]; then
176     echo "" >>"$fname"
177     echo "" >>"$fname"
178   fi
179   dollar="\$"
180   echo "if ([ FileExists ${dollar}(TOP)/Jamrules.local ]) {" >>"$fname"
181   echo "  include ${dollar}(TOP)/Jamrules.local ;" >>"$fname"
182   echo "}" >>"$fname"
186 -Generate-Boiler- ;