# Makefile for LAME 3.xx using DJGPP (DJ Delorie's DOS port of GCC)
# based on the original lame makefile
#
# Hints:
#
# To compile, use: make -f Makefile.djgpp
#
# Make sure that you have the DJGPP make utility installed (get it from where you got DJGPP)
#
# Use UPX to compress the exe to less half the original size.
#
## Some of the changes (things that don't work with DOS/DJGPP)
## removed VBR histogram capability
## removed references to GTK 
## removed references to rtp
## make clean is a hack because the dos prompt doesn't like really long command lines
## removed -pipe from CC_OPTS

# generic defaults. OS specific options go in versious sections below
PGM = lame
CC = gcc
CC_OPTS =  -O
SNDLIB = -DLAMESNDFILE
LIBSNDFILE =  
LIBS = -lm 
MAKEDEP = -M


##########################################################################
# -DHAVEMPGLIB compiles the mpglib *decoding* library into libmp3lame
##########################################################################
CPP_OPTS += -DHAVEMPGLIB 

##########################################################################
# -DUSE_LAYER_1/2 enables Layer1 or Layer2 *decoding* abilities 
##########################################################################
CPP_OPTS += -DUSE_LAYER_1 -DUSE_LAYER_2


##########################################################################
# Define these in the OS specific sections below to compile in support
# for the Ogg Vorbis audio format (both decoding and encoding)
# 
# VORBIS = -DHAVEVORBIS  -I ../vorbis/include
# VORBIS_LIB = -L ../vorbis/lib -lvorbis
##########################################################################


##########################################################################
# Define these in the section below to compile in code for:
#
# 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/
#
# Note: at present, libsndfile does not support input from stdin.  
#
# for example:
#  SNDLIB = -DLIBSNDFILE
#  LIBSNDFILE=-lsndfile 
#  if sndfile.lib is in a custom location, try:
#  LIBSNDFILE=-L $(LIBSNDHOME) -lsndfile  -I $(LIBSNDHOME)
##########################################################################


##########################################################################
# DJGPP   
##########################################################################

# Generic, safe options:
CC_OPTS = -O2

# other possibilities:
#CC_OPTS = -s  -O3 -fomit-frame-pointer -funroll-loops -ffast-math  -finline-functions -Wall

#CC_OPTS =  -s -O9 -fomit-frame-pointer -fno-strength-reduce -mpentiumpro -ffast-math -finline-functions -funroll-loops -Wall -malign-double -g -march=pentiumpro -mfancy-math-387

#CC_OPTS = -s -O2 -march=i686 -fomit-frame-pointer -ffast-math -funroll-loops  -funroll-all-loops -malign-double -fstrict-aliasing 

#CC_OPTS = -s -Wall -O9 -fomit-frame-pointer -march=pentiumpro -finline-functions -fexpensive-optimizations -funroll-loops -funroll-all-loops -fschedule-insns2 -fstrength-reduce -malign-double -mfancy-math-387 -ffast-math 

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






# 10/99 added -D__NO_MATH_INLINES to fix a bug in *all* versions of
# gcc 2.8+ as of 10/99.  

CC_SWITCHES = -DNDEBUG -D__NO_MATH_INLINES $(CC_OPTS) $(SNDLIB)  \
$(VORBIS) 
c_sources = \
	brhist.c \
	bitstream.c \
	encoder.c \
	fft.c \
	get_audio.c \
	id3tag.c \
	ieeefloat.c \
	lame.c \
	lametime.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 \
	vorbis_interface.c \
	VbrTag.c \
	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 \
	mpglib/main.c 

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


NASM = nasm
ASFLAGS=-f elf -i i386/
%.o: %.nas
	$(NASM) $(ASFLAGS) $< -o $@
%.o: %.s
	gcc -c $< -o $@

## use MMX extension. you need nasm and MMX supported CPU.
#CC_SWITCCH += -DMMX_choose_table
#OBJ += i386/choose_table.o

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

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

all: $(PGM)

$(PGM):	main.o $(OBJ)
	$(CC) $(CC_OPTS) -o $(PGM)  main.o  $(OBJ) $(LIBS) $(LIBSNDFILE) $(VORBIS_LIB)

libmp3lame.a:  $(OBJ) Makefile
#	cd libmp3lame
#	make libmp3lame
	ar cr libmp3lame.a  $(OBJ) 

clean:
	del *.o 
	del mpglib\*.o 
	del lame.exe
	del libmp3lame.a 


#
#  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
