2

I'm trying to get my project buildable with automake. Specifically while using Allegro5.

I can build my code using the following command just fine

g++ -std=c++0x *.cpp -o mygame $(pkg-config --libs allegro-5.0 \
allegro_acodec-5.0 allegro_audio-5.0 allegro_color-5.0 allegro_dialog-5.0 \
allegro_font-5.0 allegro_image-5.0 allegro_main-5.0 allegro_memfile-5.0 \
allegro_physfs-5.0 allegro_primitives-5.0 allegro_ttf-5.0)

But my Makefile will not work.

Here is my src/Makefile.am

bin_PROGRAMS = mygame

AM_CXXFLAGS = "-std=c++0x"

mygame_SOURCES = Animation.cpp Body.cpp GameObject.cpp Menu.cpp Vector3.cpp \
    Arena.cpp Button.cpp Keyboard.cpp Mesh.cpp Assets.cpp Character.cpp \
    main.cpp Mouse.cpp Barrier.cpp Environment.cpp Manager.cpp TitleMenu.cpp

mygame_LDADD = allegro-5.0 allegro_acodec-5.0 allegro_audio-5.0 \
    allegro_color-5.0 allegro_dialog-5.0 allegro_font-5.0 allegro_image-5.0 \
    allegro_main-5.0 allegro_memfile-5.0 allegro_physfs-5.0 \
    allegro_primitives-5.0 allegro_ttf-5.0

CLEANFILES = mygame *.o

And here is my configure.ac

AC_INIT(bayou, 0.1.0)
AM_INIT_AUTOMAKE

AC_LANG_CPLUSPLUS
AC_PROG_CXX
LT_INIT

AC_OUTPUT(
    Makefile \
    src/Makefile\
)

Running my first command works just fine. Running make gives me

make: *** No rule to make target `allegro-5.0', needed by 'mygame'.  Stop.

So how should I set up my configure.ac and Makefile.am's so I can use libraries I normally link with pkg-config?

DeepDeadpool
  • 1,441
  • 12
  • 36
  • I think I found out how to set up the command using -L and -lallegro. I will need to run `pkg-config --libs allegro-5.0 allegro_acodec-5.0 allegro_audio-5.0 allegro_color-5.0 llegro_dialog-5.0 allegro_font-5.0 allegro_image-5.0 allegro_main-5.0 allegro_memfile-5.0 allegro_physfs-5.0 allegro_primitives-5.0 allegro_ttf-5.0` to get a list of the libraries, then I will follow this question's answer. I will have to do that when I arrive home from work though. http://stackoverflow.com/questions/6560760/how-do-i-link-allegro-5-from-my-makefile – DeepDeadpool Apr 19 '16 at 15:58

2 Answers2

0

pkg-config is there to tell you dynamically which paths/flags to use. It is meant to be used dynamically, rather than to run it on your development machine and then copy'n'paste it into the makefile and then expect it to run on any deployment machine.

Here's an updated Makefile.am, based on your own answer:

bin_PROGRAMS = mygame
AM_CXXFLAGS = "-std=c++0x"

PKGLIBS=allegro-5.0 \
    allegro_acodec-5.0 allegro_audio-5.0 allegro_color-5.0 allegro_dialog-5.0 \
    allegro_font-5.0 allegro_image-5.0 allegro_main-5.0 allegro_memfile-5.0 \
    allegro_physfs-5.0 allegro_primitives-5.0 allegro_ttf-5.0
mygame_CXXFLAGS = $(shell pkg-config --cflags $(PKGLIBS)) $(AM_CXXFLAGS)
mygame_LDADD = $(shell pkg-config --libs $(PKGLIBS))


mygame_SOURCES = Animation.cpp Body.cpp GameObject.cpp Menu.cpp Vector3.cpp \
    Arena.cpp Button.cpp Keyboard.cpp Mesh.cpp Assets.cpp Character.cpp \
    main.cpp Mouse.cpp Barrier.cpp Environment.cpp Manager.cpp TitleMenu.cpp

it might be that in your setup, the entire allegro-foo doesn't need any special compiler-flags, but it might as well need some. therefore my example also sets the compiler-flags for your program (mygame_CXXFLAGS). finally, it get's rid of the unneeded CLEANFILES.

Also, you could go the autotools route, and use the PKG_CHECK_MODULES macro in your configure.ac

umläute
  • 28,885
  • 9
  • 68
  • 122
-1

My lead in the suggestion worked. I did not have to modify my configure.ac (though I probably should so I can verify expected packages are installed)

Anyway, I ran pkg-config <insert libs from comment here> in a terminal window, which gave the following output

-L/usr/local/lib -lallegro_acodec -lallegro_audio -lallegro_color 
-lallegro_dialog -lallegro_image -lallegro_main -lallegro_memfile 
-lallegro_physfs -lallegro_primitives -lallegro_ttf -lallegro_font
-lallegro

So my new Makefile.am looks like

bin_PROGRAMS = mygame

AM_CXXFLAGS = "-std=c++0x"

mygame_SOURCES = Animation.cpp Body.cpp GameObject.cpp Menu.cpp Vector3.cpp \
    Arena.cpp Button.cpp Keyboard.cpp Mesh.cpp Assets.cpp Character.cpp \
    main.cpp Mouse.cpp Barrier.cpp Environment.cpp Manager.cpp TitleMenu.cpp

mygame_LDADD = -Lusr/local/lib -lallegro_acodec \
    -lallegro_audio -lallegro_color -lallegro_dialog -lallegro_image \
    -lallegro_main -lallegro_memfile -lallegro_physfs -lallegro_primitives \
    -lallegro_ttf -lallegro_font -lallegro

CLEANFILES = mygame *.o

I'd like to thank the academy and my parents for seeing me through this trying time. They've meant so much to me! *blows kisses

DeepDeadpool
  • 1,441
  • 12
  • 36