e11cfb9b63898a98b1a81ee3b90e34bd4e4b830c
[asterisk/asterisk.git] / cdr / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Makefile for CDR backends
5 #
6 # Copyright (C) 1999-2006, Digium, Inc.
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:=$(patsubst %.c,%.so,$(wildcard cdr_*.c))
15
16 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),)
17   MODS:=$(filter-out cdr_odbc.so,$(MODS))
18 endif
19
20 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),)
21   MODS:=$(filter-out cdr_pgsql.so,$(MODS))
22 endif
23
24 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sqlite.h),)
25   MODS:=$(filter-out cdr_sqlite.so,$(MODS))
26 endif
27
28 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),)
29   MODS:=$(filter-out cdr_tds.so,$(MODS))
30   NOTDS=1
31 endif
32
33 ifeq (${OSARCH},CYGWIN)
34   CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
35   CYGSOLIB=-L.. -L. -lasterisk.dll
36 else
37   CFLAGS+=-fPIC
38 endif
39
40 ifeq ($(findstring BSD,${OSARCH}),BSD)
41   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include
42   SOLINK+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
43 endif
44
45 #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
46 #This works for even old (2.96) versions of gcc and provides a small boost either way.
47 #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.
48 #So we go lowest common available by gcc and go a step down, still a step up from
49 #the default as we now have a better instruction set to work with. - Belgarath
50 ifeq ($(PROC),sparc64)
51   PROC=ultrasparc
52   CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
53 endif
54
55 ifeq (${NOTDS},)
56   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)
57     CFLAGS += -DFREETDS_0_63
58   else
59         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)
60       CFLAGS += -DFREETDS_0_62
61     else
62       CFLAGS += -DFREETDS_PRE_0_62
63     endif
64   endif
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 all: depend $(MODS)
103
104 install: all
105         for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
106
107 uninstall:
108
109 clean-depend:
110         rm -f .depend
111
112 clean: clean-depend
113         rm -f *.so *.o
114
115 %.so : %.o
116         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
117
118 ifneq ($(wildcard .depend),)
119   include .depend
120 endif
121
122 cdr_odbc.so: cdr_odbc.o
123         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc $(MLFLAGS)
124
125 cdr_tds.so: cdr_tds.o
126         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -ltds $(MLFLAGS)
127
128 cdr_pgsql.so: cdr_pgsql.o
129         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lpq -lz $(MLFLAGS)
130
131 cdr_sqlite.so: cdr_sqlite.o
132         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lsqlite $(MLFLAGS)
133
134 depend: .depend
135
136 .depend:
137         ../build_tools/mkdep $(CFLAGS) `ls *.c`