# Makefile for LAME 3.xx on Elate / AmigaSDK
#
UNAME = $(shell uname)
ARCH = $(shell uname -m)


# defaults:
PGM = lame
CC = vpcc
SNDLIB = -DLAMESNDFILE
RM = rm -f
CPP_OPTS = -DLAMEPARSE


##########################################################################
# Define these to compile in code for the optional VBR bitrate histogram.  
# Requires ncurses, but libtermcap also works.  
# If you have any trouble, just dont define these
##########################################################################
#BRHIST_SWITCH = -DBRHIST
#LIBTERMCAP = -lncurses
#LIBTERMCAP = -ltermcap


##########################################################################
# SNDLIB =         no file i/o 
# SNDLIB = -DLAMESNDFILE  to use internal LAME soundfile routines
# SNDLIB = -DLIBSNDFILE   to use Erik de Castro Lopo's libsndfile 
# http://www.zip.com.au/~erikd/libsndfile/
# otherwise LAME can only read 16bit wav, aiff and pcm inputfiles.
# Note: at present, libsndfile does not support input from stdin.  
##########################################################################
#SNDLIB = -DLIBSNDFILE
#LIBSNDFILE=-lsndfile 
# if libsndfile is in a custom location, try:
#LIBSNDFILE=-L $(LIBSNDHOME) -lsndfile  -I $(LIBSNDHOME)


##########################################################################
# define these to use compile in support for the GTK mp3 frame analyzer
# Requires  -DHAVEMPGLIB
# and SNDLIB = -DLAME or -DLIBSNDFILE
##########################################################################
#GTK = -DHAVEGTK `gtk-config --cflags`
#GTKLIBS = `gtk-config --libs` 

# suggested for gcc-2.7.x
   CC_OPTS =  -fomit-frame-pointer -funroll-loops -ffast-math  -finline-functions -Wall
#  CC_OPTS =  -O9 -fomit-frame-pointer -fno-strength-reduce -mpentiumpro -ffast-math -finline-functions -funroll-loops -Wall -malign-double -g -march=pentiumpro -mfancy-math-387 -pipe 

#For debugging
#   CC_OPTS =  -UNDEBUG -O -Wall -g -DABORTFP 

#  for lots of debugging:
#   CC_OPTS =  -DDEBUG -UNDEBUG  -O -Wall -g -DABORTFP 



# The following features are experimental code, 
# so don't use them if you don't know exactly what you do! (RH 2000-01-30)
#   FEATURES  = -DRH_QUALITY_CONTROL  # tuned VBR quality control
#   FEATURES += -DRH_SIDE_VBR         # turns side channel reduction off (VBR)
#   FEATURES += -DRH_SIDE_CBR         # turns side channel reduction off (CBR)
#   FEATURES += -DRH_ATH              # max noise instead of average noise



CC_SWITCHES = -D__STRICT_ANSI__ -DNDEBUG -D__NO_MATH_INLINES $(CC_OPTS) $(SNDLIB) $(GTK) $(BRHIST_SWITCH)
c_sources = \
        brhist.c \
	formatBitstream.c \
	fft.c \
	get_audio.c \
	l3bitstream.c \
        id3tag.c \
	ieeefloat.c \
        lame.c \
        newmdct.c \
        parse.c \
	portableio.c \
	psymodel.c \
	quantize.c \
	quantize-pvt.c \
	vbrquantize.c \
	reservoir.c \
	tables.c \
	takehiro.c \
	timestatus.c \
	util.c \
        VbrTag.c \
        version.c \
        gtkanal.c \
        gpkplotting.c \
        mpglib/common.c \
        mpglib/dct64_i386.c \
        mpglib/decode_i386.c \
        mpglib/layer3.c \
        mpglib/tabinit.c \
        mpglib/interface.c \
        mpglib/main.c 

OBJ = $(c_sources:.c=.o)
DEP = $(c_sources:.c=.d)

SHELL = shell 

%.o: %.c 
	$(CC) $(CPP_OPTS) $(CC_SWITCHES) -c $< -o $@

##%.d: %.c
#	$(SHELL) -ec {$(CC) $(MAKEDEP)  $(CPP_OPTS) $(CC_SWITCHES)  $< | sed {\''s;$*.o;& $@;g'\'} > $@}

$(PGM): main.o $(OBJ)
#        $(CC) -o $(PGM)  main.o -L. -lmp3lame $(LIBS) $(LIBSNDFILE) $(GTKLIBS) $(LIBTERMCAP)

# Note: This requires gtk
#mp3x:	mp3x.o $(OBJ)
#	$(CC) -o mp3x mp3x.o  $(OBJ) $(LIBS) $(LIBSNDFILE) $(GTKLIBS) $(LIBTERMCAP)

# Note: I have not gotten this to work yet
#mp3rtp:	rtp.o mp3rtp.o $(OBJ)
#	$(CC) -o mp3rtp mp3rtp.o rtp.o   $(OBJ) $(LIBS) $(LIBSNDFILE) $(GTKLIBS) $(LIBTERMCAP)

clean:
	-$(RM) $(OBJ) $(DEP) $(PGM) main.o rtp.o mp3rtp mp3rtp.o \
         mp3x.o mp3x libmp3lame.a 


tags: TAGS

TAGS: ${c_sources}
	etags -T ${c_sources}

ifneq ($(MAKECMDGOALS),clean)
  -include $(DEP)
endif


#
#  testcase.mp3 is a 2926 byte file.  The first number output by
#  wc is the number of bytes which differ between new output
#  and 'official' results.  
#
#  Because of compilier options and effects of roundoff, the 
#  number of bytes which are different may not be zero, but
#  should be at most 30.
#
test: $(PGM)
	./lame  --nores -h testcase.wav testcase.new.mp3
	cmp -l testcase.new.mp3 testcase.mp3 | wc

testg: $(PGM)
	./lame -g -h ../test/castanets.wav
