remove duplicate CFLAGS and SOLINK definitions that are
[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 #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
41 #This works for even old (2.96) versions of gcc and provides a small boost either way.
42 #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.
43 #So we go lowest common available by gcc and go a step down, still a step up from
44 #the default as we now have a better instruction set to work with. - Belgarath
45 ifeq ($(PROC),sparc64)
46   PROC=ultrasparc
47   CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
48 endif
49
50 ifeq (${NOTDS},)
51   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)
52     CFLAGS += -DFREETDS_0_63
53   else
54         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)
55       CFLAGS += -DFREETDS_0_62
56     else
57       CFLAGS += -DFREETDS_PRE_0_62
58     endif
59   endif
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 all: depend $(MODS)
98
99 install: all
100         for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
101
102 uninstall:
103
104 clean-depend:
105         rm -f .depend
106
107 clean: clean-depend
108         rm -f *.so *.o
109
110 %.so : %.o
111         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
112
113 ifneq ($(wildcard .depend),)
114   include .depend
115 endif
116
117 cdr_odbc.so: cdr_odbc.o
118         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc $(MLFLAGS)
119
120 cdr_tds.so: cdr_tds.o
121         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -ltds $(MLFLAGS)
122
123 cdr_pgsql.so: cdr_pgsql.o
124         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lpq -lz $(MLFLAGS)
125
126 cdr_sqlite.so: cdr_sqlite.o
127         $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lsqlite $(MLFLAGS)
128
129 depend: .depend
130
131 .depend:
132         ../build_tools/mkdep $(CFLAGS) `ls *.c`