1# Copyright 1992-1996 by Jutta Degener and Carsten Bormann, Technische
2# Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
3# details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
4
5# Machine- or installation dependent flags you should configure to port
6
7SASR	= -DSASR
8######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1)
9
10# MULHACK = -DUSE_FLOAT_MUL
11######### Define this if your host multiplies floats faster than integers,
12######### e.g. on a SPARCstation.
13
14# FAST	= -DFAST
15######### Define together with USE_FLOAT_MUL to enable the GSM library's
16######### approximation option for incorrect, but good-enough results.
17
18# LTP_CUT	= -DLTP_CUT
19LTP_CUT	=
20######### Define to enable the GSM library's long-term correlation
21######### approximation option---faster, but worse; works for
22######### both integer and floating point multiplications.
23######### This flag is still in the experimental stage.
24
25WAV49	= -DWAV49
26# WAV49	=
27######### Define to enable the GSM library's option to pack GSM frames
28######### in the style used by the WAV #49 format.  If you want to write
29######### a tool that produces .WAV files which contain GSM-encoded data,
30######### define this, and read about the GSM_OPT_WAV49 option in the
31######### manual page on gsm_option(3).
32
33# Choose a compiler.  The code works both with ANSI and K&R-C.
34# Use -DNeedFunctionPrototypes to compile with, -UNeedFunctionPrototypes to
35# compile without, function prototypes in the header files.
36#
37# You can use the -DSTUPID_COMPILER to circumvent some compilers'
38# static limits regarding the number of subexpressions in a statement.
39
40# CC		= cc
41# CCFLAGS 	= -c -DSTUPID_COMPILER
42
43# CC		= /usr/lang/acc
44# CCFLAGS 	= -c -O
45
46#CC		= gcc -ansi -pedantic
47CCFLAGS 	+= -c -DNeedFunctionPrototypes=1 -Wall -Wno-comment
48
49LD 		= $(CC)
50
51# LD		= gcc
52# LDFLAGS 	=
53
54
55# If your compiler needs additional flags/libraries, regardless of
56# the source compiled, configure them here.
57
58# CCINC	= -I/usr/gnu/lib/gcc-2.1/gcc-lib/sparc-sun-sunos4.1.2/2.1/include
59######### Includes needed by $(CC)
60
61# LDINC	= -L/usr/gnu/lib/gcc-2.1/gcc-lib/sparc-sun-sunos4.1.2/2.1
62LDINC = -L$(LIB)
63######### Library paths needed by $(LD)
64
65# LDLIB	= -lgcc
66######### Additional libraries needed by $(LD)
67
68#PREFIX= /usr/local
69
70# Where do you want to install libraries, binaries, a header file
71# and the manual pages?
72#
73# Leave INSTALL_ROOT empty (or just don't execute "make install") to
74# not install gsm and toast outside of this directory.
75
76INSTALL_ROOT    =       $(DESTDIR)$(PREFIX)
77
78# Where do you want to install the gsm library, header file, and manpages?
79#
80# Leave GSM_INSTALL_ROOT empty to not install the GSM library outside of
81# this directory.
82
83GSM_INSTALL_ROOT = $(INSTALL_ROOT)
84GSM_INSTALL_LIB = $(GSM_INSTALL_ROOT)/lib
85GSM_INSTALL_INC = $(GSM_INSTALL_ROOT)/include
86GSM_INSTALL_MAN = $(GSM_INSTALL_ROOT)/man/man3
87
88
89# Where do you want to install the toast binaries and their manpage?
90#
91# Leave TOAST_INSTALL_ROOT empty to not install the toast binaries outside
92# of this directory.
93
94TOAST_INSTALL_ROOT	  = $(INSTALL_ROOT)
95TOAST_INSTALL_BIN = $(TOAST_INSTALL_ROOT)/bin
96TOAST_INSTALL_MAN = $(TOAST_INSTALL_ROOT)/man/man1
97
98#  Other tools
99
100SHELL		= /bin/sh
101LN		= ln
102BASENAME 	= basename
103AR		= ar
104ARFLAGS		= cr
105RMFLAGS		=
106FIND		= find
107COMPRESS 	= gzip
108COMPRESSFLAGS 	=
109# RANLIB 	= true
110RANLIB	 	= ranlib
111RM		= rm -f
112
113#
114#    You shouldn't have to configure below this line if you're porting.
115#
116
117
118# Local Directories
119
120ROOT	= .
121ADDTST	= $(ROOT)/add-test
122TST	= $(ROOT)/tst
123MAN	= $(ROOT)/man
124BIN	= $(ROOT)/bin
125SRC	= $(ROOT)/src
126LIB	= $(ROOT)/lib
127TLS	= $(ROOT)/tls
128INC	= $(ROOT)/inc
129
130# Flags
131
132# DEBUG	= -DNDEBUG
133######### Remove -DNDEBUG to enable assertions.
134
135CFLAGS += $(CCFLAGS) $(SASR) $(DEBUG) $(MULHACK) $(FAST) $(LTP_CUT) \
136	$(WAV49) $(CCINC) -I$(INC)
137######### It's $(CC) $(CFLAGS)
138
139LFLAGS	= $(LDFLAGS) $(LDINC)
140######### It's $(LD) $(LFLAGS)
141
142.SUFFIXES: .c .so .o
143
144# Targets
145
146LIBGSM	= libgsm.a
147SOLIBGSM	= libgsm.so.1
148TOAST	= $(BIN)/toast
149UNTOAST	= $(BIN)/untoast
150TCAT	= $(BIN)/tcat
151
152# Headers
153
154GSM_HEADERS =	$(INC)/gsm.h
155
156HEADERS	=	$(INC)/proto.h		\
157		$(INC)/unproto.h	\
158		$(INC)/config.h		\
159		$(INC)/private.h	\
160		$(INC)/gsm.h		\
161		$(INC)/toast.h		\
162		$(TLS)/taste.h
163
164# Sources
165
166GSM_SOURCES =	$(SRC)/add.c		\
167		$(SRC)/code.c		\
168		$(SRC)/debug.c		\
169		$(SRC)/decode.c		\
170		$(SRC)/long_term.c	\
171		$(SRC)/lpc.c		\
172		$(SRC)/preprocess.c	\
173		$(SRC)/rpe.c		\
174		$(SRC)/gsm_destroy.c	\
175		$(SRC)/gsm_decode.c	\
176		$(SRC)/gsm_encode.c	\
177		$(SRC)/gsm_explode.c	\
178		$(SRC)/gsm_implode.c	\
179		$(SRC)/gsm_create.c	\
180		$(SRC)/gsm_print.c	\
181		$(SRC)/gsm_option.c	\
182		$(SRC)/short_term.c	\
183		$(SRC)/table.c
184
185TOAST_SOURCES = $(SRC)/toast.c 		\
186		$(SRC)/toast_lin.c	\
187		$(SRC)/toast_ulaw.c	\
188		$(SRC)/toast_alaw.c	\
189		$(SRC)/toast_audio.c
190
191SOURCES	=	$(GSM_SOURCES)		\
192		$(TOAST_SOURCES)	\
193		$(ADDTST)/add_test.c	\
194		$(TLS)/sour.c		\
195		$(TLS)/ginger.c		\
196		$(TLS)/sour1.dta	\
197		$(TLS)/sour2.dta	\
198		$(TLS)/bitter.c		\
199		$(TLS)/bitter.dta	\
200		$(TLS)/taste.c		\
201		$(TLS)/sweet.c		\
202		$(TST)/cod2lin.c	\
203		$(TST)/cod2txt.c	\
204		$(TST)/gsm2cod.c	\
205		$(TST)/lin2cod.c	\
206		$(TST)/lin2txt.c
207
208# Object files
209
210GSM_OBJECTS =	$(SRC)/add.o		\
211		$(SRC)/code.o		\
212		$(SRC)/debug.o		\
213		$(SRC)/decode.o		\
214		$(SRC)/long_term.o	\
215		$(SRC)/lpc.o		\
216		$(SRC)/preprocess.o	\
217		$(SRC)/rpe.o		\
218		$(SRC)/gsm_destroy.o	\
219		$(SRC)/gsm_decode.o	\
220		$(SRC)/gsm_encode.o	\
221		$(SRC)/gsm_explode.o	\
222		$(SRC)/gsm_implode.o	\
223		$(SRC)/gsm_create.o	\
224		$(SRC)/gsm_print.o	\
225		$(SRC)/gsm_option.o	\
226		$(SRC)/short_term.o	\
227		$(SRC)/table.o
228
229TOAST_OBJECTS =	$(SRC)/toast.o 		\
230		$(SRC)/toast_lin.o	\
231		$(SRC)/toast_ulaw.o	\
232		$(SRC)/toast_alaw.o	\
233		$(SRC)/toast_audio.o
234
235OBJECTS =	 $(GSM_OBJECTS) $(TOAST_OBJECTS)
236
237# Manuals
238
239GSM_MANUALS =	$(MAN)/gsm.3		\
240		$(MAN)/gsm_explode.3	\
241		$(MAN)/gsm_option.3	\
242		$(MAN)/gsm_print.3
243
244TOAST_MANUALS =	$(MAN)/toast.1
245
246MANUALS	= 	$(GSM_MANUALS) $(TOAST_MANUALS) $(MAN)/bitter.1
247
248# Other stuff in the distribution
249
250STUFF = 	ChangeLog			\
251		INSTALL			\
252		MACHINES		\
253		MANIFEST		\
254		Makefile		\
255		README			\
256		$(ADDTST)/add_test.dta	\
257		$(TLS)/bitter.dta	\
258		$(TST)/run
259
260
261# Install targets
262
263GSM_INSTALL_TARGETS =	\
264		$(GSM_INSTALL_LIB)/$(LIBGSM)		\
265		$(GSM_INSTALL_LIB)/$(SOLIBGSM)		\
266		$(GSM_INSTALL_INC)/gsm.h		\
267		$(GSM_INSTALL_MAN)/gsm.3		\
268		$(GSM_INSTALL_MAN)/gsm_explode.3	\
269		$(GSM_INSTALL_MAN)/gsm_option.3		\
270		$(GSM_INSTALL_MAN)/gsm_print.3
271
272
273TOAST_INSTALL_TARGETS =	\
274		$(TOAST_INSTALL_BIN)/toast		\
275		$(TOAST_INSTALL_BIN)/tcat		\
276		$(TOAST_INSTALL_BIN)/untoast		\
277		$(TOAST_INSTALL_MAN)/toast.1
278
279
280# Default rules
281
282.c.o:
283		$(CC) $(CFLAGS) $?
284		@-mv `$(BASENAME) $@` $@ > /dev/null 2>&1
285
286.c.so:
287		${CC} -fpic -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
288
289# Target rules
290
291all:            $(LIB)/$(LIBGSM) $(LIB)/$(SOLIBGSM) $(TOAST) $(TCAT) $(UNTOAST)
292		@-echo $(ROOT): Done.
293
294tst:		$(TST)/lin2cod $(TST)/cod2lin $(TOAST) $(TST)/test-result
295		@-echo tst: Done.
296
297addtst:		$(ADDTST)/add $(ADDTST)/add_test.dta
298		$(ADDTST)/add < $(ADDTST)/add_test.dta > /dev/null
299		@-echo addtst: Done.
300
301misc:		$(TLS)/sweet $(TLS)/bitter $(TLS)/sour $(TLS)/ginger 	\
302			$(TST)/lin2txt $(TST)/cod2txt $(TST)/gsm2cod
303		@-echo misc: Done.
304
305install:	toastinstall gsminstall
306		@-echo install: Done.
307
308
309# The basic API: libgsm
310
311$(LIB)/$(SOLIBGSM): $(LIB) $(GSM_OBJECTS:S/o$/so/g)
312		$(CC) -o $@ -shared -Wl,-soname,$(SOLIBGSM) $(GSM_OBJECTS:S/o$/so/g)
313		(cd $(LIB); $(LN) -sf $(SOLIBGSM) `echo $(SOLIBGSM) | sed 's/\.so.*$$/.so/'`)
314
315$(LIB)/$(LIBGSM):	$(LIB) $(GSM_OBJECTS)
316		$(RM) $(RMFLAGS) $(LIBGSM)
317		$(AR) $(ARFLAGS) $(LIB)/$(LIBGSM) $(GSM_OBJECTS)
318		$(RANLIB) $(LIB)/$(LIBGSM)
319
320
321# Toast, Untoast and Tcat -- the compress-like frontends to gsm.
322
323$(TOAST):	$(BIN) $(TOAST_OBJECTS) $(LIB)/$(LIBGSM)
324		$(LD) $(LFLAGS) -o $(TOAST) $(TOAST_OBJECTS) -lgsm $(LDLIB)
325
326$(UNTOAST):	$(BIN) $(TOAST)
327		$(RM) $(RMFLAGS) $(UNTOAST)
328		$(LN) -sf $(TOAST) $(UNTOAST)
329
330$(TCAT):	$(BIN) $(TOAST)
331		$(RM) $(RMFLAGS) $(TCAT)
332		$(LN) -sf $(TOAST) $(TCAT)
333
334
335# The local bin and lib directories
336
337$(BIN):
338		if [ ! -d $(BIN) ] ; then mkdir $(BIN) ; fi
339
340$(LIB):
341		if [ ! -d $(LIB) ] ; then mkdir $(LIB) ; fi
342
343
344# Installation
345
346gsminstall:
347		-if [ x"$(GSM_INSTALL_ROOT)" != x ] ; then	\
348			make $(GSM_INSTALL_TARGETS) ;	\
349		fi
350
351toastinstall:
352		-if [ x"$(TOAST_INSTALL_ROOT)" != x ]; then	\
353			make $(TOAST_INSTALL_TARGETS);	\
354		fi
355
356gsmuninstall:
357		-if [ x"$(GSM_INSTALL_ROOT)" != x ] ; then	\
358			$(RM)$(RMFLAGS) $(GSM_INSTALL_TARGETS) ;	\
359		fi
360
361toastuninstall:
362		-if [ x"$(TOAST_INSTALL_ROOT)" != x ] ; then 	\
363			$(RM)$(RMFLAGS) $(TOAST_INSTALL_TARGETS);	\
364		fi
365
366$(TOAST_INSTALL_BIN)/toast:	$(TOAST)
367		$(RM) $@
368		${BSD_INSTALL_PROGRAM} $(TOAST) $@
369
370$(TOAST_INSTALL_BIN)/untoast:	$(TOAST_INSTALL_BIN)/toast
371		$(RM) $@
372		$(LN) -sf toast $@
373
374$(TOAST_INSTALL_BIN)/tcat:	$(TOAST_INSTALL_BIN)/toast
375		$(RM) $@
376		$(LN) -sf toast $@
377
378$(TOAST_INSTALL_MAN)/toast.1:	$(MAN)/toast.1
379		$(RM) $@
380		${BSD_INSTALL_MAN} $? $@
381
382$(TOAST_INSTALL_MAN)/untoast.1:	$(MAN)/toast.1
383		$(RM) $@
384		$(LN) -sf toast.1 $@
385
386$(TOAST_INSTALL_MAN)/tcat.1:	$(MAN)/toast.1
387		$(RM) $@
388		$(LN) -sf toast.1 $@
389
390$(GSM_INSTALL_MAN)/gsm.3:	$(MAN)/gsm.3
391		$(RM) $@
392		${BSD_INSTALL_MAN} $? $@
393
394$(GSM_INSTALL_MAN)/gsm_option.3:	$(MAN)/gsm_option.3
395		$(RM) $@
396		${BSD_INSTALL_MAN} $? $@
397
398$(GSM_INSTALL_MAN)/gsm_explode.3:	$(MAN)/gsm_explode.3
399		$(RM) $@
400		${BSD_INSTALL_MAN} $? $@
401
402$(GSM_INSTALL_MAN)/gsm_print.3:	$(MAN)/gsm_print.3
403		$(RM) $@
404		${BSD_INSTALL_MAN} $? $@
405
406$(GSM_INSTALL_INC)/gsm.h:	$(INC)/gsm.h
407		$(RM) $@
408		${BSD_INSTALL_DATA} $? $@
409
410$(GSM_INSTALL_LIB)/$(LIBGSM):	$(LIB)/$(LIBGSM)
411		$(RM) $@
412		${BSD_INSTALL_DATA} $? $@
413
414$(GSM_INSTALL_LIB)/$(SOLIBGSM):    $(LIB)/$(SOLIBGSM)
415		$(RM) $@
416		${BSD_INSTALL_LIB} $? $@
417		(cd $(GSM_INSTALL_LIB); $(LN) -sf $(SOLIBGSM) `echo $(SOLIBGSM) | sed 's/\.so.*$$/.so/'`)
418
419# Distribution
420
421dist:		gsm-1.0.tar.gz
422		@echo dist: Done.
423
424gsm-1.0.tar.gz:	$(STUFF) $(SOURCES) $(HEADERS) $(MANUALS)
425		(	cd $(ROOT)/..;				\
426			tar cvf - `cat $(ROOT)/gsm-1.0/MANIFEST	\
427				| sed '/^#/d'`			\
428		) | $(COMPRESS) $(COMPRESSFLAGS) > $(ROOT)/gsm-1.0.tar.gz
429
430# Clean
431
432uninstall:	toastuninstall gsmuninstall
433		@-echo uninstall: Done.
434
435semi-clean:
436		-rm $(RMFLAGS)  */*.o			\
437			$(TST)/lin2cod $(TST)/lin2txt	\
438			$(TST)/cod2lin $(TST)/cod2txt	\
439			$(TST)/gsm2cod 			\
440			$(TST)/*.*.*
441		-$(FIND) . \( -name core -o -name foo \) \
442			-print | xargs rm $(RMFLAGS)
443
444clean:	semi-clean
445		-rm $(RMFLAGS) $(LIBGSM) $(ADDTST)/add		\
446			$(TOAST) $(TCAT) $(UNTOAST)	\
447			$(ROOT)/gsm-1.0.tar.Z
448
449
450# Two tools that helped me generate gsm_encode.c and gsm_decode.c,
451# but aren't generally needed to port this.
452
453$(TLS)/sweet:	$(TLS)/sweet.o $(TLS)/taste.o
454		$(LD) $(LFLAGS) -o $(TLS)/sweet \
455			$(TLS)/sweet.o $(TLS)/taste.o $(LDLIB)
456
457$(TLS)/bitter:	$(TLS)/bitter.o $(TLS)/taste.o
458		$(LD) $(LFLAGS) -o $(TLS)/bitter \
459			$(TLS)/bitter.o $(TLS)/taste.o $(LDLIB)
460
461# A version of the same family that Jeff Chilton used to implement
462# the WAV #49 GSM format.
463
464$(TLS)/ginger:	$(TLS)/ginger.o $(TLS)/taste.o
465		$(LD) $(LFLAGS) -o $(TLS)/ginger \
466			$(TLS)/ginger.o $(TLS)/taste.o $(LDLIB)
467
468$(TLS)/sour:	$(TLS)/sour.o $(TLS)/taste.o
469		$(LD) $(LFLAGS) -o $(TLS)/sour \
470			$(TLS)/sour.o $(TLS)/taste.o $(LDLIB)
471
472# Run $(ADDTST)/add < $(ADDTST)/add_test.dta to make sure the
473# basic arithmetic functions work as intended.
474
475$(ADDTST)/add:	$(ADDTST)/add_test.o
476		$(LD) $(LFLAGS) -o $(ADDTST)/add $(ADDTST)/add_test.o $(LDLIB)
477
478
479# Various conversion programs between linear, text, .gsm and the code
480# format used by the tests we ran (.cod).  We paid for the test data,
481# so I guess we can't just provide them with this package.  Still,
482# if you happen to have them lying around, here's the code.
483#
484# You can use gsm2cod | cod2txt independently to look at what's
485# coded inside the compressed frames, although this shouldn't be
486# hard to roll on your own using the gsm_print() function from
487# the API.
488
489
490$(TST)/test-result:	$(TST)/lin2cod $(TST)/cod2lin $(TOAST) $(TST)/run
491			( cd $(TST); ./run )
492
493$(TST)/lin2txt:		$(TST)/lin2txt.o $(LIBGSM)
494			$(LD) $(LFLAGS) -o $(TST)/lin2txt \
495				$(TST)/lin2txt.o $(LIBGSM) $(LDLIB)
496
497$(TST)/lin2cod:		$(TST)/lin2cod.o $(LIBGSM)
498			$(LD) $(LFLAGS) -o $(TST)/lin2cod \
499				$(TST)/lin2cod.o $(LIBGSM) $(LDLIB)
500
501$(TST)/gsm2cod:		$(TST)/gsm2cod.o $(LIBGSM)
502			$(LD) $(LFLAGS) -o $(TST)/gsm2cod \
503				$(TST)/gsm2cod.o $(LIBGSM) $(LDLIB)
504
505$(TST)/cod2txt:		$(TST)/cod2txt.o $(LIBGSM)
506			$(LD) $(LFLAGS) -o $(TST)/cod2txt \
507				$(TST)/cod2txt.o $(LIBGSM) $(LDLIB)
508
509$(TST)/cod2lin:		$(TST)/cod2lin.o $(LIBGSM)
510			$(LD) $(LFLAGS) -o $(TST)/cod2lin \
511				$(TST)/cod2lin.o $(LIBGSM) $(LDLIB)
512