Pre compiled versions of various libraries can be found on the Xmingw32 page. To install the libraries for cross-compiling, extract them with the following command, which most likely must be run as root:
tar --directory=/usr/local -xzf LibName.tar.gz
The easiest way to configure and build an SDL project is to use GNU Autoconf and Automake. These tools allow you to easily compile your project for Linux and Win32, along with alerting the user of any problems that will hinder the build process (such as libraries being missing). Use of these tools will also help your project compile on a much wider range of platforms than if you were to use home grown make files. Another benefit is that you will not have to go to the trouble of setting up make files on your own, and maintaining them as the project changes. Autoconf and Automake scripts are generally much simpler to maintain than normal make files.
I would guess that the reason most people choose to use their own make files and scripts rather than Autoconf and Automake is because it looks complicated to set up and use. It seemed a little intimidating at first for me too, but once I started playing with it and found out how easy it makes everything, I would never go back. I have only used Autoconf and Automake for SDL projects, so I can only comment on my experiences with them in that capacity. Setting up a project involves taking the standard Autoconf files along with the SDL additions and modifing a couple other files for the specifics of the project. To simplify creating new projects, I created a skeleton project, stest, that contains everything needed to build an SDL project using Autoconf and Automake, along with some scripts that make the process even easier.
The first thing you will need to do is to change the project name. The easiest way to find the files in which is needs to be changed is to use grep:
/stest$ grep -r stest * build-win32.sh:PROGNAME=stest clean.sh:PROGNAME=stest configure.in:PROJ_NAME=stest README:stest src/Makefile.am:bin_PROGRAMS = stest src/Makefile.am:stest_SOURCES = main.cpp src/Makefile.am:#stest_LDADD = @GL_LIBS@
You can use grep be certain that you have changed all instances of the project name. It is important to make sure that the project name is the same in all places, or else the scripts will not work properly. Note that README is merely a dummy file used by the Autoconf script and the only requirement for it is that it exists. The cross-configure.sh and cross-make.sh scripts are the same as the ones found on the Xmingw32 page and are used for cross-compiling on Linux for Win32. These scripts are included for convience. I find it useful to put copies of them in /usr/local/bin for use compiling other projects, such as the SDL libraries, or even SDL itself. The build-linux.sh and build-win32.sh scripts are included to make it easy to build a Linux or Win32 executable without typing multiple commands. Because the scripts run configure and make clean each time they are run, it can be time consuming to run them everytime a change to the project is made. After running one of them the first time, a simple make or ./cross-make.sh will suffice to build the project. The build-win32.sh script adds the .exe extension to the program and removes the executable bit after a successful build, so if you are completing a partial compile by just running ./cross-make.sh, it can be useful to run build-win32.sh as a final step.
The two project specific files that will need to be modified are configure.in and src/Makefile.am. Because I use C++, configure.in is setup to check for a C++ compiler (AC_PROG_CXX) and the standard C++ library. If you will only be using C for your project, you can probably remove these. No additional libraries besides SDL and OpenGL are checked. Adding additional libraries such as SDL_image is fairly simple:
# Check for SDL_image library AC_CHECK_LIB(SDL_image, IMG_LoadPNG_RW, , AC_MSG_ERROR([ *** Unable to find SDL_image libary with PNG support (http://www.libsdl.org/projects/SDL_image/) ]))
The first parameter to AC_CHECK_LIB is the name of the library, as it would be passed to the linker following the -l. The second parameter is the name of a function in the library to check for existence (any function can be used, whether or not it has parameters, but only use the function name). Adding a library in this manner will cause the configure script to warn the user if the library does not exist, and will also add the library to the list of libraries to be linked with the project.
The other file that needs to be modified is Makefile.am. This file is what drives Automake and generates the makefiles for your project. You should only need to modify the file in the src/ directory. The one in the main directory can usually be left as-is. The bin_PROGRAMS line specifies name of the program, which will be what the executable is named. This should be the same as the name in build-win32.sh so that the .exe extension can be properly added. The projname_SOURCES line specifies all of the source files that will go into the executable. Because this list can become very long, it is common to only include one file per line and use a backslash at the end of each line (except for the last line). The #projname_LDADD = @GL_LIBS@ line can be used to link OpenGL with the project.
The autogen.sh script can be used to re-create all of the Autoconf and Automake files, and must be run anytime any of the Autoconf or Automake configuration files are changed. The only other script included is the clean.sh script. It basically deletes everything that would not belong with the project in CVS. After running the script, it will be necessary to run ./autogen.sh before being able to compile anything.
© 2001 David Phillips | david.acz.org |