Skip to content
Browse files

use autotools instead of plain Makefile

For better portability, build the shared library with autoconf,
automake and libtool.
  • Loading branch information...
1 parent 0e5a6d9 commit 4496a77219aa12c7e42b68162c20f948aae86099 @MaxKellermann MaxKellermann committed Nov 26, 2008
Showing with 190 additions and 7 deletions.
  1. +19 −0 .gitignore
  2. +0 −7 Makefile
  3. +17 −0 Makefile.am
  4. +14 −0 autogen.sh
  5. +121 −0 configure.ac
  6. +4 −0 libmpdclient.ld
  7. +15 −0 m4/cflags.m4
View
19 .gitignore
@@ -0,0 +1,19 @@
+*.cache
+aclocal.m4
+config.*
+configure
+build
+*.la
+*.lo
+*.loT
+*.o
+example
+libtool
+stamp-*
+Makefile
+Makefile.in
+.libs
+.deps
+.dirstamp
+.stgit*
+*~
View
7 Makefile
@@ -1,7 +0,0 @@
-CFLAGS = -Wall -ggdb
-SOURCES = example.c libmpdclient.c
-
-example: $(SOURCES)
-
-clean:
- rm -f *.o example
View
17 Makefile.am
@@ -0,0 +1,17 @@
+ACLOCAL_AMFLAGS = -I m4
+AUTOMAKE_OPTIONS = foreign 1.9 dist-bzip2
+
+doc_DATA = README
+
+lib_LTLIBRARIES = libmpdclient.la
+
+libmpdclient_la_SOURCES = \
+ libmpdclient.c libmpdclient.h
+
+libmpdclient_la_LDFLAGS = -version-info @LIBMPDCLIENT_LIBTOOL_VERSION@ \
+ -Wl,--version-script=libmpdclient.ld
+
+noinst_PROGRAMS = example
+
+example_SOURCES = example.c
+example_LDADD = libmpdclient.la
View
14 autogen.sh
@@ -0,0 +1,14 @@
+#!/bin/sh -e
+
+rm -rf config.cache build
+mkdir build
+libtoolize --force
+aclocal -I $PWD/m4
+autoconf
+autoheader
+automake --add-missing
+
+if test x$NOCONFIGURE = x; then
+ echo "./configure $*"
+ ./configure $*
+fi
View
121 configure.ac
@@ -0,0 +1,121 @@
+AC_PREREQ(2.60)
+AC_INIT(MPD client library for C, 2.0~git, max@duempel.org, libmpdclient)
+AC_CONFIG_SRCDIR([libmpdclient.c])
+AC_CONFIG_AUX_DIR(build)
+AM_INIT_AUTOMAKE([foreign 1.9 dist-bzip2])
+AM_CONFIG_HEADER([config.h])
+AC_CONFIG_MACRO_DIR([m4])
+
+LIBMPDCLIENT_LIBTOOL_VERSION=2:0:0
+AC_SUBST(LIBMPDCLIENT_LIBTOOL_VERSION)
+
+# Remove the check for c++ and fortran compiler
+m4_defun([_LT_AC_LANG_CXX_CONFIG], [:])
+m4_defun([_LT_AC_LANG_F77_CONFIG], [:])
+
+dnl Check for programs
+AC_PROG_CC_C99
+AC_PROG_INSTALL
+AC_PROG_LIBTOOL
+
+
+dnl
+dnl initialize variables
+dnl
+
+set -- $CFLAGS
+
+
+dnl
+dnl Check for libraries
+dnl
+
+dnl Try to find the socket functions
+AC_CHECK_FUNC([socket],
+ [],
+ [AC_CHECK_LIB([socket], [socket], [LIBS="$LIBS -lsocket"],
+ [AC_MSG_ERROR(No UNIX socket API found)])]
+)
+
+dnl Try to find the gethostbyname functions
+AC_CHECK_FUNC([gethostbyname],
+ [],
+ [AC_CHECK_LIB([nsl],[gethostbyname],[LIBS="$LIBS -lnsl"],
+ [AC_MSG_ERROR(No UNIX gethostbyname API found)])]
+)
+
+
+dnl
+dnl build options
+dnl
+
+AC_ARG_ENABLE(werror,
+ AS_HELP_STRING([--enable-werror],
+ [Treat warnings as errors (default: disabled)]),
+ ENABLE_WERROR=$enableval,
+ ENABLE_WERROR=no)
+
+if test "x$ENABLE_WERROR" = xyes; then
+ AM_CFLAGS="$AM_CFLAGS -Werror -pedantic-errors"
+fi
+
+AC_ARG_ENABLE(debug,
+ AS_HELP_STRING([--enable-debug],
+ [Enable debugging (default: disabled)]),
+ ENABLE_DEBUG=$enableval,
+ ENABLE_DEBUG=no)
+
+if test "x$ENABLE_DEBUG" = xno; then
+ AM_CFLAGS="$AM_CFLAGS -DNDEBUG"
+fi
+
+
+dnl
+dnl CFLAGS
+dnl
+
+AC_SUBST(AM_CFLAGS)
+
+CHECK_CFLAG([-Wall])
+CHECK_CFLAG([-Wextra])
+CHECK_CFLAG([-Wno-deprecated-declarations])
+CHECK_CFLAG([-Wmissing-prototypes])
+CHECK_CFLAG([-Wdeclaration-after-statement])
+CHECK_CFLAG([-Wshadow])
+CHECK_CFLAG([-Wpointer-arith])
+CHECK_CFLAG([-Wstrict-prototypes])
+CHECK_CFLAG([-Wcast-qual])
+CHECK_CFLAG([-Wwrite-strings])
+
+
+dnl
+dnl Compile-time options
+dnl
+
+dnl Default host
+AC_MSG_CHECKING([for default MPD host])
+AC_ARG_WITH([default-host],
+ AC_HELP_STRING([--with-default-host=ARG],
+ [Default MPD host @<:@localhost@:>@]),
+ [DEFAULT_HOST="$withval"],
+ [DEFAULT_HOST="localhost"])
+AC_MSG_RESULT([$DEFAULT_HOST])
+AC_DEFINE_UNQUOTED([DEFAULT_HOST], ["$DEFAULT_HOST"], [Default MPD host])
+
+dnl Default port
+AC_MSG_CHECKING([for default MPD port])
+AC_ARG_WITH([default-port],
+ AC_HELP_STRING([--with-default-port=ARG],
+ [Default port @<:@6600@:>@]),
+ [DEFAULT_PORT="$withval"],
+ [DEFAULT_PORT="6600"])
+AC_MSG_RESULT([$DEFAULT_PORT])
+AC_DEFINE_UNQUOTED([DEFAULT_PORT], [$DEFAULT_PORT], [Default MPD port])
+AC_DEFINE_UNQUOTED([DEFAULT_PORT_STR], ["$DEFAULT_PORT"], [Default MPD port])
+
+
+dnl
+dnl Done
+dnl
+
+AC_OUTPUT([Makefile])
View
4 libmpdclient.ld
@@ -0,0 +1,4 @@
+libmpdclient2 {
+global:
+ *;
+};
View
15 m4/cflags.m4
@@ -0,0 +1,15 @@
+AC_DEFUN([CHECK_CFLAG], [
+ var=`echo "$1" | tr "=-" "__"`
+ AC_CACHE_CHECK([whether the C compiler accepts $1],[check_cflag_$var],[
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $1"
+ AC_COMPILE_IFELSE([int main(void) { return 0; }],
+ [eval "check_cflag_$var=yes"],
+ [eval "check_cflag_$var=no"])
+ CFLAGS="$save_CFLAGS"
+ ])
+ if eval "test x`echo '$check_cflag_'$var` = xyes"; then
+ AM_CFLAGS="$AM_CFLAGS $1"
+ fi
+ ])
+])

0 comments on commit 4496a77

Please sign in to comment.
Something went wrong with that request. Please try again.