# $Id: Makefile,v 1.5 1999/03/02 16:37:56 roca Exp $
#
# Makefile
#
#	Modified by : V.Roca
#	Date	    : dec 1997
#


###### OS dependant variables ######

# Which OS do you want bench/benchd to execute ?
# Change the LIBRARIES variable too...
# NB:	in case of IRIX, produce a (old) ELF32 executable for portability
#	across SGI's platforms
#
OSFLAGS = -DLINUX
#OSFLAGS = -DSOLARIS
#OSFLAGS = -DIRIX -32

# Linux version
#
LIBRARIES = -lc -lm

# Solaris version: requires -lsocket -lnsl and -L/usr/ucblib -lucb
#
#LIBRARIES = -lc -lsocket -lnsl -L/usr/ucblib -lucb -lm -lposix4

# IRIX version
#
#LIBRARIES = -lc -lm



###### Other variables ######

# Prefer gcc if available (eg. Linux), otherwise revert to cc.
# If you choose cc, you may need to change the CFLAGS too.
#CC = cc
#LD = ld
CC = gcc
LD = gcc

# Local CFLAGS.

# gcc version
CFLAGS_bench  = -O -g -Wall -DCLIENT -DFAST_SYNC ${OSFLAGS} -DDEBUG
CFLAGS_benchd = -O -g -Wall -DSERVER -DFAST_SYNC ${OSFLAGS} -DDEBUG

# cc version
# -fullwarn for IRIX c compiler
#CFLAGS_bench  = -O -fullwarn -DCLIENT -DFAST_SYNC ${OSFLAGS} -DDEBUG
#CFLAGS_benchd = -O -fullwarn -DSERVER -DFAST_SYNC ${OSFLAGS} -DDEBUG


# List of source and object files that comprise a program.
# chstksiz.o removed
#
bench_OFILES    = common.o stats.o bench.o  bench_sock.o  bench_var.o
bench_SRCFILES  = common.c stats.c bench.c  bench_sock.c  bench_var.c

benchd_OFILES   = common.o stats.o benchd.o benchd_sock.o bench_var.o
benchd_SRCFILES = common.c stats.c benchd.c benchd_sock.c bench_var.c

INC_FILES = bench.h bench_proto.h


###### Dependancies ######

all: bench benchd

bench : ${bench_SRCFILES} ${INC_FILES}
	@echo "** Compile ${bench_SRCFILES} files..."
	@for f in ${bench_SRCFILES} ; do \
		of=`basename $${f} '.c'`.o; \
		echo "${CC} ${CFLAGS_bench} -c $${f}"; \
		${CC} ${CFLAGS_bench} -c $${f}; \
	done
	@echo "done"
	@echo "** Now create bench..."
	${LD} ${LIBRARIES} ${bench_OFILES} -o bench
	@echo "done"
	@echo "** Remove useless ${bench_OFILES} files..."
	@for f in ${bench_OFILES} ; do \
		if [ -f "$${f}" ] ; then \
			rm "$${f}"; \
		fi \
	done
	@echo "done"

benchd : ${benchd_SRCFILES} ${INC_FILES}
	@echo "** Compile ${benchd_SRCFILES} files..."
	@for f in ${benchd_SRCFILES} ; do \
		of=`basename $${f} '.c'`.o; \
		echo "${CC} ${CFLAGS_benchd} -c $${f}"; \
		${CC} ${CFLAGS_benchd} -c $${f} ; \
	done
	@echo "done"
	@echo "** Now create benchd..."
	${LD} ${LIBRARIES} ${benchd_OFILES} -o benchd
	@echo "done"
	@echo "** Remove useless ${benchd_OFILES} files..."
	@for f in ${benchd_OFILES} ; do \
		if [ -f "$${f}" ] ; then \
			rm "$${f}"; \
		fi \
	done
	@echo "done"

clean :
	@for f in core ${bench_OFILES} ${benchd_OFILES} ; do \
		if [ -f "$${f}" ] ; then \
			rm "$${f}"; \
		fi \
	done

cleanall : clean
	@for f in bench.linux benchd.linux bench.solaris benchd.solaris bench.irix benchd.irix ; do \
		if [ -f "$${f}" ] ; then \
			rm $${f} ; \
		fi \
	done

linux : all
	mv bench  bench.linux
	mv benchd benchd.linux
	@if [ -L ${HOME}/bin/bench.linux -o -f ${HOME}/bin/bench.linux ] ; then \
		rm ${HOME}/bin/bench.linux ; \
		rm ${HOME}/bin/benchd.linux ; \
	fi
	ln -s "`pwd`/bench.linux"  ${HOME}/bin/bench.linux  
	ln -s "`pwd`/benchd.linux" ${HOME}/bin/benchd.linux

solaris : all
	mv bench bench.solaris
	mv benchd benchd.solaris
	# NB: error below to fix, not crucial since most of the
	#     work has been done !
	@if [ -L ${HOME}/bin/bench.solaris -o -f ${HOME}/bin/bench.linux ] then \
		rm ${HOME}/bin/bench.solaris \
		rm ${HOME}/bin/benchd.solaris \
	fi
	ln -s "`pwd`/bench.solaris"  ${HOME}/bin/bench.solaris
	ln -s "`pwd`/benchd.solaris" ${HOME}/bin/benchd.solaris

irix:
	# NB: using "make irix" is compulsory. "make" leads to errors!
	# reason: we don't manage to do compilation/linkage in two steps
	# with irix, so we do everything is here for the present!!!
	#
	# client
	#
	@echo "** Compile ${bench_SRCFILES} files..."
	${CC} ${CFLAGS_bench} ${bench_SRCFILES} ${LIBRARIES} -o bench
	@echo "done"
	#
	# server
	#
	@echo "** Compile ${benchd_SRCFILES} files..."
	${CC} ${CFLAGS_benchd} ${benchd_SRCFILES} ${LIBRARIES} -o benchd
	@echo "done"
	@echo "** Remove useless ${bench_OFILES} ${benchd_OFILES} files..."
	@for f in ${bench_OFILES} ${benchd_OFILES} ; do \
		if [ -f "$${f}" ] ; then \
			rm "$${f}"; \
		fi \
	done
	@echo "done"
	mv bench bench.irix
	mv benchd benchd.irix
	@if [ -L ${HOME}/bin/bench.irix -o -f ${HOME}/bin/bench.irix ] ; then \
		rm ${HOME}/bin/bench.irix ; \
		rm ${HOME}/bin/benchd.irix ; \
	fi
	@if [ -d ${HOME}/bin ] ; then \
		ln -s "`pwd`/bench.irix"  ${HOME}/bin/bench.irix ; \
		ln -s "`pwd`/benchd.irix" ${HOME}/bin/benchd.irix; \
	fi
