Makefile 6.4 KB
Newer Older
Mark Spencer's avatar
Mark Spencer committed
1 2 3 4 5 6 7 8 9 10 11 12
#
# libpri: An implementation of Primary Rate ISDN
#
# Written by Mark Spencer <markster@linux-support.net>
#
# Copyright (C) 2001, Linux Support Services, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
13
#
Mark Spencer's avatar
Mark Spencer committed
14 15 16 17
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
18
#
Mark Spencer's avatar
Mark Spencer committed
19 20
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Mark Spencer's avatar
Mark Spencer committed
22
#
23 24 25 26
#
# Uncomment if you want libpri not send PROGRESS_INDICATOR w/ALERTING
#ALERTING=-DALERTING_NO_PROGRESS

27
CC=gcc
28 29
GREP=grep
AWK=awk
30

Mark Spencer's avatar
Mark Spencer committed
31
OSARCH=$(shell uname -s)
32
PROC?=$(shell uname -m)
Mark Spencer's avatar
Mark Spencer committed
33

34 35 36 37 38
# SONAME version; should be changed on every ABI change
# please don't change it needlessly; it's perfectly fine to have a SONAME
# of 1.2 and a version of 1.4.x
SONAME:=1.4

Mark Spencer's avatar
Mark Spencer committed
39
STATIC_LIBRARY=libpri.a
40
DYNAMIC_LIBRARY:=libpri.so.$(SONAME)
41 42 43 44 45 46
STATIC_OBJS= \
	copy_string.o \
	pri.o \
	q921.o \
	prisched.o \
	q931.o \
47
	pri_aoc.o \
48
	pri_cc.o \
49 50 51 52 53
	pri_facility.o \
	asn1_primitive.o \
	rose.o \
	rose_address.o \
	rose_etsi_aoc.o \
54
	rose_etsi_cc.o \
55 56
	rose_etsi_diversion.o \
	rose_etsi_ect.o \
57
	rose_etsi_mwi.o \
58 59
	rose_other.o \
	rose_q931.o \
60
	rose_qsig_aoc.o \
61
	rose_qsig_cc.o \
62 63 64 65 66 67
	rose_qsig_ct.o \
	rose_qsig_diversion.o \
	rose_qsig_mwi.o \
	rose_qsig_name.o \
	version.o
DYNAMIC_OBJS= \
68
	$(STATIC_OBJS)
69 70 71
CFLAGS ?= -g
CFLAGS += -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes
CFLAGS += -fPIC $(ALERTING) $(LIBPRI_OPT) $(COVERAGE_CFLAGS)
72
INSTALL_PREFIX=$(DESTDIR)
73
INSTALL_BASE=/usr
74
libdir?=$(INSTALL_BASE)/lib
75
ifneq ($(findstring Darwin,$(OSARCH)),)
76
  SOFLAGS=$(LDFLAGS) -dynamic -bundle -Xlinker -macosx_version_min -Xlinker 10.4 -Xlinker -undefined -Xlinker dynamic_lookup -force_flat_namespace
77 78 79 80 81
  ifeq ($(shell /usr/bin/sw_vers -productVersion | cut -c1-4),10.6)
    SOFLAGS+=/usr/lib/bundle1.o
  endif
  LDCONFIG=/usr/bin/true
else
82
  SOFLAGS=$(LDFLAGS) -shared -Wl,-h$(DYNAMIC_LIBRARY) $(COVERAGE_LDFLAGS)
83 84
  LDCONFIG = /sbin/ldconfig
endif
85
ifneq (,$(findstring X$(OSARCH)X, XLinuxX XGNU/kFreeBSDX XGNUX))
Mark Spencer's avatar
Mark Spencer committed
86 87 88 89 90
LDCONFIG_FLAGS=-n
else
ifeq (${OSARCH},FreeBSD)
LDCONFIG_FLAGS=-m
CFLAGS += -I../zaptel -I../zapata
91
INSTALL_BASE=/usr/local
Mark Spencer's avatar
Mark Spencer committed
92 93
endif
endif
94
ifeq (${OSARCH},SunOS)
95
CFLAGS += -DSOLARIS -I../zaptel-solaris
96
LDCONFIG =
97 98
LDCONFIG_FLAGS = \# # Trick to comment out the period in the command below
#INSTALL_PREFIX = /opt/asterisk  # Uncomment out to install in standard Solaris location for 3rd party code
99
endif
Mark Spencer's avatar
Mark Spencer committed
100

101 102
UTILITIES= pridump pritest rosetest testprilib

103 104 105 106
export PRIVERSION

PRIVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) build_tools/make_version .)

107 108 109 110 111
#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
#This works for even old (2.96) versions of gcc and provides a small boost either way.
#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesnt support it.
ifeq ($(PROC),sparc64)
PROC=ultrasparc
112 113
LIBPRI_OPT = -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
else
114 115 116 117 118 119 120
  ifneq ($(CODE_COVERAGE),)
    LIBPRI_OPT=
    COVERAGE_CFLAGS=-ftest-coverage -fprofile-arcs
    COVERAGE_LDFLAGS=-ftest-coverage -fprofile-arcs
  else
    LIBPRI_OPT=-O2
  endif
121 122
endif

123 124 125 126 127
ifeq ($(CPUARCH),i686)
CFLAGS += -m32
SOFLAGS += -m32
endif

128
all: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY) $(UTILITIES)
Mark Spencer's avatar
Mark Spencer committed
129

Mark Spencer's avatar
Mark Spencer committed
130
update:
131 132
	@if [ -d .svn ]; then \
		echo "Updating from Subversion..." ; \
133 134 135 136 137 138 139 140 141 142
		fromrev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
		svn update | tee update.out; \
		torev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
		echo "`date`  Updated from revision $${fromrev} to $${torev}." >> update.log; \
		rm -f .version; \
		if [ `grep -c ^C update.out` -gt 0 ]; then \
			echo ; echo "The following files have conflicts:" ; \
			grep ^C update.out | cut -b4- ; \
		fi ; \
		rm -f update.out; \
143
	else \
144
		echo "Not under version control";  \
145
	fi
Mark Spencer's avatar
Mark Spencer committed
146

Mark Spencer's avatar
Mark Spencer committed
147
install: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
148
	mkdir -p $(INSTALL_PREFIX)$(libdir)
149 150 151
	mkdir -p $(INSTALL_PREFIX)$(INSTALL_BASE)/include
ifneq (${OSARCH},SunOS)
	install -m 644 libpri.h $(INSTALL_PREFIX)$(INSTALL_BASE)/include
152
	install -m 755 $(DYNAMIC_LIBRARY) $(INSTALL_PREFIX)$(libdir)
153
	#if [ -x /usr/sbin/sestatus ] && ( /usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled"); then /sbin/restorecon -v $(INSTALL_PREFIX)$(libdir)/$(DYNAMIC_LIBRARY); fi
154
	( cd $(INSTALL_PREFIX)$(libdir) ; ln -sf $(DYNAMIC_LIBRARY) libpri.so)
155 156
	install -m 644 $(STATIC_LIBRARY) $(INSTALL_PREFIX)$(libdir)
	if test $$(id -u) = 0; then $(LDCONFIG) $(LDCONFIG_FLAGS) $(INSTALL_PREFIX)$(libdir); fi
157 158
else
	install -f $(INSTALL_PREFIX)$(INSTALL_BASE)/include -m 644 libpri.h
159
	install -f $(INSTALL_PREFIX)$(libdir) -m 755 $(DYNAMIC_LIBRARY)
160
	( cd $(INSTALL_PREFIX)$(libdir) ; ln -sf $(DYNAMIC_LIBRARY) libpri.so)
161
	install -f $(INSTALL_PREFIX)$(libdir) -m 644 $(STATIC_LIBRARY)
162
endif
Mark Spencer's avatar
Mark Spencer committed
163

Mark Spencer's avatar
Mark Spencer committed
164 165
uninstall:
	@echo "Removing Libpri"
166
	rm -f $(INSTALL_PREFIX)$(libdir)/$(STATIC_LIBRARY)
167
	rm -f $(INSTALL_PREFIX)$(libdir)/libpri.so
168
	rm -f $(INSTALL_PREFIX)$(libdir)/$(DYNAMIC_LIBRARY)
169
	rm -f $(INSTALL_PREFIX)$(INSTALL_BASE)/include/libpri.h
Mark Spencer's avatar
Mark Spencer committed
170

171 172
pritest: pritest.o $(STATIC_LIBRARY)
	$(CC) -o $@ $< $(STATIC_LIBRARY) $(CFLAGS)
Mark Spencer's avatar
Mark Spencer committed
173

174
testprilib.o: testprilib.c
175
	$(CC) $(CFLAGS) -D_REENTRANT -D_GNU_SOURCE $(MAKE_DEPS) -c -o $@ $<
176

177 178
testprilib: testprilib.o $(STATIC_LIBRARY)
	$(CC) -o $@ $< $(STATIC_LIBRARY) -lpthread $(CFLAGS)
179

180 181
pridump: pridump.o $(DYNAMIC_LIBRARY)
	$(CC) -o $@ $< -L. -lpri $(CFLAGS)
Mark Spencer's avatar
Mark Spencer committed
182

183 184
rosetest: rosetest.o $(STATIC_LIBRARY)
	$(CC) -o $@ $< $(STATIC_LIBRARY) $(CFLAGS)
185

186 187 188 189
MAKE_DEPS= -MD -MT $@ -MF .$(subst /,_,$@).d -MP

%.o: %.c
	$(CC) $(CFLAGS) $(MAKE_DEPS) -c -o $@ $<
190

191 192
%.lo: %.c
	$(CC) $(CFLAGS) $(MAKE_DEPS) -c -o $@ $<
Mark Spencer's avatar
Mark Spencer committed
193 194 195 196 197 198

$(STATIC_LIBRARY): $(STATIC_OBJS)
	ar rcs $(STATIC_LIBRARY) $(STATIC_OBJS)
	ranlib $(STATIC_LIBRARY)

$(DYNAMIC_LIBRARY): $(DYNAMIC_OBJS)
199
	$(CC) $(SOFLAGS) -o $@ $(DYNAMIC_OBJS)
200
	$(LDCONFIG) $(LDCONFIG_FLAGS) .
201
	ln -sf $(DYNAMIC_LIBRARY) libpri.so
Mark Spencer's avatar
Mark Spencer committed
202

203
version.c: FORCE
204 205 206 207
	@build_tools/make_version_c > $@.tmp
	@cmp -s $@.tmp $@ || mv $@.tmp $@
	@rm -f $@.tmp

Mark Spencer's avatar
Mark Spencer committed
208
clean:
209 210 211
	rm -f *.o *.so *.lo
	rm -f $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
	rm -f $(UTILITIES)
212
	rm -f .*.d
213

214
.PHONY:
215

216
FORCE:
217

218 219 220
ifneq ($(wildcard .*.d),)
   include .*.d
endif