How to pack data files using GNU autoconf and automake

I am a fairly new C ++ programmer. I made a very simple game using the SDL libraries. Naturally, my game uses some images, sounds and fonts. I wanted to make a distribution package where the user can configure && do. This is not how this simple game is worth distributing, but I want to know how autoconf and automake work. I searched for examples on the Internet, but the tutorials that I could find only show the installation of the simple helloworld program. They say neither about installing data files, nor about how to check if certain libraries exist so that I can reference them at compile time. In addition, my program needs to know where each file will be installed so that it can download them. I delved into the machines and autoconf manuals, but they are more like reference materials than resources for new users. Can someone briefly explain this concept or lead me to some place where I could read about them.

+6
source share
1 answer

I did some research on this, and I wanted to share what worked for me. I 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 put all my images, fonts, sounds, etc. to the data folder. Makefile.am in the data folder is as follows:

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

It simply lists all the files that should be in the data directory. The Makefile.am file in the src folder is as follows:

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

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

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

So, your program will be compiled, knowing where the background file should be in the file system.

+13
source

Source: https://habr.com/ru/post/908220/


All Articles