UserExtensions: utils.bkl

File utils.bkl, 14.8 KB (added by Vaclav Slavik, 4 years ago)

Various utility tags and rules

Line 
1<?xml version="1.0" ?>
2
3<!-- Author: Francesco Montorsi <frm@users.sourceforge.net>         -->
4<!-- Source: http://wiki.wxwidgets.org/wiki.pl?Bakefile_Utils       -->
5<!-- Date: 1/5/2005                                                 -->
6<!-- Last revision: 15/1/2006                                       -->
7
8<!--                                                                -->
9<!--             GENERIC BAKEFILE WITH UTILITY TAGS                 -->
10<!--                                                                -->
11<!--    This bakefile provides various new tags for easier          -->
12<!--    target creation (in particular these tags give you          -->
13<!--    the tools required to build INSTALL/UNINSTALL/RPM           -->
14<!--    targets.                                                    -->
15
16<makefile>
17    <requires version="0.2.0"/>
18
19    <!--                                                                -->
20    <!--                            NEW TAGS                            -->
21    <!--                                                                -->
22
23    <!-- Removes the $(value) list of files. Each file should be        -->
24    <!-- separed from the previous with a single space.                 -->
25    <define-tag name="rmfiles" rules="action">
26        <clean-files>$(value)</clean-files>
27    </define-tag>
28
29    <!-- Recursively removes the $(value) file from the current folder. -->
30    <!-- Usage sample:                                                  -->
31    <!--          <action id="deepclean">                               -->
32    <!--              <rmfile-rec>$(BUILDDIR)/*.o</rmfile>              -->
33    <!--          </action>                                             -->
34    <define-tag name="rmfile-rec" rules="action">
35        <if cond="TOOLSET=='unix'"><command>$(RM) -r $(value)</command></if>
36        <if cond="TOOLSET=='win32'"><command>-del /S $(value)</command></if>
37    </define-tag>
38
39    <!-- Removes the $(value) folder.                                   -->
40    <!-- Usage sample:                                                  -->
41    <!--          <action id="uninstall-scripts">                       -->
42    <!--              <rmdir>$(DATADIR)/myscripts</rmdir>               -->
43    <!--          </action>                                             -->
44    <define-tag name="rmdir" rules="action">
45        <if cond="TARGETING_WIN32=='0'">
46            <command>rm -rf $(value)</command>
47        </if>
48        <if cond="TARGETING_WIN32=='1' and FORMAT!='mingw'">
49            <command>-if exist $(value) rmdir /S /Q $(value)</command>
50        </if>
51        <if cond="TARGETING_WIN32=='1' and FORMAT=='mingw'">
52            <!-- The MINGW format needs the "then" keyword... -->
53            <command>-if exist $(value) then rmdir /S /Q $(value)</command>
54        </if>
55    </define-tag>
56
57    <!-- Removes the intermediate folders whose names are composed as   -->
58    <!-- "$(value)[u][d]" where 'u' is used when Unicode is enabled and -->
59    <!-- 'd' is used for debug builds.                                  -->
60    <!-- Usage sample:                                                  -->
61    <!--          <set var="BUILDDIR">$(FORMAT)$(WXLIBPOSTFIX)</set>    -->
62    <!--          <action id="deepclean">                               -->
63    <!--              <rmintdir>$(FORMAT)</rmintdir>                    -->
64    <!--          </action>                                             -->
65    <define-tag name="rmintdir" rules="action">
66        <rmdir>$(value)</rmdir>
67        <rmdir>$(value)</rmdir>
68        <rmdir>$(value)u</rmdir>
69        <rmdir>$(value)ud</rmdir>
70    </define-tag>
71
72    <!-- Removes *all* intermediate files from the given folder         -->
73    <!-- recursively.                                                   -->
74    <!-- NOTE: BE CAREFUL SINCE THIS TAG WILL REMOVE A LOT OF FILES     -->
75    <!--       JUST LOOKING AT THEIR EXTENSION !!                       -->
76    <!-- Usage sample:                                                  -->
77    <!--          <action id="deepclean">                               -->
78    <!--              <rmintfiles>build</rmintfiles>                    -->
79    <!--          </action>                                             -->
80    <define-tag name="rmintfiles" rules="action">
81
82        <!-- remove results -->
83        <rmfile-rec>$(value)$(DIRSEP)*.a</rmfile-rec>
84        <rmfile-rec>$(value)$(DIRSEP)*.lib</rmfile-rec>
85        <rmfile-rec>$(value)$(DIRSEP)*.pdb</rmfile-rec>
86        <rmfile-rec>$(value)$(DIRSEP)*.dll</rmfile-rec>
87        <rmfile-rec>$(value)$(DIRSEP)*.exp</rmfile-rec>
88        <rmfile-rec>$(value)$(DIRSEP)*.so*</rmfile-rec>
89        <rmfile-rec>$(value)$(DIRSEP)*.exe</rmfile-rec>
90
91        <!-- various intermediate files for the bakefile-supported compilers -->
92        <rmfile-rec>$(value)$(DIRSEP)*.obj</rmfile-rec>
93        <rmfile-rec>$(value)$(DIRSEP)*.o</rmfile-rec>
94        <rmfile-rec>$(value)$(DIRSEP)*.log</rmfile-rec>
95        <rmfile-rec>$(value)$(DIRSEP)*.manifest*</rmfile-rec>
96        <rmfile-rec>$(value)$(DIRSEP)*.log</rmfile-rec>
97        <rmfile-rec>$(value)$(DIRSEP).bakefile_gen.state</rmfile-rec>
98
99        <!-- MSVC -->
100        <rmfile-rec>$(value)$(DIRSEP)*.pch</rmfile-rec>
101        <rmfile-rec>$(value)$(DIRSEP)*.ncb</rmfile-rec>
102        <rmfile-rec>$(value)$(DIRSEP)*.plg</rmfile-rec>
103        <rmfile-rec>$(value)$(DIRSEP)*.ncb</rmfile-rec>
104        <rmfile-rec>$(value)$(DIRSEP)*.aps</rmfile-rec>
105        <rmfile-rec>$(value)$(DIRSEP)*.suo</rmfile-rec>
106        <rmfile-rec>$(value)$(DIRSEP)*.user</rmfile-rec>
107        <rmfile-rec>$(value)$(DIRSEP)*.res</rmfile-rec>
108
109        <!-- Borland -->
110        <rmfile-rec>$(value)$(DIRSEP)*.il?</rmfile-rec>
111        <rmfile-rec>$(value)$(DIRSEP)*.tds</rmfile-rec>
112        <rmfile-rec>$(value)$(DIRSEP)*.idb</rmfile-rec>
113        <rmfile-rec>$(value)$(DIRSEP)*.map</rmfile-rec>
114
115        <!-- autoconf -->
116        <rmdir>$(value)$(DIRSEP)autom4te.cache</rmdir>
117        <rmdir>$(value)$(DIRSEP).deps</rmdir>
118        <rmfile-rec>$(value)$(DIRSEP)config.status</rmfile-rec>
119        <rmfile-rec>$(value)$(DIRSEP)config.log</rmfile-rec>
120        <rmfile-rec>$(value)$(DIRSEP)Makefile</rmfile-rec>
121        <rmfile-rec>$(value)$(DIRSEP)bk-deps</rmfile-rec>
122    </define-tag>
123
124    <!-- Includes the $(value)/include path in include search paths and the $(value)/lib
125         path in the library search paths when the boolean option whose name is given in
126         the BOOLOPT attribute of this tag, has value == '1'.
127         If the attribute BOOLOPT is missing, then the $(value)/include and $(value)/lib
128         paths are always added.
129
130         E.g.
131                  <stdlib-paths>$(MYLIBPATH)</stdlibs-path>
132
133                  <option name="USE_MYLIB"><values>0,1</values></option>
134                  <stdlib-paths boolopt="USE_MYLIB">$(MYLIBPATH)</stdlibs-path>
135    -->
136    <define-tag name="stdlib-paths" rules="lib,exe,dll,module">
137        <include>$(substituteFromDict(
138                        mk.evalExpr('$(' + getTagAttrib('boolopt', '1') + ')'),
139                            {'1':value+'/include', '0':''}))</include>
140        <lib-path>$(substituteFromDict(
141                        mk.evalExpr('$(' + getTagAttrib('boolopt', '1') + ')'),
142                            {'1':value+'/lib', '0':''}))</lib-path>
143    </define-tag>
144
145
146
147
148
149    <!--                                                                -->
150    <!--                           NEW RULES                            -->
151    <!--                                                                -->
152
153    <!-- Forces the presence of the $(id) option into the final makefile; -->
154    <!-- this rule (which is really used more like a tag) is a tweaky way -->
155    <!-- to tell Bakefile not to remove from the final makefile an option -->
156    <!-- which has been qualified as 'useless'.                           -->
157    <!-- See bakefile docs for the VARS_DONT_ELIMINATE global switch.     -->
158    <!-- Usage sample:                                                    -->
159    <!--    <force-opt-presence id="MY_USELESS_OPTION"/>                  -->
160    <define-rule name="force-opt-presence" extends="phony">
161        <template id="dummytemplate_for_$(id)"/>
162        <!-- <set var="VARS_DONT_ELIMINATE" append="1">$(id)</set> -->
163    </define-rule>
164
165    <!-- Changes the current directory to the folder given to the CD    -->
166    <!-- tag and then executes the command given to the RUN tag.        -->
167    <!-- Usage sample:                                                  -->
168    <!--          <cd-and-run id="tarball">                             -->
169    <!--              <cd>..</cd>                                       -->
170    <!--              <run>tar -cvzf tarball.tar.gz myproj/*</run>      -->
171    <!--          </cd-and-run>                                         -->
172    <define-rule name="cd-and-run" extends="action">
173        <template>
174            <set var="__cmddir"/>
175            <set var="__cmdstr"/>
176        </template>
177        <define-tag name="cd">
178            <set var="__cmddir">$(nativePaths(value))</set>
179        </define-tag>
180        <define-tag name="run">
181            <set var="__cmdstr">$(value)</set>
182            <if cond="FORMAT=='msvc' or FORMAT=='mingw' or FORMAT=='gnu' or FORMAT=='autoconf'">
183                <command>( cd $(__cmddir) &amp;&amp; $(__cmdstr) )</command>
184            </if>
185            <if cond="FORMAT=='borland' or FORMAT=='watcom'">
186                <command>-cd $(__cmddir)</command>
187                <command>-$(__cmdstr)</command>
188            </if>
189        </define-tag>
190    </define-rule>
191
192    <!-- Helps you to set the MAKEARGS variable manually.               -->
193    <!-- he MAKEARGS variable is usually automatically generated by     -->
194    <!-- Bakefile using all the options available; the problem is that  -->
195    <!-- maybe you have to translate from an option name to another...  -->
196    <!-- For example, I often found that I need to translate the:       -->
197    <!--   WX_UNICODE=1/0,                                              -->
198    <!--   WX_SHARED=1/0,                                               -->
199    <!--   WX_DEBUG=1/0,                                                -->
200    <!-- options of the build system of my wxWidgets-based projects, to -->
201    <!-- some other option name, when building the non wx-based part of -->
202    <!-- those projects, like:                                          -->
203    <!--   UNICODE=1/0,                                                 -->
204    <!--   SHARED=1/0,                                                  -->
205    <!--   BUILD=debug/release                                          -->
206    <!-- To do such kind of substitution in the arguments passed to the -->
207    <!-- other MAKEs by the <subproject> targets, you need to write the -->
208    <!-- MAKEARGS variable by hand... and this tag helps you a lot !    -->
209    <!-- Usage sample:                                                  -->
210    <!--      <set var="BUILD_EQUIVALENT">                              -->
211    <!--           <if cond="WX_DEBUG=='1'">debug</if>                  -->
212    <!--           <if cond="WX_DEBUG=='0'">release</if>                -->
213    <!--      </set>                                                    -->
214    <!--      <smart-subproject id="nonwxbased">                        -->
215    <!--           <set-makeargs>                                       -->
216    <!--                    UNICODE=$(WX_UNICODE)                       -->
217    <!--                    SHARED=$(WX_SHARED)                         -->
218    <!--                    BUILD=$(BUILD_EQUIVALENT)                   -->
219    <!--           </set-makeargs>                                      -->
220    <!--      </smart-subproject>                                       -->
221    <define-rule name="smart-subproject" extends="subproject">
222        <template>
223        </template>
224        <define-tag name="set-makeargs">
225            <set var="_MAKEARGS">
226                CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)"
227                CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" $(value)
228            </set>
229
230            <!-- now adjust the real MAKEARGS -->
231            <if cond="FORMAT=='borland'">
232                <set var="MAKEARGS" make_var="1">$(''.join(['-D%s ' % (x) for x in _MAKEARGS.split()]))</set>
233            </if>
234            <if cond="FORMAT!='borland'">
235                <set var="MAKEARGS" make_var="1">$(_MAKEARGS)</set>
236            </if>
237        </define-tag>
238    </define-rule>
239
240    <!-- exactly like <copy-files> but this target just does not contain the "if not exist"
241            check and thus always performs the copy of the files (maybe overwriting old
242            versions of them). -->
243    <define-rule name="force-copy-files" extends="action">
244        <template>
245            <is-phony/>
246            <set var="__srcdir"/>
247
248            <!--
249                DigitalMars' smake has problems with long command lines, so we
250                have to work around it. More details here:
251                http://sourceforge.net/mailarchive/message.php?msg_id=9595825
252                -->
253            <if cond="TOOLSET=='win32' and FORMAT=='dmars_smake'">
254                <set var="__copy_depends" eval="0">
255                    $(''.join(['$(__srcdir)%s ' % (x) for x in __files.split()]))
256                </set>
257                <set var="__deps" append="1">$(__copy_depends)</set>
258                <set var="__copy_script_name">$(FORMAT)_copy_$(id).bat</set>
259            </if>
260
261            <set var="__copy_cmd" eval="0">
262
263                <if cond="TOOLSET=='unix'">
264                    @mkdir -p $(__dstdir)
265                    @for f in $(__files); do \
266                            cp -pRf $(__srcdir)$(DOLLAR)$(DOLLAR)f $(__dstdir) ; \
267                    done
268                </if>
269
270                <if cond="TOOLSET in ['win32','os2'] and FORMAT!='mingw' and FORMAT!='dmars_smake'">
271                    if not exist $(__dstdir) mkdir $(__dstdir)
272                    for %f in ($(__files)) do copy $(__srcdir)%f $(__dstdir)
273                </if>
274                <if cond="TOOLSET=='win32' and FORMAT=='dmars_smake'">
275                    if not exist $(__dstdir) mkdir $(__dstdir)
276                    echo copy $(__srcdir)%%1 $(__dstdir)\%%1 &gt; $(__copy_script_name)
277                    !$(__copy_script_name) $**
278                    del $(__copy_script_name)
279                </if>
280                <if cond="TOOLSET=='win32' and FORMAT=='mingw'">
281                    if not exist $(__dstdir) mkdir $(__dstdir)
282                    for %%f in ($(__files)) do copy $(__srcdir)%%f $(__dstdir)
283                </if>
284
285            </set>
286            <command>$(__copy_cmd)</command>
287        </template>
288        <define-tag name="dstdir">
289            <set var="__dstdir">$(nativePaths(value))</set>
290        </define-tag>
291        <define-tag name="srcdir">
292            <set var="__srcdir">$(nativePaths(value))$(DIRSEP)</set>
293        </define-tag>
294        <define-tag name="files">
295            <set var="__files">$(' '.join(value.split()))</set>
296        </define-tag>
297    </define-rule>
298
299</makefile>