# 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 -Iinclude -I. -Impglib -Ilibmp3lame -Ifrontend
SNDLIB = -DLAMESNDFILE
LIBSNDFILE =  
LIBS = -lm 
MAKEDEP = -M
MP3LIB = libmp3lame/libmp3lame.a
CPP_OPTS = -Ianalyzer -Iinclude -Impglib -Ifrontend -Ilibmp3lame -I.

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

##########################################################################
# -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 = -DHAVE_CONFIG_H -DNDEBUG -D__NO_MATH_INLINES $(CC_OPTS) $(SNDLIB)  \
$(VORBIS) 
frontend_sources = \
	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 


DEP = $(lib_sources:.c=.d) $(frontend_sources:.c=.d)

frontend_obj = $(frontend_sources:.c=.o)
lib_obj = $(lib_sources:.c=.o)



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

#HAVE_NASM = YES

ifeq ($(HAVE_NASM),YES)
## have NASM
CC_SWITCHES += -DHAVE_NASM
lib_obj += libmp3lame/i386/cpu_feat.o libmp3lame/i386/scalar.o

## use MMX extension. you need nasm and MMX supported CPU.
CC_SWITCHES += -DMMX_choose_table
lib_obj += libmp3lame/i386/choose_table.o
endif


%.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)

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

config.h: configMS.h
	cp configMS.h config.h

$(PGM): frontend/main.o $(frontend_obj) $(MP3LIB)
	$(CC) $(CC_OPTS) -o frontend/$(PGM)  frontend/main.o  $(frontend_obj) \
	$(MP3LIB) $(LIBS) $(LIBSNDFILE) $(VORBIS_LIB)

libmp3lame/libmp3lame.a:  $(lib_obj) 
#       cd libmp3lame
#       make libmp3lame
	ar cr libmp3lame/libmp3lame.a  $(lib_obj) 

clean:
	del frontend\*.o 
	del frontend\*.d 
	del frontend\*.exe 
	del mpglib\*.o 
	del mpglib\*.d 
	del libmp3lame\*.o      
	del libmp3lame\*.d      
	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 -l

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