Michael Gerdau wrote:
> w32api also includes the various system import libs. Even if he
> uses no platform dependent libs in his code he still links against
> kernel32 and possibly other Woe32 libs.
Actually, only kernel32 is required by the crt* objects in lib. The
other libraries are required just because they're specified in the gcc
specs file.
Since the original subject was "Isn't gcc-core enough", I was curious to
see how violently I could strip down the C compiler and still have it
compile C programs without Microsoft API's.
The following commands were executed with an MSYS shell.
The packages used were gcc-core-3.4.5-20060117-1.tar.gz,
binutils-2.17.50-20060824-1.tar.gz, w32api-3.9.tar.gz,
mingw-runtime-3.12.tar.gz.
All those packages were unzipped in /mingwtest. No other mingw was in
PATH or in the file system of the MSYS shell
Lecomte@... ~
$ export PATH=/mingwtest/bin:$PATH
$ cd /mingwtest
$ du --si -s; du -s
52M .
50194 .
# Trim down the filesystem documentation,
# and cross-compilation directory
$ rm -fr COPYING COPYING.LIB doc/ info/ man/ mingw32/
# Remove debugging utilities, and other binaries
$ rm -fr bin/{addr2line,dllwrap,mingw32-gcc-3.4.5,mingw32-gcc,ar}{.exe,}
$ rm -fr bin/{gprof,gcov,windres,gccbug,strings,nm,ranlib}{.exe,}
$ rm -fr bin/{readelf,size,c++filt,dlltool,objcopy,objdump,cpp}{.exe,}
# Remove GCC's extra stuff
$ rm -fr lib/gcc/mingw32/3.4.5/{libgcov.a,install-tools,include/README}
$ rm -fr libexec/gcc/mingw32/3.4.5/install-tools
# Save some required libs, remove the rest, and restore
$ mv -v lib/lib{kernel32,mingw32,mingwthrd,moldname,mingwex,msvcrt}.a .
$ mv -v lib/{dll,}crt{1,2,mt,st}.o .
$ rm -fr lib/lib*.{l,}a
$ rm -fr lib/*.o
$ mv lib*.a *.o lib/
# Do the same for headers
$ mv include/{_mingw,assert,complex,ctype,errno,fenv}.h .
$ mv include/{float,inttypes,limits,locale,math,setjmp}.h .
$ mv include/{signal,stdint,stdio,stdlib,string,wchar,wctype}.h .
$ rm -fr include/{*.h,ddk,GL}
$ mv *.h include/
# Use and discard strip
$ mv bin/strip.exe .
$ ./strip.exe --strip-all bin/*
$ rm strip.exe
# Fix the specs file
$ gcc -dumpspecs | sed
's%-luser32%%g;s%-lgdi32%%g;s%-lcomdlg32%%g;s%-ladvapi32
%%g;s%-lshell32%%g' > $(gcc -print-file-name=specs)
$ du --si -s; du -s
7.9M .
7706 .
As you can see, a 'pure' lean and mean MinGW compiler could take up as
little as 8 Mb instead of 52 Mb. You can compile C applications,
provided you stick to C and don't use Microsoft API's.
I'm sure this could be even more reduced by using a libkernel32.a that
only exports the functions used by crt*.o, and some libraries (moldname)
could also be pruned/removed.
Julien
|