Tuesday, July 14, 2009

My .profile for MinGW and Cygwin

The file .profile is a personal initialization file used both by MinGW and Cygwin Bash shell. It has many uses depending on how one uses it. I edit it primarily to customize my own build environment. .profile should be placed in the %HOME% directory. If %HOME% is not set, it is searched for in, for example, C:\MSYS\1.0\home\Aziz.

Because the name .profile begins with a dot, Windows explorer may not allow you to create it. If so, type the following command in Command Prompt (cmd.exe) to create .profile.


copy nul .profile

In a MSYS or Cygwin shell, type the following command to create .profile.


touch .profile


.profile For MinGW


The following is the contents of my .profile for MinGW:


CC='/mingw/bin/gcc.exe'
CFLAGS='-march=pentium2 -mtune=i586 -mthreads -O2 -g0 -mms-bitfields'
CPPFLAGS='-DWIN32 -D_WIN32 -D__WINDOWS__ -DMINGW32 -D__MINGW32__'
CXXFLAGS="${CFLAGS}"
LDFLAGS='-Wl,--enable-auto-image-base -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc '
PKG_CONFIG_PATH="C:\MinGW\lib\pkgconfig"
export CC CFLAGS CPPFLAGS CXXFLAGS LDFLAGS PKG_CONFIG_PATH

After you make any change to .profile, be sure to restart the MSYS terminal. Otherwise, do this:


source ~/.profile


.profile for Cygwin


The following is the contents of my .profile for Cygwin:


CC='/usr/bin/gcc-3.exe '
CFLAGS='-march=pentium2 -mtune=i586 -O2 -g0'
CXXFLAGS="${CFLAGS}"
LDFLAGS='-Wl,--enable-auto-image-base -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc '
export CC CFLAGS CXXFLAGS LDFLAGS

After you make any change to .profile, be sure to restart the Cygwin Bash shell. Otherwise, do this:


source ~/.profile


.profile for Cygwin-to-Win32 Cross-Compiler


Cygwin can be used to compile native Windows binaries that don't depend on cygwin1.dll. The following .profile contents enable such compiler environment:


CC='/usr/bin/gcc-3.exe '
CFLAGS='-mno-cygwin -march=pentium2 -mtune=i586 -O2 -fomit-frame-pointer -pipe '
CPPFLAGS='-mno-cygwin -DMINGW32 '
CXXFLAGS="${CFLAGS}"
LDFLAGS='-mno-cygwin -Wl,--enable-auto-image-base -Wl,--enable-auto-import -Wl,-
-enable-runtime-pseudo-reloc '
export CC CFLAGS CPPFLAGS CXXFLAGS LDFLAGS

When you compile programs, make sure to specify --build=i586-pc-mingw32 --prefix=/usr/i686-pc-mingw32 on the configure line.


./configure --build=i586-pc-mingw32 --prefix=/usr/i686-pc-mingw32
make
make install


Choices for -march and -mtune Options


The -march and -mtune options in the CFLAGS environment variable determine how GCC will compile optimized/generic codes for certain CPU families. I've tried several combinations for these options, as follows:


  • -march=pentium2 -mtune=i586
  • -march=pentium3 -mtune=i586
  • -march=k6-2 -mtune=pentium-mmx
  • -march=k8 -mtune=pentium-mmx

I haven't tested these choices extensively, but I believe the following will produce fairly generic code:


-march=pentium2 -mtune=i586

For more information on available -march and -mtune options, read this: i386 and x86-64 Options - Using the GNU Compiler Collection (GCC).

No comments:

Post a Comment

About This Blog

KBlog logo This blog is about current events and issues concerning general population. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

icon
Powered By Blogger