$Id$
--- gsm-1.0-pl10.orig/Makefile	Tue Jul  2 16:36:06 1996
+++ gsm-1.0-pl10/Makefile	Sat Jan 20 13:23:30 2007
@@ -7,11 +7,13 @@
 SASR	= -DSASR
 ######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1)
 
-MULHACK = -DUSE_FLOAT_MUL
+#MULHACK = -DUSE_FLOAT_MUL
+MULHACK =
 ######### Define this if your host multiplies floats faster than integers,
 ######### e.g. on a SPARCstation.
 
-FAST	= -DFAST
+#FAST	= -DFAST
+FAST	=
 ######### Define together with USE_FLOAT_MUL to enable the GSM library's
 ######### approximation option for incorrect, but good-enough results.
 
@@ -43,8 +45,9 @@ WAV49	=
 # CC		= /usr/lang/acc
 # CCFLAGS 	= -c -O
 
-CC		= gcc -ansi -pedantic
-CCFLAGS 	= -c -O2 -DNeedFunctionPrototypes=1
+CC		?= gcc -ansi -pedantic
+COPTS		?= -O2
+CCFLAGS 	= -c $(COPTS) -DNeedFunctionPrototypes=1
 
 LD 		= $(CC)
 
@@ -78,10 +81,10 @@ INSTALL_ROOT	=
 # Leave GSM_INSTALL_ROOT empty to not install the GSM library outside of
 # this directory.
 
-GSM_INSTALL_ROOT = $(INSTALL_ROOT)
+GSM_INSTALL_ROOT = $(INSTALL_ROOT)/usr
 GSM_INSTALL_LIB = $(GSM_INSTALL_ROOT)/lib
-GSM_INSTALL_INC = $(GSM_INSTALL_ROOT)/inc
-GSM_INSTALL_MAN = $(GSM_INSTALL_ROOT)/man/man3
+GSM_INSTALL_INC = $(GSM_INSTALL_ROOT)/include
+GSM_INSTALL_MAN = $(GSM_INSTALL_ROOT)/share/man/man3
 
 
 # Where do you want to install the toast binaries and their manpage?
@@ -89,14 +92,14 @@ GSM_INSTALL_MAN = $(GSM_INSTALL_ROOT)/ma
 # Leave TOAST_INSTALL_ROOT empty to not install the toast binaries outside
 # of this directory.
 
-TOAST_INSTALL_ROOT	  = $(INSTALL_ROOT)
+TOAST_INSTALL_ROOT	  = $(INSTALL_ROOT)/usr
 TOAST_INSTALL_BIN = $(TOAST_INSTALL_ROOT)/bin
-TOAST_INSTALL_MAN = $(TOAST_INSTALL_ROOT)/man/man1
+TOAST_INSTALL_MAN = $(TOAST_INSTALL_ROOT)/share/man/man1
 
 #  Other tools
 
 SHELL		= /bin/sh
-LN		= ln
+LN		= ln -s
 BASENAME 	= basename
 AR		= ar
 ARFLAGS		= cr
@@ -126,7 +129,7 @@ INC	= $(ROOT)/inc
 
 # Flags
 
-# DEBUG	= -DNDEBUG
+DEBUG	= -DNDEBUG
 ######### Remove -DNDEBUG to enable assertions.
 
 CFLAGS	= $(CCFLAGS) $(SASR) $(DEBUG) $(MULHACK) $(FAST) $(LTP_CUT) \
@@ -140,6 +143,7 @@ LFLAGS	= $(LDFLAGS) $(LDINC)
 # Targets
 
 LIBGSM	= $(LIB)/libgsm.a
+LIBGSMSO= $(LIB)/libgsm.so
 
 TOAST	= $(BIN)/toast
 UNTOAST	= $(BIN)/untoast
@@ -258,6 +262,9 @@ STUFF = 	ChangeLog			\
 
 GSM_INSTALL_TARGETS =	\
 		$(GSM_INSTALL_LIB)/libgsm.a		\
+		$(GSM_INSTALL_LIB)/libgsm.so		\
+		$(GSM_INSTALL_LIB)/libgsm.so.1		\
+		$(GSM_INSTALL_LIB)/libgsm.so.1.0.10	\
 		$(GSM_INSTALL_INC)/gsm.h		\
 		$(GSM_INSTALL_MAN)/gsm.3		\
 		$(GSM_INSTALL_MAN)/gsm_explode.3	\
@@ -279,7 +286,7 @@ TOAST_INSTALL_TARGETS =	\
 
 # Target rules
 
-all:		$(LIBGSM) $(TOAST) $(TCAT) $(UNTOAST)
+all:		$(LIBGSM) $(LIBGSMSO) $(TOAST) $(TCAT) $(UNTOAST)
 		@-echo $(ROOT): Done.
 
 tst:		$(TST)/lin2cod $(TST)/cod2lin $(TOAST) $(TST)/test-result
@@ -299,6 +306,11 @@ install:	toastinstall gsminstall
 
 # The basic API: libgsm
 
+$(LIBGSMSO):	$(LIB) $(GSM_OBJECTS)
+		$(LD) -o $@.1.0.10 -shared -Xlinker -soname -Xlinker libgsm.so.1 $(GSM_OBJECTS) -lc
+		ln -fs libgsm.so.1.0.10 lib/libgsm.so.1
+		ln -fs libgsm.so.1.0.10 lib/libgsm.so
+
 $(LIBGSM):	$(LIB) $(GSM_OBJECTS)
 		-rm $(RMFLAGS) $(LIBGSM)
 		$(AR) $(ARFLAGS) $(LIBGSM) $(GSM_OBJECTS)
@@ -308,15 +320,15 @@ $(LIBGSM):	$(LIB) $(GSM_OBJECTS)
 # Toast, Untoast and Tcat -- the compress-like frontends to gsm.
 
 $(TOAST):	$(BIN) $(TOAST_OBJECTS) $(LIBGSM)
-		$(LD) $(LFLAGS) -o $(TOAST) $(TOAST_OBJECTS) $(LIBGSM) $(LDLIB)
+		$(LD) $(LFLAGS) -o $(TOAST) $(TOAST_OBJECTS) $(LIBGSMSO) $(LDLIB)
 
 $(UNTOAST):	$(BIN) $(TOAST)
 		-rm $(RMFLAGS) $(UNTOAST)
-		$(LN) $(TOAST) $(UNTOAST)
+		$(LN) toast $(UNTOAST)
 
 $(TCAT):	$(BIN) $(TOAST)
 		-rm $(RMFLAGS) $(TCAT)
-		$(LN) $(TOAST) $(TCAT)
+		$(LN) toast $(TCAT)
 
 
 # The local bin and lib directories
@@ -332,12 +344,12 @@ $(LIB):
 
 gsminstall:
 		-if [ x"$(GSM_INSTALL_ROOT)" != x ] ; then	\
-			make $(GSM_INSTALL_TARGETS) ;	\
+			$(MAKE) $(GSM_INSTALL_TARGETS) ;	\
 		fi
 
 toastinstall:
 		-if [ x"$(TOAST_INSTALL_ROOT)" != x ]; then	\
-			make $(TOAST_INSTALL_TARGETS);	\
+			$(MAKE) $(TOAST_INSTALL_TARGETS);	\
 		fi
 
 gsmuninstall:
@@ -351,54 +363,67 @@ toastuninstall:
 		fi
 
 $(TOAST_INSTALL_BIN)/toast:	$(TOAST)
-		-rm $@
-		cp $(TOAST) $@
+		mkdir -p $(TOAST_INSTALL_BIN)
+		cp -f $(TOAST) $@
 		chmod 755 $@
 
 $(TOAST_INSTALL_BIN)/untoast:	$(TOAST_INSTALL_BIN)/toast
-		-rm $@
-		ln $? $@
+		mkdir -p $(TOAST_INSTALL_BIN)
+		ln -sf $? $@
 
 $(TOAST_INSTALL_BIN)/tcat:	$(TOAST_INSTALL_BIN)/toast
-		-rm $@
-		ln $? $@
+		mkdir -p $(TOAST_INSTALL_BIN)
+		ln -sf $? $@
 
 $(TOAST_INSTALL_MAN)/toast.1:	$(MAN)/toast.1
-		-rm $@
-		cp $? $@
+		mkdir -p $(TOAST_INSTALL_MAN)
+		cp -f $? $@
 		chmod 444 $@
 
 $(GSM_INSTALL_MAN)/gsm.3:	$(MAN)/gsm.3
-		-rm $@
-		cp $? $@
+		mkdir -p $(GSM_INSTALL_MAN)
+		cp -f $? $@
 		chmod 444 $@
 
 $(GSM_INSTALL_MAN)/gsm_option.3:	$(MAN)/gsm_option.3
-		-rm $@
-		cp $? $@
+		mkdir -p $(GSM_INSTALL_MAN)
+		cp -f $? $@
 		chmod 444 $@
 
 $(GSM_INSTALL_MAN)/gsm_explode.3:	$(MAN)/gsm_explode.3
-		-rm $@
-		cp $? $@
+		mkdir -p $(GSM_INSTALL_MAN)
+		cp -f $? $@
 		chmod 444 $@
 
 $(GSM_INSTALL_MAN)/gsm_print.3:	$(MAN)/gsm_print.3
-		-rm $@
-		cp $? $@
+		mkdir -p $(GSM_INSTALL_MAN)
+		cp -f $? $@
 		chmod 444 $@
 
 $(GSM_INSTALL_INC)/gsm.h:	$(INC)/gsm.h
-		-rm $@
-		cp $? $@
+		mkdir -p $(GSM_INSTALL_INC)
+		cp -f $? $@
 		chmod 444 $@
 
 $(GSM_INSTALL_LIB)/libgsm.a:	$(LIBGSM)
-		-rm $@
-		cp $? $@
+		mkdir -p $(GSM_INSTALL_LIB)
+		cp -f $? $@
 		chmod 444 $@
 
+$(GSM_INSTALL_LIB)/libgsm.so:	$(LIBGSMSO)
+		mkdir -p $(GSM_INSTALL_LIB)
+		cp -f $? $@
 
+$(GSM_INSTALL_LIB)/libgsm.so.1:	$(LIBGSMSO)
+		mkdir -p $(GSM_INSTALL_LIB)
+		cp -f $? $@
+
+$(GSM_INSTALL_LIB)/libgsm.so.1.0.10:	$(LIBGSMSO)
+		mkdir -p $(GSM_INSTALL_LIB)
+		cp -f $? $@
+		chmod 755 $@
+
+
 # Distribution
 
 dist:		gsm-1.0.tar.Z
@@ -426,7 +451,9 @@ semi-clean:
 
 clean:	semi-clean
 		-rm $(RMFLAGS) $(LIBGSM) $(ADDTST)/add		\
-			$(TOAST) $(TCAT) $(UNTOAST)	\
+			$(LIBGSMSO) $(LIB)/libgsm.so.1.0.10	\
+			$(LIB)libgsm.so.1			\
+			$(TOAST) $(TCAT) $(UNTOAST)		\
 			$(ROOT)/gsm-1.0.tar.Z
 
 
