use auto-build for cdr modules
[asterisk/asterisk.git] / cdr / Makefile
old mode 100755 (executable)
new mode 100644 (file)
index a34cc54..40779a2
@@ -1,27 +1,45 @@
 #
 # Asterisk -- A telephony toolkit for Linux.
 # 
-# Makefile for CDR backends (dynamically loaded)
+# Makefile for CDR backends
 #
-# Copyright (C) 1999, Mark Spencer
+# Copyright (C) 1999-2006, Digium, Inc.
 #
-# Mark Spencer <markster@linux-support.net>
+# Mark Spencer <markster@digium.com>
 #
 # This program is free software, distributed under the terms of
 # the GNU General Public License
 #
 
-#ADD cdr_pgsql.so to MODS= to include PostgreSQL support: REQUIRES PostgreSQL libs
-MODS=cdr_csv.so cdr_manager.so cdr_custom.so
+MODS:=$(patsubst %.c,%.so,$(wildcard cdr_*.c))
 
+ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),)
+  MODS:=$(filter-out cdr_odbc.so,$(MODS))
+endif
+
+ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql $(CROSS_COMPILE_TARGET)/usr/local/pgsql/include $(CROSS_COMPILE_TARGET)/usr/include/pgsql $(CROSS_COMPILE_TARGET)/usr/local/include/pgsql $(CROSS_COMPILE_TARGET)/opt/pgsql/include $(CROSS_COMPILE_TARGET)/usr/include/libpq-fe.h),)
+  MODS:=$(filter-out cdr_pgsql.so,$(MODS))
+endif
+
+ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sqlite.h),)
+  MODS:=$(filter-out cdr_sqlite.so,$(MODS))
+endif
 
-CFLAGS+=-fPIC
+ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/tds.h $(CROSS_COMPILE_TARGET)/usr/local/include/tds.h $(CROSS_COMPILE_TARGET)/usr/include/freetds/tds.h),)
+  MODS:=$(filter-out cdr_tds.so,$(MODS))
+  NOTDS=1
+endif
 
-PROC=$(shell uname -m)
-OSARCH=$(shell uname -s)
+ifeq (${OSARCH},CYGWIN)
+  CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+  CYGSOLIB=-L.. -L. -lasterisk.dll
+else
+  CFLAGS+=-fPIC
+endif
 
-ifeq (${OSARCH},FreeBSD)
-SOLINK+=-L/usr/local/lib
+ifeq ($(findstring BSD,${OSARCH}),BSD)
+  CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include
+  SOLINK+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
 endif
 
 #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
@@ -30,72 +48,87 @@ endif
 #So we go lowest common available by gcc and go a step down, still a step up from
 #the default as we now have a better instruction set to work with. - Belgarath
 ifeq ($(PROC),sparc64)
-PROC=ultrasparc
-CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
+  PROC=ultrasparc
+  CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
 endif
 
-#
-# unixODBC stuff...
-#
-MODS+=$(shell if [ -f "/usr/include/odbcinst.h" ]; then echo "cdr_odbc.so"; fi)
-MODS+=$(shell if [ -f "/usr/local/include/odbcinst.h" ]; then echo "cdr_odbc.so"; fi) 
-
-#
-# FreeTDS stuff...
-#
-MODS+=$(shell if [ -f "/usr/include/tds.h" ]; then echo "cdr_tds.so"; fi)
-MODS+=$(shell if [ -f "/usr/local/include/tds.h" ]; then echo "cdr_tds.so"; fi)
+ifeq (${NOTDS},)
+  ifeq ($(shell grep -s TDS_VERSION_NO $(CROSS_COMPILE_TARGET)/usr/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/local/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/include/freetds/tdsver.h | grep -c 0.63),1)
+    CFLAGS += -DFREETDS_0_63
+  else
+       ifeq ($(shell grep -s TDS_VERSION_NO $(CROSS_COMPILE_TARGET)/usr/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/local/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/include/freetds/tdsver.h | grep -c 0.62),1)
+      CFLAGS += -DFREETDS_0_62
+    else
+      CFLAGS += -DFREETDS_PRE_0_62
+    endif
+  endif
+endif
 
-#
-# PGSQL stuff...  Autoconf anyone??
-#
-MODS+=$(shell if [ -d /usr/local/pgsql/include ] || [ -d /usr/include/pgsql ] || [ -d /usr/local/include/pgsql ] || [ -d /opt/pgsql/include ] || [ -f /usr/include/libpq-fe.h ] ; then echo "cdr_pgsql.so"; fi)
-CFLAGS+=$(shell if [ -d /usr/local/pgsql/include ]; then echo "-I/usr/local/pgsql/include"; fi)
-CFLAGS+=$(shell if [ -d /usr/include/pgsql ]; then echo "-I/usr/include/pgsql"; fi)
-CFLAGS+=$(shell if [ -d /usr/include/postgresql ]; then echo "-I/usr/include/postgresql"; fi)
-CFLAGS+=$(shell if [ -d /usr/local/include/pgsql ]; then echo "-I/usr/local/include/pgsql"; fi)
-CFLAGS+=$(shell if [ -d /opt/pgsql/include ]; then echo "-I/opt/pgsql/include"; fi)
-#CFLAGS+=$(shell if [ -f /usr/include/libpq-fe.h ]; then echo "-I/usr/include"; fi)
 MLFLAGS=
-MLFLAGS+=$(shell if [ -d /usr/lib/pgsql ]; then echo "-L/usr/lib/pgsql"; fi)
-MLFLAGS+=$(shell if [ -d /usr/local/pgsql/lib ]; then echo "-L/usr/local/pgsql/lib"; fi)
-MLFLAGS+=$(shell if [ -d /usr/local/lib/pgsql ]; then echo "-L/usr/local/lib/pgsql"; fi)
-MLFLAGS+=$(shell if [ -d /opt/pgsql/lib ]; then echo "-L/opt/pgsql/lib"; fi)
-MLFLAGS+=$(shell if [ -f /usr/lib/libpq.so ]; then echo "-L/usr/lib"; fi)
 
-#
-# SQLIte stuff...
-#
-MODS+=$(shell if [ -f "/usr/include/sqlite.h" ]; then echo "cdr_sqlite.so"; fi)
+ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
+  CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
+  MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/postgresql
+endif
+
+ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/pgsql/include),)
+  CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/pgsql/include
+  MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/pgsql/lib
+endif
+
+ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/pgsql),)
+  CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/pgsql
+  MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/pgsql
+endif
+
+ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/pgsql),)
+  CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/pgsql
+  MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib/pgsql
+endif
+
+ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/opt/pgsql/include),)
+  CFLAGS+=-I$(CROSS_COMPILE_TARGET)/opt/pgsql/include
+  MLFLAGS+=-L$(CROSS_COMPILE_TARGET) /opt/pgsql/lib
+endif
+
+ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
+  CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
+endif
+
+ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/lib/libpq.so),)
+  MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib
+endif
 
 all: depend $(MODS)
 
 install: all
        for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
+uninstall:
+
 clean:
        rm -f *.so *.o .depend
 
 %.so : %.o
-       $(CC) $(SOLINK) -o $@ $<
+       $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
 
 ifneq ($(wildcard .depend),)
-include .depend
+  include .depend
 endif
 
 cdr_odbc.so: cdr_odbc.o
-       $(CC) $(SOLINK) -o $@ $< -lodbc $(MLFLAGS)
+       $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc $(MLFLAGS)
 
 cdr_tds.so: cdr_tds.o
-       $(CC) $(SOLINK) -o $@ $< -ltds $(MLFLAGS)
+       $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -ltds $(MLFLAGS)
 
 cdr_pgsql.so: cdr_pgsql.o
-       $(CC) $(SOLINK) -o $@ $< -lpq -lz $(MLFLAGS)
+       $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lpq -lz $(MLFLAGS)
 
 cdr_sqlite.so: cdr_sqlite.o
-       $(CC) $(SOLINK) -o $@ $< -lsqlite $(MLFLAGS)
+       $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lsqlite $(MLFLAGS)
 
 depend: .depend
 
 .depend:
-       ../mkdep $(CFLAGS) `ls *.c`
+       ../build_tools/mkdep $(CFLAGS) `ls *.c`