8663754e6701a35f6795817f10535ed749fc177e
[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 ifeq (${OSARCH},CYGWIN)
17 CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
18 CYGSOLIB=-L.. -L. -lasterisk.dll
19 else
20 CFLAGS+=-fPIC
21 endif
22
23 ifeq ($(findstring BSD,${OSARCH}),BSD)
24   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include
25   SOLINK+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
26 endif
27
28 #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
29 #This works for even old (2.96) versions of gcc and provides a small boost either way.
30 #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.
31 #So we go lowest common available by gcc and go a step down, still a step up from
32 #the default as we now have a better instruction set to work with. - Belgarath
33 ifeq ($(PROC),sparc64)
34  PROC=ultrasparc
35   CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
36 endif
37
38 #
39 # unixODBC stuff...
40 #
41 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),)
42   MODS+=cdr_odbc.so
43 endif
44
45 #
46 # FreeTDS stuff...
47 #
48 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/tds.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/tds.h),)
49   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)
50     CFLAGS += -DFREETDS_0_63
51   else
52         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)
53       CFLAGS += -DFREETDS_0_62
54     else
55       CFLAGS += -DFREETDS_PRE_0_62
56     endif
57   endif
58   MODS+=cdr_tds.so
59 endif
60
61 #
62 # PGSQL stuff...  Autoconf anyone??
63 #
64 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),)
65   MODS+=cdr_pgsql.so
66 endif
67
68 MLFLAGS=
69
70 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
71   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
72   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/postgresql
73 endif
74
75 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/pgsql/include),)
76   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/pgsql/include
77   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/pgsql/lib
78 endif
79
80 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/pgsql),)
81   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/pgsql
82   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/pgsql
83 endif
84
85 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/pgsql),)
86   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/pgsql
87   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib/pgsql
88 endif
89
90 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/opt/pgsql/include),)
91   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/opt/pgsql/include
92   MLFLAGS+=-L$(CROSS_COMPILE_TARGET) /opt/pgsql/lib
93 endif
94
95 ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
96   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
97 endif
98
99 ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/lib/libpq.so),)
100   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib
101 endif
102
103 #
104 # SQLite stuff...
105 #
106 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sqlite.h),)
107   MODS+=cdr_sqlite.so
108 endif
109
110 all: depend $(MODS)
111
112 install: all
113         for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
114
115 uninstall:
116
117 clean:
118         rm -f *.so *.o .depend
119
120 %.so : %.o
121         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
122
123 ifneq ($(wildcard .depend),)
124   include .depend
125 endif
126
127 cdr_odbc.so: cdr_odbc.o
128         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc $(MLFLAGS)
129
130 cdr_tds.so: cdr_tds.o
131         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -ltds $(MLFLAGS)
132
133 cdr_pgsql.so: cdr_pgsql.o
134         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lpq -lz $(MLFLAGS)
135
136 cdr_sqlite.so: cdr_sqlite.o
137         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lsqlite $(MLFLAGS)
138
139 depend: .depend
140
141 .depend:
142         ../build_tools/mkdep $(CFLAGS) `ls *.c`