Merge TDS cdr fixes (bug #5517, with slight mods)
[asterisk/asterisk.git] / cdr / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Makefile for CDR backends (dynamically loaded)
5 #
6 # Copyright (C) 1999-2005, Digium
7 #
8 # Mark Spencer <markster@digium.com>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 MODS=cdr_csv.so cdr_manager.so cdr_custom.so
15
16 CFLAGS+=-fPIC
17
18 ifeq ($(findstring BSD,${OSARCH}),BSD)
19   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
20 endif
21
22 #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
23 #This works for even old (2.96) versions of gcc and provides a small boost either way.
24 #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.
25 #So we go lowest common available by gcc and go a step down, still a step up from
26 #the default as we now have a better instruction set to work with. - Belgarath
27 ifeq ($(PROC),sparc64)
28  PROC=ultrasparc
29   CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
30 endif
31
32 #
33 # unixODBC stuff...
34 #
35 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),)
36   MODS+=cdr_odbc.so
37 endif
38
39 #
40 # FreeTDS stuff...
41 #
42 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/tds.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/tds.h),)
43   ifeq ($(shell grep -s TDS_VERSION_NO $(CROSS_COMPILE_TARGET)/usr/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/local/include/tdsver.h | grep -c 0.63),1)
44     CFLAGS += -DFREETDS_0_63
45   else
46         ifeq ($(shell grep -s TDS_VERSION_NO $(CROSS_COMPILE_TARGET)/usr/include/tdsver.h $(CROSS_COMPILE_TARGET)/usr/local/include/tdsver.h | grep -c 0.62),1)
47       CFLAGS += -DFREETDS_0_62
48     else
49       CFLAGS += -DFREETDS_PRE_0_62
50     endif
51   endif
52   MODS+=cdr_tds.so
53 endif
54
55 #
56 # PGSQL stuff...  Autoconf anyone??
57 #
58 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/pgsql/include)$(wildcard $(CROSS_COMPILE_TARGET)/usr/include/pgsql)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/pgsql)$(wildcard $(CROSS_COMPILE_TARGET)/opt/pgsql/include)$(wildcard $(CROSS_COMPILE_TARGET)/usr/include/libpq-fe.h),)
59   MODS+=cdr_pgsql.so
60 endif
61
62 MLFLAGS=
63
64 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
65   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
66   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/postgresql
67 endif
68
69 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/pgsql/include),)
70   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/pgsql/include
71   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/pgsql/lib
72 endif
73
74 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/pgsql),)
75   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/pgsql
76   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/pgsql
77 endif
78
79 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/pgsql),)
80   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/pgsql
81   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib/pgsql
82 endif
83
84 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/opt/pgsql/include),)
85   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/opt/pgsql/include
86   MLFLAGS+=-L$(CROSS_COMPILE_TARGET) /opt/pgsql/lib
87 endif
88
89 ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
90   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
91 endif
92
93 ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/lib/libpq.so),)
94   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib
95 endif
96
97 #
98 # SQLite stuff...
99 #
100 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sqlite.h),)
101   MODS+=cdr_sqlite.so
102 endif
103
104 all: depend $(MODS)
105
106 install: all
107         for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
108
109 clean:
110         rm -f *.so *.o .depend
111
112 %.so : %.o
113         $(CC) $(SOLINK) -o $@ $<
114
115 ifneq ($(wildcard .depend),)
116   include .depend
117 endif
118
119 cdr_odbc.so: cdr_odbc.o
120         $(CC) $(SOLINK) -o $@ $< -lodbc $(MLFLAGS)
121
122 cdr_tds.so: cdr_tds.o
123         $(CC) $(SOLINK) -o $@ $< -ltds $(MLFLAGS)
124
125 cdr_pgsql.so: cdr_pgsql.o
126         $(CC) $(SOLINK) -o $@ $< -lpq -lz $(MLFLAGS)
127
128 cdr_sqlite.so: cdr_sqlite.o
129         $(CC) $(SOLINK) -o $@ $< -lsqlite $(MLFLAGS)
130
131 depend: .depend
132
133 .depend:
134         ../build_tools/mkdep $(CFLAGS) `ls *.c`