Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to package data files with GNU's autoconf and automake

I am a rather new C++ programmer. I have made a very simple game using SDL libraries. My game, naturally, uses some images, sounds and fonts. I have wanted to make a distribution of the package, where user's can configure && make . It's not like this simple game is worth distributing, but I want to learn how autoconf and automake works. I searched for the examples around the internet but tutorials I could find shows only installation of a simple helloworld program. They neither talk about installation of data files, nor how to check for if certain libraries exists so that I could link against them in compile time. And also, my program should know where each file get installed so that it can load them. I have delved into automake and autoconf manuals, but they are more like a reference materials than being a resource for new comers. Could anyone briefly explain this concepts, or lead me to some place where I could read about them.

like image 960
yasar Avatar asked Feb 11 '12 17:02

yasar


1 Answers

I have made some research on this, and I have wanted to share what has worked for me. I have created a directory structure like this:

/
|->src/
|   |-> Makefile.am
|   |-> main.cpp
|   |-> functions.cpp
|
|-> data/
|   |-> Makefile.am
|   |-> somethings.png
|   |-> something.mp3
|-> configure.ac
|-> README
|-> NEWS, AUTHORS etc. etc.

I have put all my images, fonts, sounds etc. in data folder. Makefile.am on data folder looks like this:

pkgdata_DATA = esound.wav \
               another.wav \
               apicture.png

It simply lists all the files that need to be end up in the data directory. The Makefile.am in the src folder look like this:

bin_PROGRAMS = mygame
mygame_SOURCES = main.cpp functions.cpp
AM_CPPFLAGS = -DDATADIR=\"$(pkgdatadir)\"

The important part here is AM_CPPFLAGS, which defines DATADIR macro, according to the options passed to the configure script. So then we can use this macro in our source files like this:

background = load_image( DATADIR "/background.png");

So that your program will get compiled knowing where background file should reside in the filesystem.

like image 108
yasar Avatar answered Sep 19 '22 01:09

yasar