#
#
# Makefile for wavrec and mpegrec
#     Andrew L. Sandoval   Feb. 2000
#
PREFIX = /usr/local
INSTALL_DIR = $(PREFIX)/bin
#DISABLE_HOARD = YES

WHICH_LAME = $(shell which lame)
LAME = $(findstring lame,$(WHICH_LAME))
NUMPROCS = "$(shell cat /proc/cpuinfo |grep -c processor)"
HOARD_A = $(shell ls /usr/lib|grep -c libhoard.a)
HOARD_S = $(shell ls /usr/lib|grep -c libhoard.so)
HOARD_LOCAL_A = $(shell ls /usr/local/lib|grep -c libhoard.a)
HOARD_LOCAL_S = $(shell ls /usr/local/lib|grep -c libhoard.so)

HOARDLIB =
USE_HOARD = "Not utilizing libhoard for SMP memory management."

ifeq "$(LAME)" "lame"
	LAMEFOUND =  "The 'lame' encoder was found in your path."
else
	LAMEFOUND = "WARNING: 'lame' is required for mpegrec and was NOT found on your system."
endif

# Set in order of preference:
ifeq "$(HOARD_LOCAL_S)" "1"
	HOARDLIB = -L/usr/local/lib -lhoard
	USE_HOARD = "Using /usr/local/lib/libhoard.so for SMP memory management."
endif

ifeq "$(HOARD_LOCAL_A)" "1"
   HOARDLIB = /usr/local/libhoard.a
   USE_HOARD = "Using /usr/local/lib/libhoard.a for SMP memory management."
endif

ifeq "$(HOARD_S)" "1"
   HOARDLIB = -lhoard
   USE_HOARD = "Using /usr/lib/libhoard.so for SMP memory management."
endif

ifeq "$(HOARD_A)" "1"
   HOARDLIB = /usr/lib/libhoard.a
   USE_HOARD = "Using /usr/lib/libhoard.a for SMP memory management."
endif

ifeq "$(NUMPROCS)" "1"
	HOARDLIB =
	USE_HOARD = "Not utilizing libhoard for SMP memory management."
endif

ifeq "$(DISABLE_HOARD)" "YES"
	HOARDLIB =
	USE_HOARD = "Not utilizing libhoard for SMP memory management."
endif
	
all:	wavrec mpegrec

wavrec:	srec.cc Makefile
	@echo "Building wavrec for a system with $(NUMPROCS) processor(s)"
	@echo "$(USE_HOARD)"
	g++ srec.cc -o wavrec $(HOARDLIB) -O9 -lpthread -fomit-frame-pointer \
	-march=pentiumpro -ffast-math -funroll-loops -fprofile-arcs \
	-fbranch-probabilities

mpegrec:	wavrec
	ln -fs wavrec mpegrec
	@echo
	@echo -e "\a$(LAMEFOUND)"
	@echo

install:	wavrec mpegrec
	cp wavrec $(INSTALL_DIR)/
	ln -fs $(INSTALL_DIR)/wavrec $(INSTALL_DIR)/mpegrec
	@echo
	@echo -e "\a$(LAMEFOUND)"
	@echo

clean:
	rm -f wavrec mpegrec *.da

