From 711de8df9b78a46d4e12b810c26d26e9ead294e6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 17 Aug 2004 17:56:09 +0000 Subject: autoconf beefup build fixes git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@134 fefdeb5f-60dc-0310-8127-8f9354f1896f --- acinclude.m4 | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 27 +++++++ polyp/Makefile.am | 31 +++++--- polyp/cli-text.c | 10 +-- polyp/sample-util.c | 10 +-- polyp/sink-input.c | 2 +- polyp/sink.c | 2 +- polyp/source.c | 2 +- polyp/util.c | 4 ++ 9 files changed, 264 insertions(+), 23 deletions(-) create mode 100644 acinclude.m4 diff --git a/acinclude.m4 b/acinclude.m4 new file mode 100644 index 00000000..bedf51c3 --- /dev/null +++ b/acinclude.m4 @@ -0,0 +1,199 @@ +dnl Available from the GNU Autoconf Macro Archive at: +dnl http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.html +dnl +AC_DEFUN([ACX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_SAVE +AC_LANG_C +acx_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on True64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) + AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) + AC_MSG_RESULT($acx_pthread_ok) + if test x"$acx_pthread_ok" = xno; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) +# -pthreads: Solaris/gcc +# -mthreads: Mingw32/gcc, Lynx/gcc +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads too; +# also defines -D_REENTRANT) +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case "${host_cpu}-${host_os}" in + *solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (We need to link with -pthread or + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather + # a function called by this macro, so we could check for that, but + # who knows whether they'll stub that too in a future libc.) So, + # we'll just look for -pthreads and -lpthread first: + + acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags" + ;; +esac + +if test x"$acx_pthread_ok" = xno; then +for flag in $acx_pthread_flags; do + + case $flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $flag]) + PTHREAD_CFLAGS="$flag" + ;; + + pthread-config) + AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) + if test x"$acx_pthread_config" = xno; then continue; fi + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$flag]) + PTHREAD_LIBS="-l$flag" + ;; + esac + + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [acx_pthread_ok=yes]) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + AC_MSG_RESULT($acx_pthread_ok) + if test "x$acx_pthread_ok" = xyes; then + break; + fi + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$acx_pthread_ok" = xyes; then + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Detect AIX lossage: threads are created detached by default + # and the JOINABLE attribute has a nonstandard name (UNDETACHED). + AC_MSG_CHECKING([for joinable pthread attribute]) + AC_TRY_LINK([#include ], + [int attr=PTHREAD_CREATE_JOINABLE;], + ok=PTHREAD_CREATE_JOINABLE, ok=unknown) + if test x"$ok" = xunknown; then + AC_TRY_LINK([#include ], + [int attr=PTHREAD_CREATE_UNDETACHED;], + ok=PTHREAD_CREATE_UNDETACHED, ok=unknown) + fi + if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then + AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok, + [Define to the necessary symbol if this constant + uses a non-standard name on your system.]) + fi + AC_MSG_RESULT(${ok}) + if test x"$ok" = xunknown; then + AC_MSG_WARN([we do not know how to create joinable pthreads]) + fi + + AC_MSG_CHECKING([if more special flags are required for pthreads]) + flag=no + case "${host_cpu}-${host_os}" in + *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + esac + AC_MSG_RESULT(${flag}) + if test "x$flag" != xno; then + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" + fi + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + # More AIX lossage: must compile with cc_r + AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) +else + PTHREAD_CC="$CC" +fi + +AC_SUBST(PTHREAD_LIBS) +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_CC) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$acx_pthread_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) + : +else + acx_pthread_ok=no + $2 +fi +AC_LANG_RESTORE +])dnl ACX_PTHREAD diff --git a/configure.ac b/configure.ac index e6194d9f..4e4bf3aa 100644 --- a/configure.ac +++ b/configure.ac @@ -40,6 +40,33 @@ AC_SUBST(LIBLTDL) AC_LIBTOOL_DLOPEN AC_PROG_LIBTOOL +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h]) + +ACX_PTHREAD +AC_PATH_XTRA +AM_CONDITIONAL(X_DISPLAY_MISSING, test "x$X_DISPLAY_MISSING" != "x") + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_PID_T +AC_TYPE_SIZE_T +AC_HEADER_TIME + +# Checks for library functions. +AC_FUNC_FORK +AC_PROG_GCC_TRADITIONAL +AC_FUNC_LSTAT +AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK +AC_FUNC_MALLOC +AC_FUNC_MEMCMP +AC_FUNC_MMAP +AC_FUNC_REALLOC +AC_FUNC_SETPGRP +AC_TYPE_SIGNAL +AC_CHECK_FUNCS([gethostname gettimeofday memchr memmove memset mkdir mkfifo munmap rmdir socket strcspn strerror strrchr strspn strstr strtol strtoul]) + AC_C_BIGENDIAN PKG_CHECK_MODULES(LIBSAMPLERATE, [ samplerate >= 0.1.0 ]) diff --git a/polyp/Makefile.am b/polyp/Makefile.am index 791abf0e..1f982515 100644 --- a/polyp/Makefile.am +++ b/polyp/Makefile.am @@ -17,9 +17,9 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. -AM_CFLAGS=-ansi -D_GNU_SOURCE -DDLSEARCHDIR=\"$(pkglibdir)\" -I$(srcdir)/.. -AM_LDADD=-L. -lpthread -AM_LIBADD=-L. -lpthread +AM_CFLAGS=-ansi -D_GNU_SOURCE -DDLSEARCHDIR=\"$(pkglibdir)\" -I$(srcdir)/.. $(PTHREAD_CFLAGS) +AM_LDADD=$(PTHREAD_LIBS) +AM_LIBADD=$(PTHREAD_LIBS) polypincludedir=$(includedir)/polyp @@ -75,8 +75,11 @@ pkglib_LTLIBRARIES=libiochannel.la \ module-esound-protocol-tcp.la \ module-esound-protocol-unix.la \ module-native-protocol-tcp.la \ - module-native-protocol-unix.la \ - module-x11-bell.la + module-native-protocol-unix.la + +if !X_DISPLAY_MISSING +pkglib_LTLIBRARIES+=module-x11-bell.la +endif lib_LTLIBRARIES=libpolyp.la \ libpolyp-error.la \ @@ -265,9 +268,12 @@ module_cli_la_SOURCES = module-cli.c module_cli_la_LDFLAGS = -module -avoid-version module_cli_la_LIBADD = $(AM_LIBADD) libcli.la libiochannel.la +if !X_DISPLAY_MISSING module_x11_bell_la_SOURCES = module-x11-bell.c +module_x11_bell_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) module_x11_bell_la_LDFLAGS = -module -avoid-version -module_x11_bell_la_LIBADD = $(AM_LIBADD) -lX11 -L/usr/X11R6/lib +module_x11_bell_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIB) +endif libpolyp_la_SOURCES = polyplib.h \ polyplib-def.h \ @@ -299,20 +305,29 @@ libpolyp_la_SOURCES = polyplib.h \ cdecl.h \ llist.h libpolyp_la_CFLAGS = $(AM_CFLAGS) +libpolyp_la_LDFLAGS = -version-info 0:0:0 libpolyp_mainloop_la_SOURCES = mainloop-api.h mainloop-api.c \ mainloop.c mainloop.h \ mainloop-signal.c mainloop-signal.h libpolyp_mainloop_la_CFLAGS = $(AM_CFLAGS) libpolyp_mainloop_la_LIBADD = $(AM_LIBADD) libpolyp.la +libpolyp_mainloop_la_LDFLAGS = -version-info 0:0:0 libpolyp_error_la_SOURCES = polyplib-error.c polyplib-error.h libpolyp_error_la_CFLAGS = $(AM_CFLAGS) libpolyp_error_la_LIBADD = $(AM_LIBADD) libpolyp.la +libpolyp_error_la_LDFLAGS = -version-info 0:0:0 libpolyp_simple_la_SOURCES = polyplib-simple.c polyplib-simple.h libpolyp_simple_la_CFLAGS = $(AM_CFLAGS) libpolyp_simple_la_LIBADD = $(AM_LIBADD) libpolyp.la libpolyp-mainloop.la +libpolyp_simple_la_LDFLAGS = -version-info 0:0:0 + +libpolyp_mainloop_glib_la_SOURCES = glib-mainloop.h glib-mainloop.c +libpolyp_mainloop_glib_la_CFLAGS = $(AM_CFLAGS) $(GLIB20_CFLAGS) +libpolyp_mainloop_glib_la_LIBADD = $(AM_LIBADD) libpolyp-mainloop.la $(GLIB20_LIBS) +libpolyp_mainloop_glib_la_LDFLAGS = -version-info 0:0:0 pacat_SOURCES = pacat.c pacat_LDADD = $(AM_LDADD) libpolyp.la libpolyp-error.la libpolyp-mainloop.la @@ -330,10 +345,6 @@ parec_simple_SOURCES = parec-simple.c parec_simple_LDADD = $(AM_LDADD) libpolyp.la libpolyp-simple.la libpolyp-error.la parec_simple_CFLAGS = $(AM_CFLAGS) -libpolyp_mainloop_glib_la_SOURCES = glib-mainloop.h glib-mainloop.c -libpolyp_mainloop_glib_la_CFLAGS = $(AM_CFLAGS) $(GLIB20_CFLAGS) -libpolyp_mainloop_glib_la_LIBADD = $(AM_LIBADD) libpolyp-mainloop.la $(GLIB20_LIBS) - mainloop_test_SOURCES = mainloop-test.c mainloop_test_CFLAGS = $(AM_CFLAGS) mainloop_test_LDADD = $(AM_LDADD) libpolyp-mainloop.la libpolyp.la diff --git a/polyp/cli-text.c b/polyp/cli-text.c index 558b53ca..000d6d34 100644 --- a/polyp/cli-text.c +++ b/polyp/cli-text.c @@ -89,7 +89,7 @@ char *pa_sink_list_to_string(struct pa_core *c) { for (sink = pa_idxset_first(c->sinks, &index); sink; sink = pa_idxset_next(c->sinks, &index)) { char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH]; - pa_sample_snprint(ss, sizeof(ss), &sink->sample_spec); + pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec); assert(sink->monitor_source); pa_strbuf_printf( s, @@ -123,7 +123,7 @@ char *pa_source_list_to_string(struct pa_core *c) { for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) { char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH]; - pa_sample_snprint(ss, sizeof(ss), &source->sample_spec); + pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec); pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>\n", c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ', source->index, @@ -155,7 +155,7 @@ char *pa_source_output_list_to_string(struct pa_core *c) { for (o = pa_idxset_first(c->source_outputs, &index); o; o = pa_idxset_next(c->source_outputs, &index)) { char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH]; - pa_sample_snprint(ss, sizeof(ss), &o->sample_spec); + pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec); assert(o->source); pa_strbuf_printf( s, " index: %u\n\tname: <%s>\n\tsource: <%u>\n\tsample_spec: <%s>\n", @@ -185,7 +185,7 @@ char *pa_sink_input_list_to_string(struct pa_core *c) { for (i = pa_idxset_first(c->sink_inputs, &index); i; i = pa_idxset_next(c->sink_inputs, &index)) { char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH]; - pa_sample_snprint(ss, sizeof(ss), &i->sample_spec); + pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec); assert(i->sink); pa_strbuf_printf( s, " index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tsample_spec: <%s>\n", @@ -221,7 +221,7 @@ char *pa_scache_list_to_string(struct pa_core *c) { while ((e = pa_hashmap_iterate(c->scache_hashmap, &state))) { double l; char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH]; - pa_sample_snprint(ss, sizeof(ss), &e->sample_spec); + pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec); l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec); diff --git a/polyp/sample-util.c b/polyp/sample-util.c index 8f5558a4..6a09478f 100644 --- a/polyp/sample-util.c +++ b/polyp/sample-util.c @@ -64,7 +64,7 @@ void pa_silence_memory(void *p, size_t length, const struct pa_sample_spec *spec memset(p, c, length); } -size_t pa_mix(struct pa_mix_info channels[], unsigned nchannels, void *data, size_t length, const struct pa_sample_spec *spec, uint32_t volume) { +size_t pa_mix(struct pa_mix_info channels[], unsigned nchannels, void *data, size_t length, const struct pa_sample_spec *spec, pa_volume_t volume) { unsigned c, d; assert(channels && data && length && spec); assert(spec->format == PA_SAMPLE_S16NE); @@ -82,7 +82,7 @@ size_t pa_mix(struct pa_mix_info channels[], unsigned nchannels, void *data, siz if (d >= channels[c].chunk.length) return d; - if (volume == PA_VOLUME_MUTE) + if (volume == PA_VOLUME_MUTED) v = 0; else { v = *((int16_t*) (channels[c].chunk.memblock->data + channels[c].chunk.index + d)); @@ -94,7 +94,7 @@ size_t pa_mix(struct pa_mix_info channels[], unsigned nchannels, void *data, siz sum += v; } - if (volume == PA_VOLUME_MUTE) + if (volume == PA_VOLUME_MUTED) sum = 0; else if (volume != PA_VOLUME_NORM) sum = (int32_t) ((float) sum*volume/PA_VOLUME_NORM); @@ -108,7 +108,7 @@ size_t pa_mix(struct pa_mix_info channels[], unsigned nchannels, void *data, siz } -void pa_volume_memchunk(struct pa_memchunk*c, const struct pa_sample_spec *spec, uint32_t volume) { +void pa_volume_memchunk(struct pa_memchunk*c, const struct pa_sample_spec *spec, pa_volume_t volume) { int16_t *d; size_t n; assert(c && spec && (c->length % pa_frame_size(spec) == 0)); @@ -117,7 +117,7 @@ void pa_volume_memchunk(struct pa_memchunk*c, const struct pa_sample_spec *spec, if (volume == PA_VOLUME_NORM) return; - if (volume == PA_VOLUME_MUTE) { + if (volume == PA_VOLUME_MUTED) { pa_silence_memchunk(c, spec); return; } diff --git a/polyp/sink-input.c b/polyp/sink-input.c index 7629bfb9..efa8c551 100644 --- a/polyp/sink-input.c +++ b/polyp/sink-input.c @@ -71,7 +71,7 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con r = pa_idxset_put(s->inputs, i, NULL); assert(r == 0); - pa_sample_snprint(st, sizeof(st), spec); + pa_sample_spec_snprint(st, sizeof(st), spec); fprintf(stderr, "sink-input: created %u \"%s\" on %u with sample spec \"%s\"\n", i->index, i->name, s->index, st); pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW, i->index); diff --git a/polyp/sink.c b/polyp/sink.c index eb3133ac..becaef9e 100644 --- a/polyp/sink.c +++ b/polyp/sink.c @@ -76,7 +76,7 @@ struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, co r = pa_idxset_put(core->sinks, s, &s->index); assert(s->index != PA_IDXSET_INVALID && r >= 0); - pa_sample_snprint(st, sizeof(st), spec); + pa_sample_spec_snprint(st, sizeof(st), spec); fprintf(stderr, "sink: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st); pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_NEW, s->index); diff --git a/polyp/source.c b/polyp/source.c index 2c611651..6ab439d6 100644 --- a/polyp/source.c +++ b/polyp/source.c @@ -62,7 +62,7 @@ struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail r = pa_idxset_put(core->sources, s, &s->index); assert(s->index != PA_IDXSET_INVALID && r >= 0); - pa_sample_snprint(st, sizeof(st), spec); + pa_sample_spec_snprint(st, sizeof(st), spec); fprintf(stderr, "source: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st); pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index); diff --git a/polyp/util.c b/polyp/util.c index 70766a06..2878c546 100644 --- a/polyp/util.c +++ b/polyp/util.c @@ -114,12 +114,16 @@ void pa_check_for_sigpipe(void) { struct sigaction sa; sigset_t set; +#ifdef HAVE_PTHREAD if (pthread_sigmask(SIG_SETMASK, NULL, &set) < 0) { +#endif if (sigprocmask(SIG_SETMASK, NULL, &set) < 0) { fprintf(stderr, __FILE__": sigprocmask() failed: %s\n", strerror(errno)); return; } +#ifdef HAVE_PTHREAD } +#endif if (sigismember(&set, SIGPIPE)) return; -- cgit