clean up, use make functions instead of subshells, remove unused stuff
[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   MODS+=cdr_tds.so
44 endif
45
46 #
47 # PGSQL stuff...  Autoconf anyone??
48 #
49 ifneq ($(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),)
50   MODS+=cdr_pgsql.so
51 endif
52
53 MLFLAGS=
54
55 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/pgsql/include),)
56   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/pgsql/include
57   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/pgsql/lib
58 endif
59
60 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/pgsql),)
61   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/pgsql
62   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib/pgsql
63 endif
64
65 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/pgsql),)
66   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/pgsql
67   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib/pgsql
68 endif
69
70 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/opt/pgsql/include),)
71   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/opt/pgsql/include
72   MLFLAGS+=-L$(CROSS_COMPILE_TARGET) /opt/pgsql/lib
73 endif
74
75 ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/include/postgresql),)
76   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/include/postgresql
77 endif
78
79 ifneq ($(wilcard $(CROSS_COMPILE_TARGET)/usr/lib/libpq.so),)
80   MLFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/lib
81 endif
82
83 #
84 # SQLite stuff...
85 #
86 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sqlite.h),)
87   MODS+=cdr_sqlite.so
88 endif
89
90 all: depend $(MODS)
91
92 install: all
93         for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
94
95 clean:
96         rm -f *.so *.o .depend
97
98 %.so : %.o
99         $(CC) $(SOLINK) -o $@ $<
100
101 ifneq ($(wildcard .depend),)
102   include .depend
103 endif
104
105 cdr_odbc.so: cdr_odbc.o
106         $(CC) $(SOLINK) -o $@ $< -lodbc $(MLFLAGS)
107
108 cdr_tds.so: cdr_tds.o
109         $(CC) $(SOLINK) -o $@ $< -ltds $(MLFLAGS)
110
111 cdr_pgsql.so: cdr_pgsql.o
112         $(CC) $(SOLINK) -o $@ $< -lpq -lz $(MLFLAGS)
113
114 cdr_sqlite.so: cdr_sqlite.o
115         $(CC) $(SOLINK) -o $@ $< -lsqlite $(MLFLAGS)
116
117 depend: .depend
118
119 .depend:
120         ../build_tools/mkdep $(CFLAGS) `ls *.c`