#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#  Copyright (C) 2003 - The Authors
#
#  Author : Richard GAYRAUD - 04 Nov 2003
#           From Hewlett Packard Company.
#

# Output binary to be built
OUTPUT=sipp

# C & C++ object files to be built
OBJ= xp_parser.o scenario.o screen.o call.o comp.o sipp.o stat.o \
     actions.o variables.o 

# Include directories
INCDIR= -I.

# Libraries directories
LIBDIR_linux=
LIBDIR_hpux=
LIBDIR_tru64=
LIBDIR_SunOS=

# Archive file created in your home directory when building the archive target
# ARCHIVE= $(HOME)/$(OUTPUT).tgz
ARCHIVE= $(OUTPUT).tgz

# Files to be erased by 'make clean' in addition to the output 
# binaries and object files:
TOCLEAN= sipp_errors.log sipp_messages.log sipp_statistics.log $(ARCHIVE) \
         *.csv

###################################################################
# Generic Rules

OSNAME=`uname`
MODELNAME=`uname -m`

# SYSTEM nickname
SYSTEM_HP-UX=hpux
SYSTEM_Linux=linux
SYSTEM_OSF1=tru64
SYSTEM_SunOS=SunOS
SYSTEM=$(SYSTEM_$(OSNAME))

# C compiler
CC_hpux=cc  
CC_linux=cc  
CC_tru64=cc  
CC_SunOS=gcc
CC=$(CC_$(SYSTEM))

# C++ compiler mapping
CPP_hpux=aCC  
CPP_linux=gcc  
CPP_tru64=cxx  
CPP_SunOS=gcc
CPP=$(CPP_$(SYSTEM))

#Model specific flags
MFLAGS_ia64=+DD64
MFLAGS_9000/800=+DAportable
MFLAGS_9000/785=+DAportable
MFLAGS_i686=
MFLAGS_i586=
MFLAGS_i486=
MFLAGS_i386=
MFLAGS=$(MFLAGS_$(MODELNAME))

#C Compiler Flags
CFLAGS_hpux=-D__HPUX
CFLAGS_linux=-D__LINUX -pthread
CFLAGS_tru64=-D__OSF1 -pthread
CFLAGS_SunOS=-g
CFLAGS=$(CFLAGS_$(SYSTEM)) -D__3PCC__

#C++ Compiler Flags
CPPFLAGS_hpux=-AA -mt -D__HPUX 
CPPFLAGS_linux=-D__LINUX -pthread
CPPFLAGS_tru64=-D__OSF1 -pthread
CPPFLAGS_SunOS=-g
CPPFLAGS=$(CPPFLAGS_$(SYSTEM)) -D__3PCC__

#Linker mapping
CCLINK_hpux=aCC
CCLINK_linux=gcc
CCLINK_tru64=cxx
CCLINK_SunOS=gcc
CCLINK=$(CCLINK_$(SYSTEM))

#Linker Flags
LFLAGS_hpux=-AA -mt
LFLAGS_linux=
LFLAGS_tru64=
LFLAGS_SunOS=
LFLAGS=$(LFLAGS_$(SYSTEM))

#Link Libraries
LIBS_linux= -ldl -lpthread -lcurses -lstdc++
LIBS_hpux= -lcurses
LIBS_tru64= -lcurses -lpthread
LIBS_SunOS= -lcurses -lpthread -lnsl -lsocket -lstdc++ -ldl
LIBS=$(LIBS_$(SYSTEM))

# Operating system detection rule
all:
	make OSNAME=`uname` MODELNAME=`uname -m` $(OUTPUT)

$(OUTPUT): $(OBJ)
	$(CCLINK) $(LFLAGS) $(MFLAGS) $(LIBDIR_$(SYSTEM)) \
	$(LIBS) $(DEBUG_FLAGS) -o $@ $(OBJ)

debug:
	@DEBUG_FLAGS=-g ; export DEBUG_FLAGS ; make all

clean:
	rm -f $(OBJ) $(OUTPUT) *~ $(TOCLEAN) 
	rm -rf cxx_repository

archive:
	rm -f TMP_TAR_FILE.* $(ARCHIVE)
	make clean
	tar cf TMP_TAR_FILE.tar .
	gzip TMP_TAR_FILE.tar
	cp TMP_TAR_FILE.tar.gz $(ARCHIVE)
	rm -f TMP_TAR_FILE.*


# Files types rules
.SUFFIXES: .o .cpp .c .h .hpp

*.o: *.h *.hpp

.C.o:
	$(CPP) $(CPPFLAGS) $(MFLAGS) $(DEBUG_FLAGS) $(INCDIR) -c -o $*.o $<

.cpp.o:
	$(CPP) $(CPPFLAGS) $(MFLAGS) $(DEBUG_FLAGS) $(INCDIR) -c -o $*.o $<

.c.o:
	$(CC) $(CFLAGS) $(MFLAGS) $(DEBUG_FLAGS) $(INCDIR) -c -o $*.o $<

