# Generated automatically from Makefile.in by configure.
#
# Makefile.in for LAME 3.xx
#
# processed by ./configure to produce Makefile
#
#
# these variables are available on command line:
#
#   make UNAME=xxxxx ARCH=xxxxx   - specify a type of host
#   make PGM=lame_exp             - specify a name of an executable file
#
#
SHELL = /bin/sh


UNAME = $(shell uname)
ARCH = $(shell uname -m)


prefix = /usr
exec_prefix = ${prefix}

BINDIR = ${exec_prefix}/bin
LIBDIR = $(prefix)/lib
INCLUDEDIR = $(prefix)/include
CC     = gcc
CFLAGS = -DBRHIST -DHAVEGTK -I/usr/lib/glib/include -I/usr/X11R6/include -DUSE_LAYER_2 -DUSE_LAYER_1 -DHAVEMPGLIB -DLAMESNDFILE  -fPIC
LIBS   = -lm -lncurses -L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXext -lX11 -lm 
LDFLAGS= 
INSTALL= /usr/bin/install -c
INSTALL_PROGRAM=${INSTALL}
INSTALL_DATA=${INSTALL} -m 644
INSTALL_SCRIPT = ${INSTALL_PROGRAM}

SHARED_LIB = libmp3lame.so
SHARED_LIB_MAJOR = $(SHARED_LIB).1
SHARED_LIB_MINOR = $(SHARED_LIB_MAJOR).0

# generic defaults. OS specific options go in versious sections below
PGM ?= lame
CPP_OPTS = 
CC_OPTS = -O
AR = ar
RANLIB = ranlib
MAKEDEP = -M
RM_F = rm -f
LN_S = ln -s

##########################################################################
# -DHAVEMPGLIB compiles the mpglib *decoding* library into libmp3lame
##########################################################################
# handled by configure

##########################################################################
# -DUSE_LAYER_1/2 enables Layer1 or Layer2 *decoding* abilities 
##########################################################################
# hadled by configure


##########################################################################
#
# ** handled by configure **
# 
# Define these in the OS specific sections below to compile in support
# for the Ogg Vorbis audio format (both decoding and encoding)
# http://www.xiph.org/ogg/vorbis/
#
# VORBIS = -DHAVEVORBIS  -I ../vorbis/include
# VORBIS_LIB = -L ../vorbis/lib -lvorbis
##########################################################################

##########################################################################
#
# ** handled by configure **
# 
# Define these in the OS specific sections below 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
#
# or, to try and simulate TERMCAP (ANSI), use:
# BRHIST_SWITCH = -DBRHIST -DNOTERMCAP
#
##########################################################################


##########################################################################
#
# ** handled by configure **
# 
# Define these in the OS specific sections 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 libsndfile is in a custom location, try:
#  LIBSNDFILE=-L $(LIBSNDHOME) -lsndfile  -I $(LIBSNDHOME)
##########################################################################


##########################################################################
#
# ** handled by configure **
# 
# Define these in the OS specific sections below to compile in code for
# the GTK mp3 frame analyzer
#
# Requires  -DHAVEMPGLIB
# and SNDLIB = -DLAME or -DLIBSNDFILE
#
# GTK = -DHAVEGTK `gtk-config --cflags`
# GTKLIBS = `gtk-config --libs` 
#
##########################################################################




##########################################################################
# LINUX   
##########################################################################
ifeq ($(UNAME),Linux)

# suggested for gcc-2.7.x
   CC_OPTS =  -O3 -fomit-frame-pointer -funroll-loops -ffast-math  -finline-functions -Wall -pedantic
#  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 -pedantic

#  for debugging:
#  CC_OPTS =  -UNDEBUG -O -Wall -pedantic -ggdb -DABORTFP

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


#  some alternate code (work in progress Robert.Hegemann@gmx.de)
#  CPP_OPTS += -DRH_AMP -DRH_VALIDATE_MS
# these options for gcc-2.95.2 to produce fast code
#   CC_OPTS = \
#	-Wall -O9 -fomit-frame-pointer -march=pentium \
#	-finline-functions -fexpensive-optimizations \
#	-funroll-loops -funroll-all-loops -pipe -fschedule-insns2 \
#	-fstrength-reduce \
#	-malign-double -mfancy-math-387 -ffast-math 


##########################################################################
# LINUX on Digital/Compaq Alpha CPUs
##########################################################################
ifeq ($(ARCH),alpha)

################################################################
#### Check if 'ccc' is in our path
####   if not, use 'gcc'
################################################################
ifeq ($(shell which ccc 2>/dev/null | grep -c ccc),0)

# double is faster than float on Alpha
CC_OPTS =       -O4 -pedantic -Wall -fomit-frame-pointer -ffast-math -funroll-loops \
                -mfp-regs -fschedule-insns -fschedule-insns2 \
                -finline-functions \
#                -DFLOAT=double
# add "-mcpu=21164a -Wa,-m21164a" to optimize for 21164a (ev56) CPU

################################################################
#### else, use 'ccc'
################################################################
else

# Compaq's C Compiler
CC = ccc

################################################################
#### set 'CC_OPTS = -arch host -tune host' to generate/tune instructions for this machine
####     'CC_OPTS += -migrate -fast -inline speed -unroll 0' tweak to run as fast as possible :)
####     'CC_OPTS += -w0 -pedantic -Wall' set warning and linking flags
################################################################
CC_OPTS = -arch host -tune host
CC_OPTS += -migrate -fast -inline speed -unroll 0
CC_OPTS += -w0 -pedantic -Wall


################################################################
#### to debug, uncomment
################################################################
# For Debugging
#CC_OPTS += -g3

################################################################
#### define __DECALPHA__ (i was getting re-declaration warnings
####   in machine.h
################################################################
# Define DEC Alpha
CPP_OPTS += -D__DECALPHA__

# standard Linux libm
#LIBS	=	-lm
# optimized libffm (free fast math library)
#LIBS	=	-lffm
# Compaq's fast math library
LIBS    +=       -lcpml
endif  #  gcc or ccc?
endif  #  alpha 
endif  #  linux



##########################################################################
# FreeBSD
##########################################################################
ifeq ($(UNAME),FreeBSD)
  # nothing left...
endif


##########################################################################
# OpenBSD
##########################################################################
ifeq ($(UNAME),OpenBSD)
  # nothing left...
endif



##########################################################################
# SunOS
##########################################################################
ifeq ($(UNAME),SunOS) 
   CC = cc
   CC_OPTS = -O -xCC  	
   MAKEDEP = -xM
# for gcc, use instead:
#   CC = gcc 
#   CC_OPTS = -O 
#   MAKEDEP = -M 
endif


##########################################################################
# SGI
##########################################################################
ifeq ($(UNAME),IRIX64) 
   CC = cc
   CC_OPTS = -O3 -woff all 

endif

ifeq ($(UNAME),IRIX) 
   CC = cc
   CC_OPTS = -O3 -woff all 
endif



##########################################################################
# Compaq Alpha running Dec Unix (OSF)
##########################################################################
ifeq ($(UNAME),OSF1)
   CC = cc
   CC_OPTS = -fast -O3 -std -g3 -non_shared
endif

##########################################################################
# BeOS
##########################################################################
ifeq ($(UNAME),BeOS)
   CC = $(BE_C_COMPILER)
   LIBS =
ifeq ($(ARCH),BePC)
   CC_OPTS = -O9 -fomit-frame-pointer -march=pentium \
   -mcpu=pentium -ffast-math -funroll-loops \
   -fprofile-arcs -fbranch-probabilities
else
   CC_OPTS = -opt all
   MAKEDEP = -make
endif
endif

###########################################################################
# MOSXS (Rhapsody PPC)
###########################################################################
ifeq ($(UNAME),Rhapsody)
   CC = cc
   LIBS =
   CC_OPTS = -O9 -ffast-math -funroll-loops -fomit-frame-pointer
   MAKEDEP = -make 
endif

##########################################################################
# OS/2
##########################################################################
# Properly installed EMX runtime & development package is a prerequisite.
# tools I used: make 3.76.1, uname 1.12, sed 2.05, PD-ksh 5.2.13
#
##########################################################################
ifeq ($(UNAME),OS/2)
   SHELL=sh	
   CC = gcc
   CC_OPTS = -O3
   PGM ?= lame.exe
   LIBS =

# I use the following for slightly better performance on my Pentium-II
# using pgcc-2.91.66:
#   CC_OPTS = -O6 -ffast-math -funroll-loops -mpentiumpro -march=pentiumpro

# Uncomment & inspect the 2 GTK lines to use MP3x GTK frame analyzer.
# Properly installed XFree86/devlibs & GTK+ is a prerequisite.
# The following works for me using Xfree86/OS2 3.3.5 and GTK+ 1.2.3:
#   LIBS += -DHAVEGTK -IC:/XFree86/include/gtk12 -Zmt -D__ST_MT_ERRNO__ -IC:/XFree86/include/glib12 -IC:/XFree86/include
#   CFLAGS += -LC:/XFree86/lib -Zmtd -Zsysv-signals -Zbin-files -lgtk12 -lgdk12 -lgmodule -lglib12 -lXext -lX11 -lshm -lbsd -lsocket -lm
endif

###########################################################################
# MSDOS/Windows
###########################################################################
ifeq ($(UNAME),MSDOS)
  RM_F =
  PGM ?= lame.exe
endif

###########################################################################
# AmigaOS
###########################################################################
# Type 'Make ARCH=PPC' for PowerUP and 'Make ARCH=WOS' for WarpOS
#
###########################################################################
ifeq ($(UNAME),AmigaOS)
	CC = gcc -noixemul
	CC_OPTS = -O3 -ffast-math -funroll-loops -m68020-60 -m68881
	MAKEDEP = -MM
	ifeq ($(ARCH),WOS)
		CC = ppc-amigaos-gcc -warpup
		CC_OPTS = -O3 -ffast-math -fomit-frame-pointer -funroll-loops \
		-mmultiple -mcpu=603e
		AR = ppc-amigaos-ar
		RANLIB = ppc-amigaos-ranlib
		LIBS =
	endif
	ifeq ($(ARCH),PPC)
		CC = ppc-amigaos-gcc
		CC_OPTS = -O3 -ffast-math -fomit-frame-pointer -funroll-loops \
		-mmultiple -mcpu=603e
		AR = ppc-amigaos-ar
		RANLIB = ppc-amigaos-ranlib
		LIBS =
	endif
endif















# ** handled by configure **
# 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 $(CC_OPTS) $(CFLAGS) $(LDFLAGS)

gtk_sources = gtkanal.c gpkplotting.c
gtk_obj = $(gtk_sources:.c=.o)

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 \
        mpglib/main.c 

brhist_sources = brhist.c

c_sources_s =  $(gtk_sources) $(mpglib_sources) $(brhist_sources) \
	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

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

ifeq ($(UNAME),MSDOS)
  c_sources = $(subst /,\\,$(c_sources_s))
else
  c_sources = $(c_sources_s)
endif



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_SWITCHES += -DMMX_choose_table
#OBJ += i386/choose_table.o

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

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

all: $(PGM) lib

$(PGM):	main.o $(gtk_obj) libmp3lame.a 
	$(CC) $(CC_OPTS) -o $(PGM)  main.o $(gtk_obj) -L. -lmp3lame $(LIBS) $(CFLAGS) $(LDFLAGS)

mp3x:	mp3x.o $(gtk_obj) libmp3lame.a
	$(CC) -o mp3x mp3x.o $(gtk_obj) $(OBJ) $(LIBS) $(LDFLAGS) $(CFLAGS)

mp3rtp:	rtp.o mp3rtp.o libmp3lame.a
	$(CC) -o mp3rtp mp3rtp.o rtp.o   $(OBJ) $(LIBS) $(LDFLAGS) $(CFLAGS)

libmp3lame.a:  $(OBJ) Makefile
	$(AR) cr libmp3lame.a  $(OBJ)
	$(RANLIB) libmp3lame.a

#shared library, probably GNU specific?
libmp3lame.so:  $(OBJ) Makefile
	$(CC) -shared -Wl,-soname,$(SHARED_LIB_MAJOR) -o $(SHARED_LIB_MINOR) $(LIBS) $(LDFLAGS) $(OBJ)
	@$(RM_F) $(SHARED_LIB_MAJOR)
	$(LN_S) $(SHARED_LIB_MINOR) $(SHARED_LIB_MAJOR)
	@$(RM_F) $(SHARED_LIB)
	$(LN_S) $(SHARED_LIB_MAJOR) $(SHARED_LIB)

lib:  libmp3lame.a libmp3lame.so

install_header:
	@mkdir -p $(INCLUDEDIR)
	$(INSTALL_PROGRAM) lame.h $(INCLUDEDIR)

install_static_lib: libmp3lame.a install_header
	@mkdir -p $(LIBDIR)
	$(INSTALL_PROGRAM) libmp3lame.a $(LIBDIR)

install_shared_lib: libmp3lame.so install_header
	@mkdir -p $(LIBDIR)
	$(INSTALL_PROGRAM) $(SHARED_LIB_MINOR) $(LIBDIR)
	@$(RM_F) $(LIBDIR)/$(SHARED_LIB_MAJOR)
	(cd $(LIBDIR) && $(LN_S) $(SHARED_LIB_MINOR) $(SHARED_LIB_MAJOR))
	@$(RM_F) $(LIBDIR)/$(SHARED_LIB)
	(cd $(LIBDIR) && $(LN_S) $(SHARED_LIB_MAJOR) $(SHARED_LIB))

install_program: $(PGM)
	$(INSTALL_PROGRAM) $(PGM) ${BINDIR}

install: install_program install_static_lib install_shared_lib

uninstall:
	$(RM_F) $(BINDIR)/$(PGM)
	$(RM_F) $(INCLUDEDIR)/lame.h
	$(RM_F) $(LIBDIR)/libmp3lame.a
	$(RM_F) $(LIBDIR)/$(SHARED_LIB)
	$(RM_F) $(LIBDIR)/$(SHARED_LIB_MAJOR)
	$(RM_F) $(LIBDIR)/$(SHARED_LIB_MINOR)

clean:
  ifeq ($(UNAME),MSDOS)
	-del *.o
	-del *.d
	-del *.a
	-del mpglib\*.o
	-del mpglib\*.d
	-del $(PGM)
  else
	-$(RM_F) $(gtk_obj) $(OBJ) $(DEP) $(PGM) main.o rtp.o mp3rtp mp3rtp.o \
         mp3x.o mp3x libmp3lame.a \
         $(SHARED_LIB) $(SHARED_LIB_MAJOR) $(SHARED_LIB_MINOR)
  endif

bla:
	echo "LIB=$(SHARED_LIB) MAJOR=$(SHARED_LIB_MAJOR) MINOR=$(SHARED_LIB_MINOR)"

tags: TAGS

TAGS: ${c_sources} ${mpglib_sources} ${gtk_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 compiler options and effects of roundoff, the 
#  number of bytes which are different may not be zero, but
#  should be at most 30.
#
test: $(PGM)
	./$(PGM)  --nores -h testcase.wav testcase.new.mp3
	cmp -l testcase.new.mp3 testcase.mp3 | wc

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