I'm adding autotools features to a personal library but I have some problems. I precise that autotools are totally new for me.
.
|-- Makefile.am
|-- configure.ac
`-- socket++
|-- Makefile.am
|-- base_socket.cpp
|-- base_socket.hpp
|-- client.cpp
|-- client.hpp
|-- config.h
|-- config.h.in
|-- refcount++.hpp
|-- server.cpp
|-- server.hpp
|-- server.imp.hpp
`-- types
|-- Makefile.am
|-- simple_socket.cpp
|-- simple_socket.hpp
|-- simple_socket_stop.cpp
|-- simple_socket_stop.hpp
|-- text_buffered.hpp
`-- text_buffered.imp.hpp
Here is configure.ac
AC_INIT([socket++], [1.2], [[email protected]], [socket++], [http://dev.xif.fr/socketxx])
AM_INIT_AUTOMAKE([foreign -Wall])
AC_CONFIG_HEADERS([socket++/config.h])
AC_CONFIG_SRCDIR([socket++/base_socket.cpp])
AC_CONFIG_FILES([Makefile socket++/Makefile socket++/types/Makefile])
AC_CONFIG_MACRO_DIR([m4])
# Distribute additional compiler and linker flags
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])
# Checks for compilers
AC_PROG_CXX
AC_PROG_CC
AX_CXX_COMPILE_STDCXX_11
# Libtool
LT_INIT
LT_LANG([C++])
# Checks for header files
AC_CHECK_HEADERS([arpa/inet.h inttypes.h netdb.h netinet/in.h stddef.h sys/ioctl.h sys/socket.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
# Checks for library functions
AC_FUNC_ERROR_AT_LINE
AC_CHECK_FUNCS([gethostbyname inet_ntoa select socket strerror])
AC_OUTPUT
Here is socket++/Makefile.am
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
AM_CXXFLAGS = -I$(top_srcdir)/socket++ @AM_CXXFLAGS@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = types
lib_LTLIBRARIES = libsocket++.la
library_includedir=$(includedir)/socket++
library_include_HEADERS = refcount++.hpp base_socket.hpp client.hpp server.imp.hpp server.hpp
libsocket++_la_SOURCES = base_socket.cpp client.cpp server.cpp
socket++_libincludedir = $(libdir)/socket++/include
nodist_socket++_libinclude_HEADERS = config.h
libsocket++_la_LIBADD = types/libsocket++types.a
And finally socket++/types/Makefile.am
noinst_lib_LTLIBRARIES = libsocket++types.la
library_includedir=$(includedir)/socket++/types
library_include_HEADERS = simple_socket_stop.hpp simple_socket.hpp text_buffered.imp.hpp text_buffered.hpp
libsocket++types_la_SOURCES = simple_socket_stop.cpp simple_socket.cpp
All is fine with ./configure
But when I make
, I have this error :
make[3]: Entering directory '/root/socket++/socket++/types'
make[3]: *** No rule to make target 'libsocket++types.c', needed by 'libsocket++types.lo'. Stop.
That's strange because libsocket++types.c
was never defined in libsocket++types_la_SOURCES
I searched for a while but found nothing about phantoms file like this. Thanks in advance for the help !
There's just a few issues with the use of <prefix>_
primaries:
lib_LTLIBRARIES = libsocket++.la
results in a derived variable name of libsocket__
libsocket___includedir = $(includedir)/socket++
libsocket___include_HEADERS = ...
libsocket___la_SOURCES = ...
You can put header files in the _SOURCES
list as well. i.e., if a header is changed, make
will see that the library, or other dependents, must be recompiled.
What you've called a 'phantom' target, is typically referred to as a convenience library, where: libsocket++types.la
transforms to the libsocket__types_
prefix. The parent Makefile.am
should add include paths to AM_CPPFLAGS
. Since subdirs
will be descended first, you can add the convenience library with:
libsocket___la_LIBADD = types/libsocket++types.la
Also, it's noinst_LTLIBRARIES
not noinst_lib_LTLIBRARIES
.