# Makefile for LAME 3.xx using Borlands free C++ compiler.
#
# Based on the original LAME makefile.
#

##########################################################################
# Windows, Borland C++
##########################################################################

HAVE_NASM=YES
NASM = @-nasmw
ASFLAGS=-DWIN32 -f obj -i libmp3lame/i386/


PGM = lame.exe
CC = @-bcc32
CC_OPTS = -q -fp -ff -w- -5 -O2 -OS -I. -Iinclude -Ilibmp3lame -Impglib -DNDEBUG
LIBS =
MAKEDEP =
RM = del

GTK = 
GTKLIBS = 
SNDLIB = -DLAMESNDFILE
LIBSNDFILE =  
MP3LIB = libmp3lame/libmp3lame.lib


##########################################################################
# -DHAVEMPGLIB compiles the mpglib *decoding* library into libmp3lame
##########################################################################
CPP_OPTS = $(CPP_OPTS) -DHAVE_MPGLIB 


##########################################################################
# Define these in the OS specific sections below to compile in code for
# the GTK mp3 frame analyzer
#
# Requires  -DHAVE_MPGLIB
# and SNDLIB = -DLAME or -DLIBSNDFILE
#
# GTK = -DHAVE_GTK `gtk-config --cflags`
# GTKLIBS = `gtk-config --libs` 
#
##########################################################################




# uncomment to use LIBSNDFILE
# SNDLIB = -DLIBSNDFILE
# LIBSNDHOME = ../libsndfile/src/
# LIBSNDFILE= -L $(LIBSNDHOME) sndfile.lib -I $(LIBSNDHOME)

# uncomment to compile in Vorbis support
# VORBIS = -DHAVE_VORBIS -I ../vorbis/include
# VORBIS_LIB = -L ../vorbis/lib vorbis.lib

# for debugging:
# CC_OPTS = $(CC_OPTS) -UNDEBUG


CC_SWITCHES = -DHAVE_CONFIG_H -DNDEBUG $(CC_OPTS) $(SNDLIB) $(GTK) $(BRHIST_SWITCH) $(VORBIS) 
frontend_sources = \
	frontend/amiga_mpega.c \
	frontend/brhist.c \
	frontend/get_audio.c \
	frontend/lametime.c \
	frontend/parse.c \
	frontend/portableio.c \
	frontend/timestatus.c 

lib_sources = \
	libmp3lame/bitstream.c \
	libmp3lame/encoder.c \
	libmp3lame/fft.c \
	libmp3lame/id3tag.c \
	libmp3lame/lame.c \
	libmp3lame/newmdct.c \
	libmp3lame/psymodel.c \
	libmp3lame/quantize.c \
	libmp3lame/quantize_pvt.c \
	libmp3lame/set_get.c \
	libmp3lame/vbrquantize.c \
	libmp3lame/reservoir.c \
	libmp3lame/tables.c \
	libmp3lame/takehiro.c \
	libmp3lame/util.c \
	libmp3lame/vorbis_interface.c \
	libmp3lame/mpglib_interface.c \
	libmp3lame/VbrTag.c \
	libmp3lame/version.c \
	mpglib/common.c \
	mpglib/dct64_i386.c \
	mpglib/decode_i386.c \
	mpglib/layer1.c \
	mpglib/layer2.c \
	mpglib/layer3.c \
	mpglib/tabinit.c \
	mpglib/interface.c 


gtk_sources = frontend/gtkanal.c frontend/gpkplotting.c

gtk_obj = $(gtk_sources:.c=.obj)
frontend_obj = $(frontend_sources:.c=.obj)
lib_obj = $(lib_sources:.c=.obj)

!ifdef NASM
CC_SWITCHES = $(CC_SWITCHES) -DHAVE_NASM -DMMX_choose_table

lib_obj = $(lib_obj) libmp3lame/i386/cpu_feat.obj \
	libmp3lame/i386/scalar.obj \
	libmp3lame/i386/choose_table.obj \
	libmp3lame/i386/fft3dn.obj \
#	libmp3lame/i386/fftsse.obj \
#	libmp3lame/i386/fftfpu.obj 

!endif


.SUFFIXES : .nas

.nas.obj:
	$(NASM) $(ASFLAGS) $< -o $@

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

all: $(PGM)

$(lib_sources) $(frontend_sources) : config.h

config.h: configMS.h
	-copy configMS.h config.h

$(PGM):	$(MP3LIB) $(frontend_obj) frontend/main.obj
	$(CC) -e$@ $(CC_OPTS) frontend/main.obj  $(frontend_obj) $(MP3LIB) $(LIBS) $(LIBSNDFILE) $(GTKLIBS) $(LIBTERMCAP) $(VORBIS_LIB)

mp3x:	 $(MP3LIB) $(gtk_obj) $(frontend_obj) frontend/mp3x.o
	$(CC) -e$@ $(CC_OPTS) frontend/mp3x.obj $(frontend_obj) $(gtk_obj) $(MP3LIB) $(LIBS) $(LIBSNDFILE) $(GTKLIBS) $(LIBTERMCAP) $(VORBIS_LIB)

mp3rtp:	frontend/rtp.obj frontend/mp3rtp.obj $(MP3LIB)
	$(CC) -e$@ $(CC_OPTS) frontend/mp3rtp.obj frontend/rtp.o $(frontend_obj) $(MP3LIB) $(LIBS) $(LIBSNDFILE) $(GTKLIBS) $(LIBTERMCAP) $(VORBIS_LIB)

libmp3lame/libmp3lame.lib: $(lib_obj)
	-del $(@:/=\)
	tlib /a $(@:/=\) $(lib_obj:/=\)

Dll/lame_enc.dll: Dll/BladeMP3EncDLL.obj $(MP3LIB)
	$(CC) -e$@ -WD $(CC_OPTS) Dll/BladeMP3EncDLL.obj $(MP3LIB) $(LIBS) $(LIBSNDFILE) $(VORBIS_LIB)

clean:
	-del *.obj
	-del *.lib
	-del i386\*.obj
	-del libmp3lame\*.obj
	-del libmp3lame\i386\*.obj
	-del mpglib\*.obj
	-del frontend\*.obj
	-del $(PGM)
	-del Dll\*.obj

#
#  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 testcase.new.mp3 testcase.mp3

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