Intro: compiling your game with VgaGames

For compiling your game with VgaGames use "vgag2-config".
"vgag2-config --cflags" outputs all needed "-I" compiler-flags.
"vgag2-config --libs" outputs all needed libraries with "-L" and "-l".
"vgag2-config --version" outputs the installed VgaGames2-version as a numerical value.
You may concatenate --cflags and --libs:  vgag2-config --cflags --libs

Distributing your game

With VgaGames2 you have two possibilities to give your new game to your
friend Fred:
 a) you assume, he already has an installed VgaGames2 version
 b) or you include in your game a local version of VgaGames2
For both possibilities Fred has to compile the game, before he can play it.


For the following descriptions we use "mygame" as an example:
  mygame/Makefile   # Makefile for compiling game
  mygame/main.c     # main function
  mygame/game.c     # game loop, called from main function
  mygame/bitmaps/   # contains all bitmaps
  mygame/sounds/    # contains all sounds
  mygame/sprites/   # contains all sprites
  mygame/share/     # contains optional colormaps and fonts
                    # and is used for saving properties (.vgag2.rc)
To compile, you have to type:
  cc -O2 `vgag2-config --cflags` main.c game.c `vgag2-config --libs` -o mygame

a) Your friend Fred has already an installed VgaGames2 version

You give to him only your game, he unpacks it and types "make".
Your Makefile:
  CFLAGS = -O2

  # check for installed version of VgaGames, then make your game
  mygame: check_version main.c game.c
  	$(CC) $(CFLAGS) `vgag2-config --cflags` -o mygame main.c game.c `vgag2-config --libs`

  # clean (clean also saved properties)
  	rm -f *.o mygame share/.vgag2.rc

  # check for installed version of VgaGames
	@test `vgag2-config --version` -ge 201 || { \
	  echo "You need VgaGames version 2.01 or higher"; \
	  exit 1; \
<== b) You include in your game a local version of VgaGames2 The advantage is that Fred need not have installed any version of VgaGames. This included local version will be installed under "mygame/" and nowhere else in Freds system. The disadvantage is that compiling VgaGames may fail due to missing sound- or graphic libraries (no ALSA, OSS, SUN-Audio or no console library and no X-headers). What you have to do, is: - unpack the source of VgaGames under "mygame/share/" which creates directory "vgagames-X.XX/" (where X.XX is the actual version) - you only need subdirectory "src/" and "share/" - you have to modify your "Makefile" as shown later You now have: mygame/Makefile mygame/main.c mygame/game.c mygame/bitmaps/ mygame/sounds/ mygame/sprites/ mygame/share/ mygame/share/vgagames-X.XX/ mygame/share/vgagames-X.XX/COPYING mygame/share/vgagames-X.XX/src/ # with all files mygame/share/vgagames-X.XX/share/ # with all files To modify your Makefile, you have to insert the local-installing of VgaGames and to prepend a path to "vgag2-config". Your modified Makefile: ==>
  CFLAGS = -O2
  # two new variables, we assume version of VgaGames is 2.01
  VGAG_SOURCEPATH = share/vgagames-2.01/src
  VGAG_PATH = share/vgagames/bin

  # make game: at first install VgaGames, then make your game, using VGAG_PATH
  mygame: vgagames-install main.c game.c
  	$(CC) $(CFLAGS) `$(VGAG_PATH)/vgag2-config --cflags` -o mygame main.c game.c `$(VGAG_PATH)/vgag2-config --libs`

  # install VgaGames (using parameter "-local")
  	(cd $(VGAG_SOURCEPATH) && ./ -local && make all install)

  # clean: uninstall VgaGames and make clean
  clean: vgagames-uninstall
  	rm -f *.o mygame share/.vgag2.rc

  # uninstall VgaGames
  	(cd $(VGAG_SOURCEPATH) && make uninstall clean)
<== As you see, "vgag2-config" is prepended with share/vgagames/bin, the check for the VgaGames-version is removed (because not needed), and "vgagames-install" and "vgagames-uninstall" are inserted. The "" of VgaGames is called with parameter "-local", which indicates a local installation into "../../vgagames/". Source files under "src/" If your Makefile, main.c and game.c were in a "src/" directory: mygame/src/Makefile mygame/src/main.c mygame/src/game.c mygame/share/ mygame/share/vgagames-2.01/ ... then you had to change VGAG_SOURCEPATH and VGAG_PATH in your Makefile: VGAG_SOURCEPATH = ../share/vgagames-2.01/src VGAG_PATH = ../share/vgagames/bin Compiling only a part of the VgaGames package If your game e.g. has no ".mid" soundfiles, you could pass the tmidi-compiling of the local VgaGames version. Edit share/vgagames-X.XX/src/Makefile.tmpl - remove in target "all:" the entry "tmidi.d" For no support of ".mp3" soundfiles, remove "mp3.d". Executing the game Fred now can use the compiled binary "mygame" with all found graphic libraries, e.g. with svgalib and X-window. If he wants to use a console library like svgalib or libvgl he must be root or change the mode of his binary to 04755 (setuid bit) for root. Alternative for a Makefile Refer to ../tutorial/game/src/Makefile, linking .o-files instead of .c-files. Back to Index