Search code examples
makefileautoconfautomakeallegro5

How should I link libraries in automake normally linked with pkg-config?


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?


Solution

  • 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