#	Makefile.MSVC: MSVC Makefile for LAME 3.88
#
#	2000-11-21 Robert Hegemann  e-mail: Robert.Hegemann@gmx.de
#	dedicated to the LAME project http://www.mp3dev.org
###############################################################################



#__ readme ____________________________________________________________________
#	nmake -f Makefile.MSVC
#		-> build lame and dll, but not mp3x
#		-> use Robert's code modifications
#		-> assume INTEL compiler available  
#		-> assume NASM available
#		-> assemble MMX code with NASM
#		-> optimize for PIII
#		-> single file optimizations
#		-> no compiler warnings
#
#	passing arguments, one can modify the default behaviour:
#	COMP=<not INTEL or BCC>    ->  use MS compiler
#	WARN=<anything but OFF>    ->  give verbose compiler warnings
#	OPT=<NORMAL,EXTRA,ULTRA>   ->  different Intel optimizations
#	ASM=<anything but YES>     ->  no NASM nor MMX
#	MMX=<anything but YES>     ->  do not assemble MMX code
#	CFG=<anything but RH>      ->  disable Robert's modifications
#	OGG=<anything>             ->  have Vorbis library, use it
#	CPU=P1                     ->  optimize for Pentium instead of P II/III
#	GTK=YES                    ->  have GTK, adds mp3x to default targets
#
#	Example:
#	nmake -f Makefile.MSVC CPU=P1 GTK=YES
#____________________________________________________________________ readme __



#	targets <-> DOS filenames
T_LAME = lame.exe
T_LDLL = lame_enc.dll
T_MP3X = mp3x.exe

#	default targets
PGM = $(T_LDLL) $(T_LAME)

#	some default settings

!	IF "$(COMP)" == ""
COMP = INTEL
!	ENDIF

!	IF "$(ASM)" == ""
ASM = YES
!	ENDIF

!	IF "$(MMX)" == ""
MMX = YES
!	ENDIF

!	IF "$(CFG)" == "NO-ALTERNATE-CODE-AVAILABLE"
CFG = RH
!	ENDIF

!	IF "$(CPU)" == ""
CPU = P3
!	ENDIF

!	IF "$(OPT)" == ""
OPT = NORMAL
!	ENDIF

!	IF "$(WARN)" == ""
WARN = OFF
!	ENDIF



OFF = win32

!	MESSAGE ----------------------------------------------------------------------
!	MESSAGE building LAME featuring $(CFG)
!	IF "$(ASM)" == "YES"
!	MESSAGE + ASM
!	IF "$(MMX)" == "YES"
!	MESSAGE + MMX
!	ENDIF 
!	ENDIF 
!	IF "$(GTK)" == "YES"
!	MESSAGE + GTK
!	ENDIF 
!	IF "$(OGG)" != ""
!	MESSAGE + Ogg-Vorbis
!	ENDIF 
!	IF "$(COMP)" == "INTEL"
!	MESSAGE using INTEL COMPILER
!	IF "$(OPT)" == "NORMAL"
!	MESSAGE + perform single-file optimizations
!	ENDIF
!	IF "$(OPT)" == "EXTRA"
!	MESSAGE + perform multi-file optimizations
!	ENDIF
!	IF "$(OPT)" == "ULTRA"
!	MESSAGE + perform multi-file optimizations over entire program
!	ENDIF
!	ELSE
!	MESSAGE using MS COMPILER
!	ENDIF
!	IF "$(CPU)" == "P1"
!	MESSAGE + optimizing for Pentium (MMX) (may slow down PIII a few percent)
!	ELSE
!	MESSAGE + optimizing for Pentium II/III (slows down Pentium a few percent)
!	ENDIF
!	MESSAGE ----------------------------------------------------------------------



!	IF "$(COMP)" != "INTEL"
!	IF "$(COMP)" != "BCC"

#__ Microsoft C options _______________________________________________________
#
#	/O2     maximize speed
#	/Ob<n>  inline expansion
#	/Og     enable global optimizations
#	/Oi     enable intrinsic functions
#	/Ot     favor code speed
#	/Oy     enable frame pointer omission
#	/G5     Pentium optimization
#	/G6     Pentium II/III optimization
#	/GA     optimize for Windows Application
#	/GF     enable read-only string pooling
#	/Gf     enable string spooling
#	/Gs     disable stack checking calls
#	/Gy     separate functions for linker
#	/QIfdiv generate code for Pentium FDIV fix
#	/QI0f   generate code for Pentium 0x0f erratum fix
#
#	remarks: 
#	 - aliasing options seem to break code
#	 - try to get the Intel compiler demonstration code!
#	   ICL produces faster code.

# debugging options
# CC_OPTS = /nologo /Zi /Ge /GZ
# LN_OPTS = /nologo /debug:full /debugtype:cv /fixed:no

# profiling options
# CC_OPTS = /nologo /Zi /O2b2gity /G6As /DNDEBUG 
# LN_OPTS = /nologo /debug:full /debugtype:cv /fixed:no /profile

# release options
CC_OPTS = /nologo /DNDEBUG /O2 /Ob2 /GAy /Gs1024 /QIfdiv /QI0f /YX
LN_OPTS = /nologo /DNDEBUG

!	IF "$(CPU)" == "P1"
CC_OPTS = $(CC_OPTS) /G5
!	ELSE
CC_OPTS = $(CC_OPTS) /GX
!	ENDIF

!	IF "$(WARN)" == "OFF"
CC_OPTS = $(CC_OPTS) /w
!	ELSE
CC_OPTS = $(CC_OPTS) /W2 /Wport
!	ENDIF

LN_DLL = /LD
LN_OUT = /Fe
CC_OUT = /Fo

CC = cl
LN = cl
#_______________________________________________________ Microsoft C options __


!	ELSE

#__ Borland BCC options _______________________________________________________
#
#	first draft, DLL not working, generates very slow code!
BCCINST = C:/Borland/BCC55

CC_OPTS = -pc -q -ff -fp -jb -j1 -tWC -tWM -O2 -OS -I$(BCCINST)/include -DNDEBUG -DWIN32
# dll >> -tWD
LN_OPTS = -lGn -lGi -lap -lx -L$(BCCINST)/lib
# dll >> -Tpd
!	IF "$(CPU)" == "P1"
CC_OPTS = $(CC_OPTS) -5
!	ELSE
CC_OPTS = $(CC_OPTS) -6
!	ENDIF

!	IF "$(WARN)" == "OFF"
CC_OPTS = $(CC_OPTS) -w-
!	ELSE
CC_OPTS = $(CC_OPTS) 
!	ENDIF

LN_DLL = 
#$(CCINST)/lib/cw32R.lib
LN_OUT = -e
CC_OUT = -o

CC = bcc32
LN = bcc32

OFF = obj
PGM = $(T_LAME)

!	ENDIF
#_______________________________________________________ Borland BCC options __


!	ELSE

#__ Intel 4.5 options _________________________________________________________
#
#	/YX         enable automatic precompiled header file creation/usage
#	/Ox         maximum optimization same as /O2 without /Gfy
#	/O2         same as /Gfsy /Ob1gyti
#	/Gd      1) make cdecl the default calling convention
#	/G5      2) optimized for Pentium
#	/G6      3) optimized for Pentium II/III
#	/GA         assume single threaded
#	/Gs[n]      disable stack checks for functions with <n bytes of locals
#	/GF         read-only string pooling optimization
#	/Gy         separate functions for the linker 
#	/Qunroll    unroll loops with default heuristic
#	/QIfist     enable fast float to int conversion
#	/QIfdiv     enable patch for Pentium with FDIV erratum
#	/QI0f       enable patch for Pentium with 0f erratum
#	/Qip     2) enable single-file IP optimizations (within files)
#	/Qipo       enable multi-file IP optimizations (between files)
#	/Qipo_wp 4) enable entire program multi-file IP optimizations
#	/QaxiMK     automatic use of specialized code for PII/III, MMX, SIMD
#
#	remarks: 
#	1) slows speed down, not using
#	2) faster compared to 3) or 4) on Pentium MMX at 200 MHz

!	IF "$(CPU)" == "P1"
CC_OPTS = /G5 /QaxiMK
!	ELSE
CC_OPTS = /G6 /Qaxi
!	ENDIF

!	IF "$(OPT)" == "NORMAL"
CC_OPTS = $(CC_OPTS) /Qip
!	ELSE
!	IF "$(OPT)" == "EXTRA"
#	resulting exe seems to be not faster than with NORMAL
CC_OPTS = $(CC_OPTS) /Qip /Qipo
!	ELSE
!	IF "$(OPT)" == "ULTRA"
#	resulting exe seems to be not faster than with NORMAL
CC_OPTS = $(CC_OPTS) /Qip /Qipo_wp
!	ENDIF
!	ENDIF
!	ENDIF

!	IF "$(WARN)" == "OFF"
CC_OPTS = $(CC_OPTS) /w
!	ELSE
CC_OPTS = $(CC_OPTS) /W2 /Wport
!	ENDIF

CC_OPTS = /nologo /DNDEBUG /YX /GA /O2 /Gs1024 \
          /Qunroll /Qsox- /QIfist /QIfdiv /QI0f $(CC_OPTS) /DFLOAT8=float

LN_OPTS = $(CC_OPTS)
LN_DLL = /LD
LN_OUT = /Fe
CC_OUT = /Fo

CC = icl
LN = icl
#_________________________________________________________ Intel 4.5 options __

!	ENDIF



#-- MISC --
SNDLIB = /DLAMESNDFILE
LIBSNDFILE =

BRHIST_SWITCH = /DBRHIST
TIMER_SWITCH =

CPP_OPTS = /DHAVE_CONFIG_H -I.



#__ FRAME ANALYZER SUPPORT ____________________________________________________
#
#	Assuming you have "glib-dev" and "gtk+-dev" installed and the system
#	DLLs "glib-1.3.dll", "gdk-1.3.dll" and "gtk-1.3.dll" copied into the
#	"Win\System" folder
#
#	To compile in the frame analyzer support, you need the above mentioned
#	libraries. You can pass the appropriate path to them in GTK_DIRS.
#
!	IF "$(GTK)" == "YES"
!	IF "$(GTK_DIRS)" == ""
GTK_DIRS = ../src
!	ENDIF
GTK_OPTS = -I$(GTK_DIRS)/glib     \
           -I$(GTK_DIRS)/gtk+     \
           -I$(GTK_DIRS)/gtk+/gtk \
           -I$(GTK_DIRS)/gtk+/gdk
GTK_LIBS = $(GTK_DIRS)/gtk+/gtk/gtk-1.3.lib \
           $(GTK_DIRS)/gtk+/gdk/gdk-1.3.lib \
           $(GTK_DIRS)/glib/glib-1.3.lib

PGM = $(T_MP3X) $(PGM)
!	ELSE
!	IF "$(GTK)" == ""
!	MESSAGE Pass GTK=YES to build the frame analyzer. (requires installed GTK)
!	ENDIF
!	ENDIF
#____________________________________________________ FRAME ANALYZER SUPPORT __



#__ VORBIS SUPPORT ____________________________________________________________
!	IF "$(OGG)" != ""
VORBIS = /DHAVE_VORBIS -I../vorbis/include
VORBISLIB = ../vorbis/lib/vorbis.lib
!	ENDIF
#____________________________________________________________ VORBIS SUPPORT __



#__ MPG123 DECODING ___________________________________________________________
#
#	uncomment the following if you want decoding support
#	It's always a good idea to compile it in!
#
CPP_OPTS = $(CPP_OPTS) /DHAVE_MPGLIB /DUSE_LAYER_1 /DUSE_LAYER_2
#___________________________________________________________ MPG123 DECODING __



#__ Takehiro's IEEE hack ______________________________________________________
#
#	uncomment the following to enable Takehiro's IEEE hack
#	You'll want it on a x86 machine with i387 FPU
#
CPP_OPTS = $(CPP_OPTS) /DTAKEHIRO_IEEE754_HACK
#______________________________________________________ Takehiro's IEEE hack __



#__ Robert's alternate code ___________________________________________________
!	IF "$(CFG)" == "RH"
CPP_OPTS = $(CPP_OPTS) 
!MESSAGE there is currently no alternate code by RH
!	ENDIF
#___________________________________________________ Robert's alternate code __



CC_SWITCHES = $(CC_OPTS) $(SNDLIB) $(VORBIS) $(BRHIST_SWITCH) \
              $(TIMER_SWITCH) $(GTK_OPTS) /DBS_FORMAT=BINARY

LN_SWITCHES = $(LN_OPTS)

lame_sources = \
	frontend/main.c

mpx_sources = \
	frontend/gpkplotting.c \
	frontend/gtkanal.c \
	frontend/mp3x.c

dll_sources = \
	dll/BladeMP3EncDll.c

common_sources = \
	frontend/portableio.c \
	frontend/get_audio.c \
	frontend/parse.c \
	frontend/timestatus.c \
	frontend/lametime.c \
	frontend/brhist.c

lamelib_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_sources = \
	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



LIB_OBJ = $(lamelib_sources:.c=.obj)
MPG_OBJ = $(mpglib_sources:.c=.obj)
CMMN_OBJ = $(common_sources:.c=.obj)
LAME_OBJ = $(lame_sources:.c=.obj)
MPX_OBJ = $(mpx_sources:.c=.obj)
DLL_OBJ = $(dll_sources:.c=.obj)

.c.obj: 
	@$(CC) $(CPP_OPTS) $(CC_SWITCHES) -Iinclude -Ilibmp3lame -Impglib \
	       $(CC_OUT)$@  -c $<

#__ NASM ______________________________________________________________________
#
#	NASM: Netwide Assembler
#
!	IF "$(ASM)" == "YES"
.SUFFIXES : .nas
.nas.obj:
	@echo $< 
	@nasmw -f $(OFF) -i libmp3lame/i386/ -DWIN32 $< -o $@
                                
CC_SWITCHES = $(CC_SWITCHES) /DHAVE_NASM
ASM_OBJ = $(ASM_OBJ) libmp3lame/i386/cpu_feat.obj libmp3lame/i386/scalar.obj


ASM_OBJ = $(ASM_OBJ) libmp3lame/i386/fft3dn.obj

#	not yet coded
#CC_SWITCHES = $(CC_SWITCHES) /DUSE_FFTSSE
#ASM_OBJ = $(ASM_OBJ) libmp3lame/i386/fftsse.obj

#CC_SWITCHES = $(CC_SWITCHES) /DUSE_FFTFPU
#ASM_OBJ = $(ASM_OBJ) libmp3lame/i386/fftfpu.obj
!	ENDIF
#______________________________________________________________________ NASM __



#__ MMX _______________________________________________________________________
#
#	you need NASM but *not necessarily* a processor with MMX
#	The above CPU feature detection code allows to run the same
#	binary on a CPU without MMX too!
#
!	IF "$(ASM)" == "YES"
!	IF "$(MMX)" == "YES"
CC_SWITCHES = $(CC_SWITCHES) /DMMX_choose_table
ASM_OBJ = $(ASM_OBJ) libmp3lame/i386/choose_table.obj
!	ENDIF
!	ENDIF
#_______________________________________________________________________ MMX __

!	MESSAGE



all :	$(PGM)
	@echo.
	@echo --=*  $(PGM) uptodate  *=--
	@echo.

common:	$(CMMN_OBJ)
	@echo.
	@echo --- COMMON FRONTEND STUFF UPTODATE ---
	@echo.

libA:	$(LIB_OBJ)
	@echo.
	@echo --- LAME MP3 ENCODING LIBRARY UPTODATE ---
	@echo.

libB:	$(MPG_OBJ)
	@echo.
	@echo --- MPG123 DECODING LIBRARY UPTODATE ---
	@echo.

lib: $(ASM_OBJ) libA libB

$(T_LAME) : config.h lib common $(LAME_OBJ)
	@$(LN) $(LN_OUT)$@ $(LN_SWITCHES) $(LIBSNDFILE) $(VORBISLIB) \
	       $(ASM_OBJ) $(LIB_OBJ) $(MPG_OBJ) $(CMMN_OBJ) $(LAME_OBJ)
	@echo.
	@echo --=*  $@ ready  *=--
	@echo.

$(T_MP3X) : config.h lib common $(MPX_OBJ)
	@$(LN) $(LN_OUT)$@ $(LN_SWITCHES) $(GTK_LIBS) $(LIBSNDFILE) $(VORBISLIB) \
	       $(ASM_OBJ) $(LIB_OBJ) $(MPG_OBJ) $(CMMN_OBJ) $(MPX_OBJ)
	@echo.
	@echo --=*  $@ ready  *=--
	@echo.

$(T_LDLL) : config.h lib $(DLL_OBJ)
	@$(LN) $(LN_OUT)$@ $(LN_SWITCHES) $(LN_DLL) $(LIBSNDFILE) $(VORBISLIB) \
	       $(ASM_OBJ) $(LIB_OBJ) $(MPG_OBJ) $(DLL_OBJ)
	@echo.
	@echo --=*  $@ ready  *=--
	@echo.

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

clean:
	@-del *.exe
	@-del icl.pch
	@-del lame_enc.*
	@-del frontend\*.obj
	@-del dll\*.obj
	@-del mpglib\*.obj
	@-del libmp3lame\*.obj
	@-del libmp3lame\i386\*.obj


rebuild: clean all


lame	:	$(T_LAME)
dll 	:	$(T_LDLL)
mp3x	:	$(T_MP3X)

