1#
2# libpri: An implementation of Primary Rate ISDN
3#
4# Written by Mark Spencer <markster@linux-support.net>
5#
6# Copyright (C) 2001, Linux Support Services, Inc.
7# All Rights Reserved.
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22#
23#
24# Uncomment if you want libpri not send PROGRESS_INDICATOR w/ALERTING
25#ALERTING=-DALERTING_NO_PROGRESS
26
27CC?=gcc
28GREP=grep
29AWK=awk
30
31OSARCH=$(shell uname -s)
32PROC?=$(shell uname -m)
33
34# SONAME version; should be changed on every ABI change
35# please don't change it needlessly; it's perfectly fine to have a SONAME
36# of 1.2 and a version of 1.4.x
37SONAME:=1
38
39STATIC_LIBRARY=libpri.a
40DYNAMIC_LIBRARY:=libpri.so.$(SONAME)
41STATIC_OBJS= \
42	copy_string.o \
43	pri.o \
44	q921.o \
45	prisched.o \
46	q931.o \
47	pri_aoc.o \
48	pri_cc.o \
49	pri_facility.o \
50	asn1_primitive.o \
51	rose.o \
52	rose_address.o \
53	rose_etsi_aoc.o \
54	rose_etsi_cc.o \
55	rose_etsi_diversion.o \
56	rose_etsi_ect.o \
57	rose_etsi_mwi.o \
58	rose_other.o \
59	rose_q931.o \
60	rose_qsig_aoc.o \
61	rose_qsig_cc.o \
62	rose_qsig_ct.o \
63	rose_qsig_diversion.o \
64	rose_qsig_mwi.o \
65	rose_qsig_name.o \
66	version.o
67DYNAMIC_OBJS= \
68	$(STATIC_OBJS)
69CFLAGS ?= -g
70CFLAGS += $(CPPFLAGS)
71CFLAGS += -Wall -Wstrict-prototypes -Wmissing-prototypes
72CFLAGS += -fPIC $(ALERTING) $(LIBPRI_OPT) $(COVERAGE_CFLAGS)
73INSTALL_PREFIX=$(PREFIX)
74INSTALL_BASE=
75libdir?=$(INSTALL_BASE)/lib
76ifneq ($(findstring Darwin,$(OSARCH)),)
77  SOFLAGS=$(LDFLAGS) -dynamic -bundle -Xlinker -macosx_version_min -Xlinker 10.4 -Xlinker -undefined -Xlinker dynamic_lookup -force_flat_namespace
78  ifeq ($(shell /usr/bin/sw_vers -productVersion | cut -c1-4),10.6)
79    SOFLAGS+=/usr/lib/bundle1.o
80  endif
81  LDCONFIG=/usr/bin/true
82else
83  SOFLAGS=$(LDFLAGS) -shared -Wl,-h$(DYNAMIC_LIBRARY) $(COVERAGE_LDFLAGS)
84  LDCONFIG = /sbin/ldconfig
85endif
86ifneq (,$(findstring X$(OSARCH)X, XLinuxX XGNU/kFreeBSDX XGNUX))
87LDCONFIG_FLAGS=-n
88else
89ifeq (${OSARCH},FreeBSD)
90LDCONFIG_FLAGS=-m
91CFLAGS += -I../zaptel -I../zapata
92INSTALL_BASE=
93endif
94endif
95ifeq (${OSARCH},SunOS)
96CFLAGS += -DSOLARIS -I../zaptel-solaris
97LDCONFIG =
98LDCONFIG_FLAGS = \# # Trick to comment out the period in the command below
99#INSTALL_PREFIX = /opt/asterisk  # Uncomment out to install in standard Solaris location for 3rd party code
100endif
101
102UTILITIES= pridump pritest rosetest testprilib
103
104export PRIVERSION
105
106PRIVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) build_tools/make_version .)
107
108#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
109#This works for even old (2.96) versions of gcc and provides a small boost either way.
110#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesnt support it.
111ifeq ($(PROC),sparc64)
112PROC=ultrasparc
113LIBPRI_OPT = -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
114else
115  ifneq ($(CODE_COVERAGE),)
116    LIBPRI_OPT=
117    COVERAGE_CFLAGS=-ftest-coverage -fprofile-arcs
118    COVERAGE_LDFLAGS=-ftest-coverage -fprofile-arcs
119  else
120    LIBPRI_OPT=-O2
121  endif
122endif
123
124ifeq ($(CPUARCH),i686)
125CFLAGS += -m32
126SOFLAGS += -m32
127endif
128
129all: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
130
131update:
132	@if [ -d .svn ]; then \
133		echo "Updating from Subversion..." ; \
134		fromrev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
135		svn update | tee update.out; \
136		torev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
137		echo "`date`  Updated from revision $${fromrev} to $${torev}." >> update.log; \
138		rm -f .version; \
139		if [ `grep -c ^C update.out` -gt 0 ]; then \
140			echo ; echo "The following files have conflicts:" ; \
141			grep ^C update.out | cut -b4- ; \
142		fi ; \
143		rm -f update.out; \
144	else \
145		echo "Not under version control";  \
146	fi
147
148install: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
149	mkdir -p $(INSTALL_PREFIX)$(libdir)
150	mkdir -p $(INSTALL_PREFIX)$(INSTALL_BASE)/include
151ifneq (${OSARCH},SunOS)
152	$(BSD_INSTALL_DATA) libpri.h $(INSTALL_PREFIX)$(INSTALL_BASE)/include
153	$(BSD_INSTALL_PROGRAM) $(DYNAMIC_LIBRARY) $(INSTALL_PREFIX)$(libdir)
154	#if [ -x /usr/sbin/sestatus ] && ( /usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled"); then /sbin/restorecon -v $(INSTALL_PREFIX)$(libdir)/$(DYNAMIC_LIBRARY); fi
155	( cd $(INSTALL_PREFIX)$(libdir) ; ln -sf $(DYNAMIC_LIBRARY) libpri.so)
156	$(BSD_INSTALL_DATA) $(STATIC_LIBRARY) $(INSTALL_PREFIX)$(libdir)
157	#if test $$(id -u) = 0; then $(LDCONFIG) $(LDCONFIG_FLAGS) $(INSTALL_PREFIX)$(libdir); fi
158else
159	install -f $(INSTALL_PREFIX)$(INSTALL_BASE)/include -m 644 libpri.h
160	install -f $(INSTALL_PREFIX)$(libdir) -m 755 $(DYNAMIC_LIBRARY)
161	( cd $(INSTALL_PREFIX)$(libdir) ; ln -sf $(DYNAMIC_LIBRARY) libpri.so)
162	install -f $(INSTALL_PREFIX)$(libdir) -m 644 $(STATIC_LIBRARY)
163endif
164
165uninstall:
166	@echo "Removing Libpri"
167	rm -f $(INSTALL_PREFIX)$(libdir)/$(STATIC_LIBRARY)
168	rm -f $(INSTALL_PREFIX)$(libdir)/libpri.so
169	rm -f $(INSTALL_PREFIX)$(libdir)/$(DYNAMIC_LIBRARY)
170	rm -f $(INSTALL_PREFIX)$(INSTALL_BASE)/include/libpri.h
171
172pritest: pritest.o $(STATIC_LIBRARY)
173	$(CC) -o $@ $< $(STATIC_LIBRARY) $(CFLAGS)
174
175testprilib.o: testprilib.c
176	$(CC) $(CFLAGS) -D_REENTRANT -D_GNU_SOURCE $(MAKE_DEPS) -c -o $@ $<
177
178testprilib: testprilib.o $(STATIC_LIBRARY)
179	$(CC) -o $@ $< $(STATIC_LIBRARY) -lpthread $(CFLAGS)
180
181pridump: pridump.o $(DYNAMIC_LIBRARY)
182	$(CC) -o $@ $< -L. -lpri $(CFLAGS)
183
184rosetest: rosetest.o $(STATIC_LIBRARY)
185	$(CC) -o $@ $< $(STATIC_LIBRARY) $(CFLAGS)
186
187MAKE_DEPS= -MD -MT $@ -MF .$(subst /,_,$@).d -MP
188
189%.o: %.c
190	$(CC) $(CFLAGS) $(MAKE_DEPS) -c -o $@ $<
191
192%.lo: %.c
193	$(CC) $(CFLAGS) $(MAKE_DEPS) -fPIC -c -o $@ $<
194
195$(STATIC_LIBRARY): $(STATIC_OBJS)
196	ar rcs $(STATIC_LIBRARY) $(STATIC_OBJS)
197	ranlib $(STATIC_LIBRARY)
198
199$(DYNAMIC_LIBRARY): $(DYNAMIC_OBJS)
200	$(CC) $(SOFLAGS) -o $@ $(DYNAMIC_OBJS)
201	#$(LDCONFIG) $(LDCONFIG_FLAGS) .
202	ln -sf $(DYNAMIC_LIBRARY) libpri.so
203
204version.c: FORCE
205	@build_tools/make_version_c > $@.tmp
206	@cmp -s $@.tmp $@ || mv $@.tmp $@
207	@rm -f $@.tmp
208
209clean:
210	rm -f *.o *.so *.lo
211	rm -f $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
212	rm -f $(UTILITIES)
213	rm -f .*.d
214
215.PHONY:
216
217FORCE:
218
219ifneq ($(wildcard .*.d),)
220   include .*.d
221endif
222