How can I link an executable in say test subdirectory of an autotools project against a library, say libfoo, that is just built from files in src directory of same project?
Makefile.am looks like:
SUBDIRS = src . test
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
src/Makefile.am:
ACLCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
lib_LTLIBRARIES = libfoo.la
libfoo_la_SOURCES = \
foo.cpp
foo_includedir = $(includedir)/foo
foo_include_HEADERS = \
foo.hpp
test/Makefile.am:
ACLCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
check_PROGRAMS = footest
footest_SOURCES = \
main.cpp
footest_LDADD = ?????
That's easy: footest_LDADD = ../src/libfoo.la
This works for 'out-of-tree' builds, e.g., if you invoke configure from another directory (not ./configure).
Related
I have a Makefile where within:
TARGETDIR=../rel/$(PLATFORM)
ANALYZER=$(TARGETDIR)/analyzer
TARGETS=$(ANALYZER)
XMLFILE=pgns.xml
JSONFILE=pgns.json
all: $(TARGETS)
$(ANALYZER): analyzer.c pgn.c analyzer.h pgn.h ../common/common.c ../common/common.h Makefile
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $(ANALYZER) -I../common pgn.c analyzer.c ../common/common.c $(LDLIBS$(LDLIBS-$(#)))
json: $(ANALYZER) pgns2json.xslt
$(ANALYZER) -explain-xml >$(XMLFILE) && xsltproc pgns2json.xslt $(XMLFILE) >$(JSONFILE)
$(ANALYSER) gets compiled and is stored in TARGETDIR. Now in json the analyzer binary is called which provides
| /bin/sh: ../rel/linux-x86_64/analyzer: cannot execute binary file: Exec format error
because upon file analyzer it show the file as ELF 32-bit file. I understand incompatibility here.
This has been addressed in the my Previous SE Query.
Since I cannot get around this issue; I was thinking of using the json call in a postinstall script in my Recipe.
But I cannot wrap my head around it. These are the steps I have drawn up:
I modify the Makefile which removes json
Should I add DEPENDS = "libxslt libxml2 ?
Should I add RDEPENDS_{PN} = "bash" to execute the command for json?
how should the post-install look like for the recipe?
The Recipe:
SUMMARY = "CANBOAT"
SECTION = "base"
LICENSE = "GPLv3"
#DEPENDS = "libxml2 libxsl"
LIC_FILES_CHKSUM = "file://GPL;md5=05507c6da2404b0e88fe5a152fd12540"
S = "${WORKDIR}/git"
SRC_URI = "git://github.com/canboat/canboat.git;branch=${SRCBRANCH}"
SRCBRANCH = "master"
SRCREV = "93b2ebfb334d7a9750b6947d3a4af9b091be2432"
EXTRA_OEMAKE = "'CC=${CC}' 'AR=${AR}'"
do_compile() {
oe_runmake
}
do_install() {
oe_runmake install
}
#post_install() { # here? what will be the structure}
analyzer is a tool that is used to generate some artifacts and is not necessarily needed to be compiled for target in a cross compile environment , rather it needs a platform to run (build host) and input file.
SUMMARY = "CANBOAT"
SECTION = "base"
LICENSE = "GPLv3"
DEPENDS += "libxslt-native canboat-native"
LIC_FILES_CHKSUM = "file://GPL;md5=05507c6da2404b0e88fe5a152fd12540"
SRC_URI = "git://github.com/canboat/canboat.git;branch=${SRCBRANCH} \
file://0001-Do-not-use-root-user-group-during-install.patch \
file://0001-Define-ANALYZEREXEC.patch \
file://0001-use-php-instead-of-php5.patch \
"
SRCBRANCH = "master"
SRCREV = "93b2ebfb334d7a9750b6947d3a4af9b091be2432"
S = "${WORKDIR}/git"
PREFIX ?= "${root_prefix}"
#PREFIX_class-native = "${prefix}"
EXTRA_OEMAKE_append_class-target = " ANALYZEREXEC=analyzer "
do_compile() {
oe_runmake
}
do_install() {
oe_runmake DESTDIR=${D} PREFIX=${root_prefix} EXEC_PREFIX=${exec_prefix} install
}
RDEPENDS_${PN}_append_class-target = " php-cli perl"
BBCLASSEXTEND = "native nativesdk"
The extra patches you need to cross compile canboat are here
0001-Define-ANALYZEREXEC.patch
0001-Do-not-use-root-user-group-during-install.patch
0001-use-php-instead-of-php5.patch
In my src directory, I have source files such as cells.c. When I perform a compilation, the compiler prefixes the object file with the package name, so that it becomes neoleo-cells.o, for example. Why is it doing this, and how can I stop it? I don't think it's standard behaviour.
Here is Makefile.am:
#VPATH = $(srcdir) $(builddir)
GUI_SRCS =
GUI_LINK =
#GUI_DEFINES = -DX_DISPLAY_MISSING
GUI_DEFINES = -DHAVE_X
# Order of linking of libraries for Motif seems to be important
# I have decided to mandate the use of the Xbae library, rather than
# have it optional.
if UseMotif
GUI_SRCS += io-motif.c appres.c fallback.c oleo_icon.xpm
GUI_LINK += -lXm -lXt -lXbae
GUI_DEFINES += -DHAVE_MOTIF
endif
GUI_SRCS += io-x11.c xrdb.c
GUI_LINK += -lX11
YFLAGS = -d
EXTRA_DIST = $(srcdir)/neoleo.i
bin_PROGRAMS = neoleo
BUILT_SOURCES = getdate.c parse.c parse.h posixtm.c posixtm.h
#BUILT_SOURCES += neoleo_wrap.c
CLEANFILES = $(BUILT_SOURCES)
#lib_LTLIBRARIES = libneoleo.la
neoleo_CFLAGS = $(GUI_DEFINES) -Dmain0=main
neoleo_LDADD = -lm -lncurses -lpthread $(GUI_LINK)
#neoleo_LDFLAGS = -e main0
#neoleo_la_LDFLAGS = -module -avoid-version -shared
neoleo_SOURCES = afm.c args.c basic.c busi.c byte-compile.c cells.c cmd.c date.c decompile.c display.c \
epson.c eval.c font.c format.c forminfo.c funcs.c graph.c gsl.c hash.c help.c \
info.c init.c input.c \
io-headless.c io-curses.c io-edit.c io-term.c io-utils.c \
ir.c key.c legend.c line.c list.c lists.c mdi.c oleofile.c pcl.c plot.c \
postscript.c print.c prtext.c ref.c regions.c sc.c sort.c string.c stub.c sylk.c utils.c \
window.c \
defuns.c \
get_date.h getdate.y \
parse.y \
posixtm.y \
neoleo_swig.c \
mysql.c $(GUI_SRCS)
noinst_HEADERS = afm.h appres.h args.h basic.h byte-compile.h cell.h \
cmd.h decompile.h defun.h defuns.h display.h epson.h \
errors.h eval.h font.h format.h forminfo.h funcdef.h \
funcs.h global.h graph.h hash.h help.h info.h init.h \
input.h io-abstract.h io-headless.h io-curses.h io-edit.h \
io-generic.h io-motif.h io-term.h io-utils.h io-x11.h \
ir.h key.h line.h list.h lists.h mdi.h mysql.h node.h \
oleofile.h oleo_plot.h oleosql.h oleo_xb.h parse.h pcl.h \
posixtm.h postscript.h print.h proto.h prtext.h ref.h \
regions.h sc.h sciplot.h sciplotI.h sort.h stub.h stubs.h \
sylk.h sysdef.h userpref.h utils.h window.h \
neoleo_swig.h
# exclude these for now:
# plotter.c xbase.cpp
ref.o : parse.h
#neoleo_wrap.c : $(srcdir)/neoleo.i neoleo_swig.c neoleo_swig.h
# swig -tcl8 -o $# $<
This line causes the rename of the object files:
neoleo_CFLAGS = $(GUI_DEFINES) -Dmain0=main
If you have target-dependent compilation flags, Automake chooses different names for the resulting object files. This approach avoids clashes if there are multiple different targets that use the same sources but different flags.
Now, Automake could in theory notice that this isn't happening and not rename the object files. However, in practice most people don't care what the intermediate files are called, and this approach, I believe, simplified the implementation.
In your case, it sounds like you do care. So, just rename that variable to AM_CFLAGS and everything should work as you expect.
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?
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
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
I try to add LDLIBS=-lm to my makefile, to link math.h, but I get the same error as before "sin undeclared " function. Here is part of my makefile:
I appreciate your help in advance.
LDLIBS=-lm
ACLOCAL_AMFLAGS = -I m4
bin_PROGRAMS = \
kdv
kdv_SOURCES = kdv.c vector.c
lib_LIBRARIES = liblinalg.a
liblinalg_a_SOURCES = \
kdv.h \
vector.c
LDADD = liblinalg.a
TESTS = \
kdv
I am a beginner in using autotool, I want to add some shell script in the Makefile.am, when I use the method below, the Makefile created by autotool is not I am expected. How can I write to create the correct one.
Thanks for your reply!
PS:
this is my configure.in and Makefile.am(parts)
configure.in:
if test "$sample" = yes;then
DEFS="$DEFS -DSAMPLE=1"
AC_SUBST(SAMPLE, [yes])
fi
Makefile.am:
if test "$SAMPLE" = yes;then
noinst_PROGRAMS = test
test_SOURCES = test.c
else
bin_PROGRAMS = release
release_SOURCES = main.c
fi
Makefile autotool created:
........
........
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libLTLIBRARIES clean-libtool clean-noinstPROGRAMS ctags \
distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am \
install-includeHEADERS install-info install-info-am \
install-libLTLIBRARIES install-man install-pdf install-pdf-am \
install-ps install-ps-am install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-includeHEADERS \
uninstall-libLTLIBRARIES
if test "yes" = yes;then
fi
Automake conditionals don't work like that. See the manual.
Here's how it should look:
configure.ac:
AM_CONDITIONAL([SAMPLE], [test "$SAMPLE" = yes])
Makefile.am:
if SAMPLE
noinst_PROGRAMS = test
test_SOURCES = test.c
else
bin_PROGRAMS = release
release_SOURCES = main.c
endif