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