@html_text_substitution=readme.txt|<a href="../readme.html">readme.txt</a>
@external-css=../allegro.css
@document_title=Notes on building the MinGW/Cygwin version of Allegro.
@<pre>
     ______   ___    ___
    /\  _  \ /\_ \  /\_ \
    \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___ 
     \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
      \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
       \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
	\/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
				       /\____/
				       \_/__/


   Notes on building the MinGW/Cygwin version of Allegro.

   Written by Henrik Stokseth.

   Robert J Ohannessian added some updates to the installation instructions
   and an example on how to use Dev-C++ with Allegro.

   Elias Pschernig and Hein Zelle revamped the cross-compilation section.

   Andrei Ellman updated the Cygwin section.

   Michal Molhanec simplified the Dev-C++ instructions.

   See readme.txt for a more general overview.
@</pre>



@heading
MinGW notes

   This is a complete MinGW port of Allegro. This build doesn't rely
   on the DLL files produced by MSVC any longer but can make them itself.
   I'm proud to say Allegro can now make Win32 programs entirely using
   free professional tools. On that note I'd like to thank Peter Puck for
   making this a reality and for finishing off what I started. Enjoy!

   The screensaver example is built, but you must copy <tt>scrsave.scr</tt> to
   your <tt>windows/system</tt> directory (or <tt>winnt/system32</tt> directory
   under Windows NT/2k/XP) if you want to test it.

   If you have both GNU bash and GNU fileutils installed on your system, then
   set the environment variable <tt>UNIX_TOOLS</tt> (<tt>set UNIX_TOOLS=1</tt>). This is needed
   because GNU make will automatically use sh.exe instead of command.com if
   it finds it somewhere in the <tt>PATH</tt>. This step is not necessary when using
   MSYS or Cygwin as the makefile automatically sets <tt>UNIX_TOOLS</tt> for you.

   "<tt>make depend</tt>" and "<tt>fixdll.bat</tt>" require that you have GNU sed installed.
   "<tt>fixdll.bat</tt>" requires that you have GNU sort (not DOS sort!) installed.
   You can download some extra utilities for MinGW from:
   '<link>http://sourceforge.net/projects/gnuwin32/</a>'



@heading
Obtaining and installing the compiler & tools

   You have four choices when it comes to installing MinGW and Allegro
   on your computer:
<ul>
      <li>The section 'Setting up MinGW to build Allegro' describes how to set
      up the MinGW command line tools which is the preferred choice for
      those who like to work on the command line.

      <li>The section 'Setting up Dev-C++ to build Allegro' describes how to set
      up the Dev-C++ environment to work with Allegro. This is the preferred
      choice for those who like to work in a graphical development environment.

      <li>The section 'Setting up Cygwin to build Allegro' describes how to set
      up your Cygwin compiler to build Allegro. Cygwin offers a mature
      Unix-like environment for you to work in.

      <li>The last section 'Cross compilation' describes how to set up the
      MinGW command line tools to compile Win32 programs from your Linux
      box.
</ul>
   Note: You will need a program to decompress .zip, .tar.gz and optionally
   .tar.bz2 files. I recommend PowerArchiver (shareware) which can be
   downloaded from: '<link>http://www.powerarchiver.com</a>'.



@heading
Setting up MinGW to build Allegro

   The procedure is as follows:
<blockquote>
   1. Make sure you have a working MinGW installation. You can download the
      complete distribution or individual packages from '<link>http://www.mingw.org</a>'
      or '<link>http://sourceforge.net/projects/mingw/</a>'. You can also use
      the Minimal SYStem (MSYS) environment with Allegro.

   2. Get the minimal DirectX 7 SDK for MinGW (<tt>dx70_mgw.zip</tt>). You
      download it from '<link>http://alleg.sourceforge.net/wip.html</a>'. Note
      that this is *not* the same package as '<tt>dx70_min.zip</tt>'. Unzip it
      to the compiler directory, overwriting any existing files.

   3. Set the environment variable MINGDIR to the compiler directory. If you
      use Windows 9x, you can add the line
<textblock>
	 set MINGDIR=c:\MinGW
<endblock>
      to your '<tt>c:\autoexec.bat</tt>' file, assuming '<tt>c:\MinGW</tt>' is the compiler
      directory, and reboot. If you use Windows ME, you can run '<tt>msconfig</tt>',
      select the 'Environment' tab and then add <tt>MINGDIR</tt>. If you use
      Windows NT/2k/XP, you can open the Control Panel, click the 'System'
      applet, the 'Advanced' tab and finally the 'Environment' button, and
      then add <tt>MINGDIR</tt>. If you use MSYS, add instead the line
<textblock>
	 export MINGDIR=/mingw
<endblock>
      to your '<tt>c:\msys\etc\profile</tt>' file.
</blockquote>
   Test the installation by typing the following on the command line:
   '<tt>gcc -v</tt>'. The answer should be similar to:
<textblock>
      Reading specs from ../lib/gcc-lib/mingw32/3.2/specs
      Configured with: ../gcc/configure --with-gcc --with-gnu-ld
      --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw
      --enable-threads --disable-nls --enable-languages=f77,c++,objc,ada
      --disable-win32-registry --disable-shared
      Thread model: win32
      gcc version 3.2 (mingw special 20020817-1)
<endblock>
   If you don't know how to open a terminal, you can click on '<tt>Start -&gt Run</tt>'
   then type "<tt>command</tt>". Under Windows 2k/XP, you should type "<tt>cmd</tt>" instead.



@heading
Setting up Dev-C++ to build Allegro

   Note: we assume that the complete version of the Dev-C++ environment (i.e
   with the bundled MinGW compiler) is used. If you use instead Dev-C++ as
   a mere IDE on top of an already installed MinGW compiler, follow the
   instructions given in the previous section.

   The procedure is as follows:
<blockquote>
   1. Make sure you have a working Dev-C++ installation. You can download the
      complete version from '<link>http://bloodshed.net/dev/devcpp.html</a>'.
   
   2. Get the DirectX SDK: go to Tools\Check for Updates/Packages... and
      install the DirectX package. Close Dev-C++.

   3. Add '<tt>c:\DevCpp\bin</tt>' to the beginning of your <tt>PATH</tt> environment variable
      and set the environment variable MINGDIR to '<tt>c:\DevCpp</tt>'. If you use
      Windows 9x, you can add the lines
<textblock>
	 PATH=c:\DevCpp\bin;%PATH%
	 set MINGDIR=c:\DevCpp
<endblock>
      to your '<tt>c:\autoexec.bat</tt>' file and reboot. If you use Windows ME, you
      can run '<tt>msconfig</tt>', select the 'Environment' tab, then modify <tt>PATH</tt> and
      add <tt>MINGDIR</tt>. If you use Windows NT/2k/XP, you can open the Control
      Panel, click the 'System' applet, the 'Advanced' tab and finally the
      'Environment' button, then modify <tt>PATH</tt> and add <tt>MINGDIR</tt>.

</blockquote>
   Test the installation by typing the following on the command line:
   '<tt>gcc -v</tt>'. The answer should be similar to:
<textblock>
      Reading specs from ../lib/gcc-lib/mingw32/3.2/specs
      Configured with: ../gcc/configure --with-gcc --with-gnu-ld
      --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw
      --enable-threads --disable-nls --enable-languages=f77,c++,objc,ada
      --disable-win32-registry --disable-shared
      Thread model: win32
      gcc version 3.2 (mingw special 20020817-1)
<endblock>
   If you don't know how to open a terminal, you can click on '<tt>Start -&gt Run</tt>'
   then type "<tt>command</tt>". Under Windows 2k/XP, you should type "<tt>cmd</tt>" instead.



@heading
Setting up Cygwin to build Allegro

   The procedure is as follows:
<blockquote>
   1. Make sure you have a working Cygwin installation. You can download the
      <tt>setup.exe</tt> program from '<link>http://sources.redhat.com/cygwin/</a>'.
      You will need the followin packages: bash, binutils, cygwin, cygutils,
      fileutils, gcc, gdb, login, make, man, mingw-runtime, sed, sh-utils,
      texinfo, textutils and w32api.

   2. Get the minimal DirectX 7 SDK for MinGW. (<tt>dx70_mgw.zip</tt>) Download it
      from '<link>http://alleg.sourceforge.net/wip.html</a>' and unzip it to a
      temporary directory, for instance '<tt>C:\Temp</tt>'. Then move the contents of
      '<tt>C:\Temp\lib</tt>' to '<tt>C:\cygwin\lib\w32api</tt>', and the contents of
      '<tt>C:\Temp\include</tt>' to '<tt>c:\cygwin\usr\include\w32api</tt>'. If you are asked
      if you want to overwrite any existing files, choose to overwrite them.

   3. Put the following text in '<tt>/etc/profile</tt>' (<tt>c:\cygwin\etc\profile</tt>)
<textblock>
	 export ALLEGRO_USE_CYGWIN=1
	 export MINGDIR=/usr/local
	 export CPATH=/usr/local/include
	 export LIBRARY_PATH=/usr/local/lib
<endblock>
      Note: if the <tt>CPATH</tt> or <tt>LIBRARY_PATH</tt> variables are already set, you will
      have to append the new path to the existing one by using a colon (":")
      as the separator.

</blockquote>
   Test the installation by typing the following in the Bash shell:
   '<tt>gcc -v</tt>'. The answer should be similar to:
<textblock>
      Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2/specs
      gcc version 3.2 20020927 (prerelease)
<endblock>
   Note: if you have problems installing the profiling version of the Allegro
   library, you will probably need to copy a file called <tt>libgmon.a</tt> from the
   MinGW distribution to your <tt>/lib/mingw</tt> directory (<tt>c:\cygwin\lib\mingw</tt>) in
   Cygwin. This is expected to be fixed in a later release of the
   mingw-runtime package (I'm currently using mingw-runtime-1.2-1).



@heading
Cross compilation

   The procedure is as follows:
<blockquote>
   1. Download and install the MinGW cross-compiler. You can get the
      software:
      
      <ul><li>directly from the MingW site: <link>http://sourceforge.net/projects/mingw/</a>.
         
         You need the following packages (as of February 2003):
         
            <ul><li>gcc (<tt>gcc-3.2.2-20030208-1-src.tar.gz</tt>)
            <li>binutils (<tt>binutils-2.13.90-20030111-1-src.tar.gz</tt>)
            <li>mingw runtime (<tt>mingw-runtime-2.4.tar.gz</tt>)
            <li>w32api (<tt>w32api-2.2.tar.gz</tt>)
            </ul>
         Optionally, you can get from the SDL site,
         <link>http://www.libsdl.org/extras/win32/common</a>: opengl-devel
         (<tt>opengl-devel.tar.gz</tt>)
      
      <li>using a more convenient script with instructions for downloading:
      <link>http://www.libsdl.org/extras/win32/cross/README.txt</a>.
      Follow the instructions, and make sure to edit the build-crosh.sh
      script so it downloads the most recent version of gcc and binutils.

      <li>as a premade Debian package called '<tt>mingw32</tt>', which you can install
      with '<tt>apt-get install mingw32</tt>'.
      </ul>
   2. Get the minimal DirectX 7 SDK for MinGW (<tt>dx70_mgw.zip</tt>).
      Download it from '<link>http://alleg.sourceforge.net/wip.html</a>' and unzip it
      in the cross-compiler base directory. Make sure you convert all text
      files to unix style (<tt>unzip -a</tt>) or the preprocessor will croak. The
      DirectX package downloaded and installed by the SDL script is not up
      to date: replace it with the package from the Allegro site.

   3. Edit the file '<tt>xmake.sh</tt>' in the root of your Allegro directory,
      replacing <tt>XC_PATH</tt>, <tt>XPREFIX</tt> and <tt>INSTALL_BASE</tt> with the right names.
      For example, if your compiler's base dir (the one with bin, lib and
      include sub-folders) is <tt>/usr/i586-mingw32msvc</tt>, and you have prefix-less
      binaries in <tt>/usr/i586-mingw32msvc/bin</tt>, you would use:
<textblock>
	 XC_PATH=/usr/i586-mingw32msvc/bin
	 XPREFIX=
	 INSTALL_BASE=/usr/i586-mingw32msvc
<endblock>
      Note that the <tt>build-cross.sh</tt> script from SDL installs binaries both
      with and without prefix, but some binaries (windres specifically)
      are installed only with prefix. If you installed the crosscompiler
      in <tt>/opt/cross-tools</tt> using this script, you would use:
<textblock>
	 XC_PATH=/opt/cross-tools/i386-mingw32msvc/bin:/opt/cross-tools/bin
	 XPREFIX=i386-mingw32msvc-
	 INSTALL_BASE=/opt/cross-tools/i386-mingw32msvc
<endblock>
   4. Run '<tt>./fix.sh mingw --dtou</tt>' (<tt>--dtou</tt> is only needed if your Allegro
      directory has text files in DOS format, otherwise you can use <tt>--quick</tt>).
      If you are using a CVS version of Allegro, run '<tt>make depend</tt>' to
      generate the build dependencies, then run '<tt>misc/fixdll.sh</tt>' to generate
      the <tt>allegro.def</tt> file. You are now finished with all the preparations.

   5. You can now run '<tt>./xmake.sh</tt>' to build the Allegro library and then run
      '<tt>./xmake.sh install</tt>' as root to install it. Afterwards, you can use
      '<tt>xmake.sh</tt>' as you would use '<tt>make</tt>' to compile your Allegro programs, or
      you can use the '<tt>cross-make.sh</tt>' and '<tt>cross-configure.sh</tt>' scripts from
      the SDL site. You must use '<tt>xmake.sh</tt>' to compile Allegro itself though.

   6. To build the documentation, use the native build process. This
      limitation will eventually be removed.
</blockquote>


@heading
Installing Allegro

   This assumes you have unzipped allegro to <tt>c:\allegro</tt> or, if you are using
   MSYS, you have unzipped it to <tt>c:\msys\allegro</tt> (which is equivalent to
   <tt>/allegro</tt> from within the MSYS environment) or, if you are using Cygwin,
   you have unzipped it to <tt>c:\cygwin\allegro</tt> (which is equivalent to
   <tt>/allegro</tt> from within the Cygwin environment).

   First configure Allegro for MinGW. Unless you are using MSYS or Cygwin,
   enter the following on the commandline (click on '<tt>Start -&gt Run</tt>' then type
   "<tt>command</tt>" or "<tt>cmd</tt>" to get a command prompt):
<textblock>
      cd c:\allegro
      fix.bat mingw
<endblock>
   If you are using MSYS or Cygwin, start your environment, which you can
   find either on your desktop and/or on your Windows start menu. The
   following commands should then be used instead of the ones above:
<textblock>
      cd /allegro
      ./fix.sh mingw --dtou   (--dtou can be replaced by --quick for MSYS).
<endblock>
   Now you're ready to build the Allegro library with:
<textblock>
      make (or mingw32-make if you are using a recent version of MinGW)
<endblock>
   The dynamically linked version of Allegro gets built by default. If you
   want to build the statically linked version of Allegro, use:
<textblock>
      make STATICLINK=1
<endblock>
   If you want to build either the debug or the profile version of the
   library, enter one of the following commands:
<textblock>
      make DEBUGMODE=1 (dynamically linked)
      make DEBUGMODE=1 STATICLINK=1 (statically linked)
      make PROFILEMODE=1 (dynamically linked)
      make PROFILEMODE=1 STATICLINK=1 (statically linked)
<endblock>
   A list of all the available options:
<blockquote><dl>
      <dt><tt>CROSSCOMPILE</tt></dt><dd>
	 Set this if you are crosscompiling; it implies <tt>UNIX_TOOLS</tt>.</dd>

      <dt><tt>WARNMODE</tt></dt><dd>
	 Set this if you want Allegro to display and stop on nearly all
	 warnings issued by the compiler. Allegro should compile fine with
	 this set.</dd>

      <dt><tt>TARGET_ARCH_COMPAT</tt>
	 or
      <tt>TARGET_ARCH_EXCL</tt></dt><dd>
	 These affect the level of processor dependant optimisation that
	 Allegro uses. You can set either of these to the processor type you
	 want to optimize for. The difference between these two is that
	 <tt>TARGET_ARCH_COMPAT</tt> optimise for the given processor so that the code
	 will still run on older processors, while <tt>TARGET_ARCH_EXCL</tt> will
	 generate code that will run exclusively on the given processor and of
	 course newer ones. Example: set <tt>TARGET_ARCH_COMPAT=i686</tt></dd>

      <dt><tt>TARGET_OPTS</tt></dt><dd>
	 Affects the general optimisations that Allegro uses.</dd>

      <dt><tt>UNIX_TOOLS</tt></dt><dd>
	 If your system does not have the usual DOS tools available (`<tt>md</tt>',
	 `<tt>rd</tt>', `<tt>copy</tt>', etc., and commands which understand the <tt>\</tt> character),
	 then set this to 1 to use the Unix equivalents. This is set
	 implicitly when you set <tt>CROSSCOMPILE</tt>, and is also set automatically
	 when you are running under bash.</dd>
</dl></blockquote>
   To activate any of these, type (for example) "<tt>make WARNMODE=1</tt>".

   If your copy of Allegro does not include the linker .def file (unlikely,
   unless you have run "<tt>make veryclean</tt>" at some point, or are using the CVS
   version of Allegro), you can regenerate it by running "<tt>misc\fixdll.bat</tt>".
   You will need to have GNU sed and sort installed for this operation to
   work. The version of sed that is linked from the MinGW site does not
   work properly; it has issues with end-of-line characters. You should get
   sed and sort from the link at the top of this document.

   Once the build is finished you can recover some disk space by running
   "<tt>make compress</tt>", which uses the UPX program to compress the executable
   files and the optimized dll. Before running "<tt>make compress</tt>", you must set
   the environment variable <tt>UPX_BIN</tt> to point to <tt>upx.exe</tt>. You will have to
   do run "<tt>make compress</tt>" before "<tt>make install</tt>" if you want the compressed
   dll to be copied to the windows directory. To recover even more disk
   space, you can run "<tt>make clean</tt>" to get rid of all the temporary files and
   HTML format documentation.

   And then the last thing, installing the library. Run:
<textblock>
      make install
<endblock>
   with the same options you passed to '<tt>make</tt>' in order to build the library.

   You have now installed Allegro! See the rest of the documentation and
   examples to learn more about it.



@heading
Using Allegro

   All the Allegro functions, variables, and data structures are defined 
   in <tt>allegro.h</tt>. You should include this in your programs, and link with
   either the optimised library <tt>liballeg.a</tt>, the debugging library
   <tt>liballd.a</tt>, or the profiling library <tt>liballp.a</tt>. You should include the
   Allegro DLLs in any software you release to the public.

   When using a statically linked library, you must define the preprocessor
   symbol <tt>ALLEGRO_STATICLINK</tt> before including any of the Allegro headers and
   link your program against Allegro and the main Win32/DirectX libraries
   in that order (see the variable <tt>LIBRARIES</tt> in <tt>makefile.mgw</tt>). The names of
   the statically linked Allegro libraries are post-fixed with '<tt>_s</tt>' so that
   you will link with either <tt>liballeg_s.a</tt>, <tt>liballd_s.a</tt> or <tt>liballp_s.a</tt>.

   Don't forget that you need to use the <code>END_OF_MAIN()</code> macro right after
   your <code>main()</code> function.



@heading
Compiling manually with MinGW

   A simple example of a command line to compile an Allegro program with
   MinGW looks like:
<textblock>
      gcc foo.c -Wl,--subsystem,windows -O2 -Wall -o foo.exe -lalleg
<endblock>
   If you are compiling with Cygwin, the compiler option '<tt>-mno-cygwin</tt>' must
   be added, both at compile-time and at link-time:
<textblock>
      gcc foo.c -Wl,--subsystem,windows -mno-cygwin -O2 -Wall -o foo.exe -lalleg
<endblock>
   Note that, if you want to make a console application, you must use
   '<tt>-Wl,--subsystem,console</tt>' instead of '<tt>-Wl,--subsystem,windows</tt>'.



@heading
Creating a program with Dev-C++

   A simple example on how to create a little program with Dev-C++:

   Launch Dev-C++ and create a new project (File/New Project). Select
   "Windows Application", then click on the "Ok" button. Name your
   project and give associate it to a new file. You should now see a
   sample code in a window. Close that window since you won't be
   needing it (Allegro is much simpler to use than this). Create a
   new file (File/New Source File), then write a small Allegro
   program. You can inspire yourself by the Allegro examples if you
   wish. Here's a small program you can type to see if everything
   worked until now:
<codeblock>
      #include &ltallegro.h&gt

      int main() {
         allegro_init();
         allegro_message("Hello World!");
         return 0;
      }
      END_OF_MAIN()
<endblock>
   You now need to tell Dev-C++ that you'd like to make a program that
   uses Allegro. For that, go in the Project Options screen
   (Project/Project Options menu), then enter <tt>-lalleg</tt> (or <tt>-lalld</tt> for
   the debug mode) in the box under 'Further object file or linker
   options' or select 'Parameters tab' and enter -lalleg (or -lalld for
   the debug mode) in the box under 'Linker'.

   Compile your project! Simply click on the green check mark on
   your Dev-C++ toolbar. Correct any syntax errors in your code,
   then click on "Execute" to run the program. If all worked
   you will see a message box pop up with "Hello World" inside of it.

   Happy coding!
