Use loops for str* checks and to install configuration and tone files,
[lcr.git] / Makefile.am
index 66a0c82..d65dc05 100644 (file)
@@ -3,7 +3,7 @@
 ##    This file is part of linux-call-router
 ##    Copyright (C) 2007 Joerg Habenicht (j.habenicht@gmx.de)
 ##    Copyright (C) 2008 Peter Schlaile (peter -at- schlaile.de)
-##    Copyright (C) 2008 Andreas Eversberg (andreas@eversberg.eu)
+##    Copyright (C) 2008-2012 Andreas Eversberg (andreas@eversberg.eu)
 
 ##    This program is free software; you can redistribute it and/or
 ##    modify it under the terms of the GNU General Public License as
@@ -43,6 +43,14 @@ INSTALLATION_DEFINES = \
  -DLOG_DIR="\"$(LOGdir)\"" \
  -DEXTENSION_DATA="\"$(EXTENSIONdir)\""
 
+if ENABLE_MISDN
+
+MISDN_INCLUDE = -DWITH_MISDN -DWITH_CRYPT
+MISDN_SOURCE = mISDN.cpp dss1.cpp loop.c crypt.cpp remote.cpp joinremote.cpp
+MISDN_LIB = -lmisdn
+
+endif
+
 GSM_INCLUDE =
 GSM_SOURCE =
 GSM_LIB =
@@ -51,7 +59,7 @@ if ENABLE_GSM
 
 GSM_INCLUDE +=
 
-GSM_SOURCE += gsm_audio.c gsm.cpp gsm_conf.c
+GSM_SOURCE += gsm_audio.c gsm.cpp
   
 GSM_LIB += /usr/lib/libgsm.a
 
@@ -62,21 +70,17 @@ endif
 
 if ENABLE_GSM_BS
 
-GSM_INCLUDE += -DWITH_GSM_BS -I./openbsc/include -I./libosmocore/include -I./openbsc
+GSM_INCLUDE += -DWITH_GSM_BS
 
-GSM_SOURCE += gsm_bs.cpp openbsc/src/bsc_init.c openbsc/src/bsc_vty.c openbsc/src/vty_interface_layer3.c openbsc/src/bsc_api.c openbsc/src/bsc_version.c
-
-GSM_LIB +=  ./openbsc/src/libbsc.a ./openbsc/src/libmsc.a ./openbsc/src/libvty.a -losmovty -losmocore -ldbi -lcrypt
+GSM_SOURCE += gsm_bs.cpp
 
 endif
 
 if ENABLE_GSM_MS
 
-GSM_INCLUDE += -DPACKAGE_VERSION=0 -DWITH_GSM_MS -I./layer23/include -I./libosmocore/include
-
-GSM_SOURCE += gsm_ms.cpp layer23/src/app_mobile.c
+GSM_INCLUDE += -DWITH_GSM_MS
 
-GSM_LIB += ./layer23/src/liblayer23.a ./libosmocore/build-host/src/.libs/libosmocore.a ./libosmocore/build-host/src/vty/.libs/libosmovty.a
+GSM_SOURCE += gsm_ms.cpp
 
 endif
 
@@ -88,6 +92,22 @@ SS5_SOURCE = ss5.cpp ss5_encode.c ss5_decode.c
 
 endif
 
+SIP_LIB =
+
+if ENABLE_SIP
+
+# FIXME: remove that
+#pkgconfigdir = $(libdir)/pkgconfig
+#pkgconfig_DATA = sofia-sip-ua.pc
+
+SIP_INCLUDE = -DWITH_SIP $(SOFIA_CFLAGS)
+
+SIP_SOURCE = sip.cpp
+
+SIP_LIB += $(SOFIA_LIBS)
+
+endif
+
 bin_PROGRAMS = lcradmin gentones genwave
 
 sbin_PROGRAMS = lcr genrc genextension
@@ -99,19 +119,19 @@ chan_lcr_so_LDFLAGS = -shared
 chan_lcr_so_LDADD = chan_lcr.po bchannel.po options.po callerid.po select.po
 
 chan_lcr.po: chan_lcr.c chan_lcr.h
-       $(CC) $(INCLUDES) $(AST_CFLAGS) -D_GNU_SOURCE -fPIC -c chan_lcr.c -o chan_lcr.po
+       $(CC) $(INCLUDES) $(AST_CFLAGS) $(CPPFLAGS) $(CFLAGS) -D_GNU_SOURCE -fPIC -c chan_lcr.c -o chan_lcr.po
 
 bchannel.po: bchannel.c bchannel.h
-       $(CC) $(INCLUDES) -D_GNU_SOURCE -fPIC -c bchannel.c -o bchannel.po
+       $(CC) $(INCLUDES) -D_GNU_SOURCE $(CPPFLAGS) $(CFLAGS) -fPIC -c bchannel.c -o bchannel.po
 
 callerid.po: callerid.c callerid.h
-       $(CC) $(INCLUDES) -D_GNU_SOURCE -fPIC -c callerid.c -o callerid.po
+       $(CC) $(INCLUDES) -D_GNU_SOURCE $(CPPFLAGS) $(CFLAGS) -fPIC -c callerid.c -o callerid.po
 
 options.po: options.c options.h
-       $(CC) $(INCLUDES) -D_GNU_SOURCE -fPIC -c options.c -o options.po
+       $(CC) $(INCLUDES) -D_GNU_SOURCE $(CPPFLAGS) $(CFLAGS) -fPIC -c options.c -o options.po
 
 select.po: select.c select.h
-       $(CC) $(INCLUDES) -D_GNU_SOURCE -fPIC -c select.c -o select.po
+       $(CC) $(INCLUDES) -D_GNU_SOURCE $(CPPFLAGS) $(CFLAGS) -fPIC -c select.c -o select.po
 
 install-exec-hook:
        mkdir -p $(astmoddir)
@@ -119,18 +139,17 @@ install-exec-hook:
        $(INSTALL) chan_lcr.so $(astmoddir)
 endif
 
-INCLUDES = $(all_includes) $(GSM_INCLUDE) $(SS5_INCLUDE) -Wall $(INSTALLATION_DEFINES)
+INCLUDES = $(all_includes) $(MISDN_INCLUDE) $(GSM_INCLUDE) $(SS5_INCLUDE) $(SIP_INCLUDE) -Wall $(INSTALLATION_DEFINES)
 
-lcr_SOURCES = $(GSM_SOURCE) $(SS5_SOURCE) select.c action.cpp       mISDN.cpp        tones.c \
-       action_efi.cpp   crypt.cpp        mail.c           trace.c \
-       action_vbox.cpp  dss1.cpp         main.c           \
-       vbox.cpp alawulaw.c       endpoint.cpp     interface.c     message.c \
-       apppbx.cpp       endpointapp.cpp  join.cpp        options.c       \
-       extension.c      joinpbx.cpp     port.cpp \
-       callerid.c       joinremote.cpp  route.c \
-       cause.c          socket_server.c
+lcr_SOURCES = \
+       main.c select.c trace.c options.c tones.c alawulaw.c cause.c interface.c message.c callerid.c socket_server.c \
+       port.cpp vbox.cpp \
+       $(MISDN_SOURCE) $(GSM_SOURCE) $(SS5_SOURCE) $(SIP_SOURCE) \
+       endpoint.cpp endpointapp.cpp \
+       appbridge.cpp apppbx.cpp route.c action.cpp action_efi.cpp action_vbox.cpp extension.c mail.c \
+       join.cpp joinpbx.cpp
 
-lcr_LDADD = $(LIBCRYPTO) -lmisdn -lpthread $(GSM_LIB)
+lcr_LDADD = $(LIBCRYPTO) $(MISDN_LIB) -lpthread $(GSM_LIB) $(SIP_LIB)
 
 
 lcradmin_SOURCES = lcradmin.c cause.c options.c
@@ -138,57 +157,37 @@ genextension_SOURCES = genext.c options.c extension.c
 
 # Special install function to preserve existing configs.
 # Optimization with equivalen results are welcome
+CONFIGFILES = options.conf interface.conf routing.conf directory.list
+TONEDIRS = tones_american tones_efi tones_german vbox_english vbox_german
 
 install-data-hook:
-       @sh -c 'grep -n strcpy *.c* --exclude chan_lcr.c --exclude bchannel.c --exclude callerid.c ; if test $$''? = 0 ; then echo "dont use strcpy, use makro instead." ; exit -1 ; fi'
-       @sh -c 'grep -n strncpy *.c* --exclude chan_lcr.c --exclude bchannel.c --exclude callerid.c ; if test $$''? = 0 ; then echo "dont use strncpy, use makro instead." ; exit -1 ; fi'
-       @sh -c 'grep -n strcat *.c* --exclude chan_lcr.c --exclude bchannel.c --exclude callerid.c ; if test $$''? = 0 ; then echo "dont use strcat, use makro instead." ; exit -1 ; fi'
-       @sh -c 'grep -n strncat *.c* --exclude chan_lcr.c --exclude bchannel.c --exclude callerid.c ; if test $$''? = 0 ; then echo "dont use strncat, use makro instead." ; exit -1 ; fi'
-       @sh -c 'grep -n sprintf *.c* --exclude chan_lcr.c --exclude bchannel.c --exclude callerid.c ; if test $$''? = 0 ; then echo "dont use sprintf, use makro instead." ; exit -1 ; fi'
-       @sh -c 'grep -n snprintf *.c* --exclude chan_lcr.c --exclude bchannel.c --exclude callerid.c ; if test $$''? = 0 ; then echo "dont use snprintf, use makro instead." ; exit -1 ; fi'
+       @fns='strcpy strncpy strcat strncat sprintf snprintf' ; \
+       files=$$( find . -type f -name "*.c*" \
+         | $(GREP) -v -e chan_lcr.c -e bchannel.c -e callerid.c ) ; \
+       test -z "$$files" || { for fn in $$fns ; do \
+         $(GREP) -n $$fn $$files ; if test $$? = 0 ; then \
+           ( echo "dont use $$fn, use makro instead." ; exit -1 ) ; \
+         fi ; \
+       done ; }
        mkdir -p $(CONFIGdir)
        mkdir -p $(SHAREdir)
        mkdir -p $(LOGdir)
        mkdir -p $(EXTENSIONdir)
-       @if test -a $(CONFIGdir)/options.conf ; then \
-               echo "NOTE: options.conf already exists, not changed." ; else \
-               cp -v default/options.conf $(CONFIGdir) ; fi
-       @if test -a $(CONFIGdir)/interface.conf ; then \
-               echo "NOTE: interface.conf already exists, not changed." ; else \
-               cp -v default/interface.conf $(CONFIGdir) ; fi
-       @if test -a $(CONFIGdir)/routing.conf ; then \
-               echo "NOTE: routing.conf already exists, not changed." ; else \
-               cp -v default/routing.conf $(CONFIGdir) ; fi
-if ENABLE_GSM
-       @if test -a $(CONFIGdir)/gsm.conf ; then \
-               echo "NOTE: gsm.conf already exists, not changed." ; else \
-               cp -v default/gsm.conf $(CONFIGdir) ; fi
-       @if test -a $(CONFIGdir)/openbsc.cfg ; then \
-               echo "NOTE: openbsc.cfg already exists, not changed." ; else \
-               cp -v default/openbsc.cfg $(CONFIGdir) ; fi
-endif
-       @if test -a $(CONFIGdir)/numbering_int.conf ; then \
+       @fs='$(CONFIGFILES)' ; for f in $$fs ; do \
+         if test -a "$(CONFIGdir)/$$f" ; then \
+           echo "NOTE: $$f already exists, not changed." ; \
+         else $(INSTALL) -m 644 default/$$f "$(CONFIGdir)/" ; fi ; \
+       done
+       @if test -a "$(CONFIGdir)/numbering_int.conf" ; then \
                echo "NOTE: numbering_int.conf is obsolete, please use routing." ; fi
-       @if test -a $(CONFIGdir)/numbering_ext.conf ; then \
+       @if test -a "$(CONFIGdir)/numbering_ext.conf" ; then \
                echo "NOTE: numbering_ext.conf is obsolete, please use routing." ; fi
-       @if test -a $(CONFIGdir)/directory.list ; then \
-               echo "NOTE: directory.list already exists, not changed." ; else \
-               cp -v default/directory.list $(CONFIGdir) ; fi
-       @if test -a $(SHAREdir)/tones_american ; then \
-               echo "NOTE: american tones already exists, not overwritten." ; else \
-               cp -a tones_american $(SHAREdir) ; fi
-       @if test -a $(SHAREdir)/tones_german ; then \
-               echo "NOTE: german tones already exists, not overwritten." ; else \
-               cp -a tones_german $(SHAREdir) ; fi
-       @if test -a $(SHAREdir)/vbox_german ; then \
-               echo "NOTE: german vbox tones already exists, not overwritten." ; else \
-               cp -a vbox_german $(SHAREdir) ; fi
-       @if test -a $(SHAREdir)/vbox_english ; then \
-               echo "NOTE: english vbox tones already exists, not overwritten." ; else \
-               cp -a vbox_english $(SHAREdir) ; fi
-       @if test -a $(SHAREdir)/tones_efi ; then \
-               echo "NOTE: special efi tones already exists, not overwritten." ; else \
-               cp -a tones_efi $(SHAREdir) ; fi
+       @ds='$(TONEDIRS)' ; for d in $$ds ; do \
+         destdir="$(SHAREdir)/$$d" ; \
+         if test -a "$$destdir" ; then \
+           echo "NOTE: $$d already exists, not overwritten." ; \
+         else mkdir -p "$$destdir" ; cp -a $$d/* "$$destdir/" ; fi ; \
+       done
 
 clean-generic:
        rm -f *.po