Thursday, 11 December 2008

A flexible way to exclude files from CE image

Sometimes you want to remove files from a CE image for example to save ROM/RAM space or because you do not want to support a certain functionality.

Usually, the right way is to remove the related feature from the OS design. But there are circumstances where a catalogue feature adds several files and you do not want them to be included. Here comes a little batch file and additional bib file which will do all the work.

Here the batch file 'make_bibremove.bat' which will do the work for you

@echo off
rem -- remove items from a .bib file
rem -- declare items to remove with "; @BIBREMOVE "
rem -- keep semicolon and spaces ^^----------^
rem -- somewhere inside the .bib file you request filtered
rem -- filtering occurs by case-insensitive item identifier comparison
rem -- a list of removed items is appended to the resulting file
rem -- USAGE: make_bibremove

if not exist %1 goto :EOF

rem -- extract files marked by tag -------------------------------------
findstr "@BIBREMOVE" %1 > ~bibremove~.0
for /f "tokens=3 eol=§" %%I in (~bibremove~.0) do (
echo Removing %%I from %1
echo %%I> ~bibremove~.1
rem -- filter marked files ---------------------------------------------
if exist ~bibremove~.1 (
findstr /i /v /g:~bibremove~.1 %1 > ~bibremove~.2
echo ; ** Files removed by make_bibremove.bat ** >> ~bibremove~.2
type ~bibremove~.0 >> ~bibremove~.2
copy ~bibremove~.2 %1 > NUL:
rem -- cleanup temporary files -----------------------------------------
rem del ~bibremove~.*

Call this batch file in your FILES\postfmergebib.bat:

@rem --------------------------------------------------------------------------
@rem -- remove unnecessary items from the ROM filesystem ----------------------
@rem --------------------------------------------------------------------------
@call make_bibremove.bat %_FLATRELEASEDIR%\ce.bib

@rem --------------------------------------------------------------------------
@rem -- add additional generic postfmergebib directives here ------------------
@rem --------------------------------------------------------------------------

Now add the items to be removed somewhere in your platform.bib (or any other included file), like

;; Remove items which aren't required for our application to
;; => save some RAM (winsock API is required for compilation of our
;; application framework, but the target does not provide network interface)
; @BIBREMOVE ws2instl.dll
; @BIBREMOVE wspm.dll
; @BIBREMOVE nspm.dll
; @BIBREMOVE ws2k.dll
; @BIBREMOVE ws2serv.dll
; @BIBREMOVE afd.dll
; @BIBREMOVE usbhid.dll
; @BIBREMOVE usbmsfn.dll

Pleas let me know if you have any questions or suggestions.

No comments: