#
# 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.
# 
# 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.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
#
#
# Uncomment if you want libpri not send PROGRESS_INDICATOR w/ALERTING
#ALERTING=-DALERTING_NO_PROGRESS

# Uncomment if you want libpri to count number of Q921/Q931 sent/received
#LIBPRI_COUNTERS=-DLIBPRI_COUNTERS

OSARCH=$(shell uname -s)
PROC=$(shell uname -m)

STATIC_LIBRARY=libgsmat.a
DYNAMIC_LIBRARY=libgsmat.so.1.0
STATIC_OBJS=gsm.o gsmsched.o gsm_modem.o gsm_sms.o
DYNAMIC_OBJS=gsm.lo gsmsched.lo gsm_modem.lo gsm_sms.lo
CFLAGS=-Wall -Wstrict-prototypes -Wmissing-prototypes -g
INSTALL_PREFIX=
ifeq (${OSARCH},Linux)
LDCONFIG_FLAGS=-n
else
ifeq (${OSARCH},FreeBSD)
LDCONFIG_FLAGS=-m
CFLAGS += -I../zaptel -I../zapata
endif
endif

#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
CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
endif

all: depend $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)

install: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
	mkdir -p $(INSTALL_PREFIX)/usr/lib
	mkdir -p $(INSTALL_PREFIX)/usr/include
	install -m 644 libgsmat.h $(INSTALL_PREFIX)/usr/include
	install -m 755 $(DYNAMIC_LIBRARY) $(INSTALL_PREFIX)/usr/lib
	if [ -x /usr/sbin/sestatus ] && ( /usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled"); then  restorecon -v $(INSTALL_PREFIX)/$(INSTALL_BASE)/lib/$(DYNAMIC_LIBRARY); fi
	( cd $(INSTALL_PREFIX)/usr/lib ; ln -sf libgsmat.so.1 libgsmat.so )
	install -m 644 $(STATIC_LIBRARY) $(INSTALL_PREFIX)/usr/lib
	/sbin/ldconfig

uninstall:
	@echo "Removing Libpri"
	rm -f $(INSTALL_PREFIX)/usr/lib/libgsmat.so.1.0
	rm -f $(INSTALL_PREFIX)/usr/lib/libgsmat.so
	rm -f $(INSTALL_PREFIX)/usr/lib/libgsmat.a
	rm -f $(INSTALL_PREFIX)/usr/include/libgsmat.h

gsmtest: gsmtest.o
	$(CC) -o gsmtest gsmtest.o -L. -lgsm 

gsm_sms_test: gsm_sms_test.o
	$(CC) -o gsm_sms_test gsm_sms_test.o -L. -lgsm 

ifneq ($(wildcard .depend),)
include .depend
endif

%.lo : %.c
	$(CC) -fPIC $(CFLAGS) -o $@ -c $<

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

$(DYNAMIC_LIBRARY): $(DYNAMIC_OBJS)
	$(CC) -shared -Wl,-soname,libgsmat.so.1 -o $@ $(DYNAMIC_OBJS) -lm
	/sbin/ldconfig $(LDCONFIG_FLAGS) .
	ln -sf libgsmat.so.1 libgsmat.so

clean:
	rm -f *.o *.so *.lo *.so.1 *.so.1.0
	rm -f $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
	rm -f .depend
	rm -f gsmtest gsm_sms

depend: .depend

.depend: 
	./mkdep ${CFLAGS} `ls *.c`
