#
# Revision History:
#
#               P. Ezolt                                ??-Jul-1997
#                       Original version
#
#               J. Goddard                      11-Sep-1997
#                       Add machinery to product C listing files and
#                       a linker map file. This includes adding the
#                       new directory 'LIS'.
#
#               J. Goddard                      10-Sep-1997
#                       Added version/rev numbers to make file.
#
#		P. Ezolt			15-Sep-1998
#			New cross-platform makefile.
#
#------------------------------------------------------------------------------------------
#
# IPROBE version and revision numbers...
#
# The version number only gets incremented for major releases and must
# be one decimal digit in length.
#
#               version number          description
#   --------------    -----------
#         3           Major cleanup of REP done during the summer of
#                     1997. REP mostly complies with the internal C
#                     coding standard, has all known bugs fixed and
#                     was resturctured in various place for correctness,
#                     readablility or sanity.
#
# The revision number gets incremented for each patch or sequence of patches
# (if they were applied together). The revision number may be from one to
# three decimal digits in length.
#
#               revision number         description
#     ---------------      -----------
#          0               Initial rev as per version 3
#
#          1               Enhance option error processing with new/mod messages
#
#          2               Misc error message enhancment and such
#
#          3               kill process started by -command when iprobe is forced to exit via ^c
#
#          4               update copyright date in help output
#                                                                                                                     

#TODO:
#
#Use CVS to set version numbers. 
#
#

##############
#Common Flags#
##############
IPROBE_OBJ = $(TOPDIR)/iprobe/obj

IPROBE_COMMON_INC = $(TOPDIR)/iprobe/inc/common
IPROBE_DUNIX_INC = $(TOPDIR)/iprobe/inc/dunix
IPROBE_DULINUX_INC = $(TOPDIR)/iprobe/inc/dunix_linux
IPROBE_VMSDUNIX_INC = $(TOPDIR)/iprobe/inc/vms_dunix
IPROBE_VMSDULINUX_INC = $(TOPDIR)/iprobe/inc/vms_dunix_linux
IPROBE_NT_INC = $(TOPDIR)/iprobe/inc/nt

IPROBE_COMMON_SRC = $(TOPDIR)/iprobe/src/common
IPROBE_LINUX_SRC = $(TOPDIR)/iprobe/src/linux
IPROBE_DUNIX_SRC = $(TOPDIR)/iprobe/src/dunix
IPROBE_DULINUX_SRC = $(TOPDIR)/iprobe/src/dunix_linux
IPROBE_VMSDUNIX_SRC = $(TOPDIR)/iprobe/src/vms_dunix
IPROBE_NT_SRC = $(TOPDIR)/iprobe/src/nt


IPROBE_DEFS = $(SUITE_DEFS)

IPROBE_VPATH =  $(IPROBE_COMMON_SRC):$(IPROBE_DUNIX_SRC):$(IPROBE_LINUX_SRC):$(IPROBE_DULINUX_SRC):$(SUITE_COMMON_SRC):$(IPROBE_NT_SRC):$(IPROBE_VMSDUNIX_SRC)


#############
#NT Flags#
#############
ifeq ($(OS),Windows_NT)

IPROBE_INCLUDE = $(INC) -I$(IPROBE_COMMON_INC) -I$(IPROBE_NT_INC)

IPROBE_LIB = $(TOPDIR)\\iprobe\\nt_libs

IPROBE_LIBS = $(TOPDIR)\\lib\\obj\\iprshr.lib  libc.lib kernel32.lib advapi32.lib winmm.lib user32.lib    

# This Make magic transforms are -Idir/dir into -Idir\dir

IPROBE_CFLAGS = $(subst /,\\,$(IPROBE_INCLUDE)) -Dnt -D_ALPHA_=1 -D__NT -DWIN32_LEAN_AND_MEAN $(IPROBE_DEFS) 

$(IPROBE_OBJ)/%.o: %.c
	$(CC) $(IPROBE_CFLAGS) -c /Fo$(subst /,\\,$@) $(subst /,\\,$<) /FAs /Fa$(subst /,\\,$(subst .o,.lis,$@))

endif


#############
#DUNIX Flags#
#############

ifeq ($(OSTYPE),OSF1)

IPROBE_CFLAGS = -migrate -g -Dunix -Dosf -D__OSF1__ -DOSF $(INC) -I$(IPROBE_VMSDUNIX_INC) -I$(IPROBE_VMSDULINUX_INC) -I$(IPROBE_COMMON_INC) -I$(IPROBE_DUNIX_INC) -I$(IPROBE_DULINUX_INC) $(IPROBE_DEFS) 

$(IPROBE_OBJ)/%.o: %.c
	$(CC) $(IPROBE_CFLAGS) -c -o $@ $<

endif


#############
#LINUX Flags#
#############

ifeq ($(OSTYPE),Linux)

IPROBE_CFLAGS = -D__LINUX__ -I/usr/src/linux/include $(INC) -I$(IPROBE_VMSDULINUX_INC) -I$(IPROBE_COMMON_INC) -I$(IPROBE_DULINUX_INC) $(IPROBE_DEFS) -g

$(IPROBE_OBJ)/%.o: %.c
	$(CC) $(IPROBE_CFLAGS) -c -o $@ $<

endif



ALL_COMMON_IPROBE_OBJS = 	$(IPROBE_OBJ)/iprobe_args.o\
		 		$(IPROBE_OBJ)/iprobe_counting.o\
		 		$(IPROBE_OBJ)/iprobe_eventlib.o\
				$(IPROBE_OBJ)/iprobe_histogram.o\
				$(IPROBE_OBJ)/iprobe_main.o\
		 		$(IPROBE_OBJ)/iprobe_global.o\
		 		$(IPROBE_OBJ)/iprobe_sampling.o\
		 		$(IPROBE_OBJ)/iprobe_keylib.o\
		 		$(IPROBE_OBJ)/iprobe_time.o\
		 		$(IPROBE_OBJ)/iprobe_hdr.o

# The NT code doesn't work right now.. It has to be changed...
#  --Phil

ALL_NT_IPROBE_OBJS = 		$(ALL_COMMON_IPROBE_OBJS) \
		 		$(IPROBE_OBJ)/iprobe_nt.o

ALL_LINUX_IPROBE_OBJS = 	$(ALL_COMMON_IPROBE_OBJS) \
		 		$(IPROBE_OBJ)/iprobe_osf1_linux.o\
		 		$(IPROBE_OBJ)/iprobe_osf_vms_signal.o


ALL_DUNIX_IPROBE_OBJS = 	$(ALL_COMMON_IPROBE_OBJS) \
		 		$(IPROBE_OBJ)/iprobe_osf1_linux.o\
		 		$(IPROBE_OBJ)/iprobe_osf_vms_signal.o


#
# Headers for IPROBE.EXE
#
ipr_struct_combo=			$(IPROBE_COMMON_INC)/iprobe_struct.h\
					$(ipr_api_ext_defs_combo)\
					$(IPROBE_COMMON_INC)/iprobe_keylib.h
# "FORCE" guarentees that this command will be rebuilt.
#  We need that so the latest version of the suite is always embedded in the 
#  program help.    

$(IPROBE_OBJ)/iprobe_args.o:		FORCE\
					$(IPROBE_COMMON_SRC)/iprobe_args.c\
					$(ipr_struct_combo)\
					$(SUITE_COMMON_INC)/getopt.h\
					$(SUITE_COMMON_INC)/ipr_events.h\
					$(IPROBE_COMMON_INC)/iprobe_hdr.h\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h


$(IPROBE_OBJ)/iprobe_counting.o:	$(IPROBE_COMMON_SRC)/iprobe_counting.c\
					$(ipr_struct_combo)\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h

$(IPROBE_OBJ)/iprobe_eventlib.o:	$(IPROBE_COMMON_SRC)/iprobe_eventlib.c\
					$(ipr_struct_combo)\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h

$(IPROBE_OBJ)/iprobe_histogram.o:	$(IPROBE_COMMON_SRC)/iprobe_histogram.c\
					$(ipr_struct_combo)\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h

$(IPROBE_OBJ)/iprobe_hdr.o:		$(IPROBE_COMMON_SRC)/iprobe_hdr.c\
					$(ipr_struct_combo)\
					$(IPROBE_COMMON_INC)/iprobe_hdr.h\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h

$(IPROBE_OBJ)/iprobe_keylib.o:		$(IPROBE_COMMON_SRC)/iprobe_keylib.c\
					$(ipr_struct_combo)\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h

$(IPROBE_OBJ)/iprobe_main.o:		$(IPROBE_COMMON_SRC)/iprobe_main.c\
					$(ipr_struct_combo)\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h\
					$(IPROBE_COMMON_INC)/iprobe_hdr.h\
					$(IPROBE_COMMON_INC)/iprobe_histogram.h

$(IPROBE_OBJ)/iprobe_sampling.o:	$(IPROBE_COMMON_SRC)/iprobe_sampling.c\
					$(ipr_struct_combo)\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h\
					$(IPROBE_COMMON_INC)/iprobe_hdr.h

$(IPROBE_OBJ)/iprobe_time.o:		$(IPROBE_COMMON_SRC)/iprobe_time.c\
					$(ipr_struct_combo)

$(IPROBE_OBJ)/iprobe_global.o:		$(IPROBE_COMMON_SRC)/iprobe_global.c\
					$(IPROBE_COMMON_INC)/iprobe_hdr.h




########################################################################
#OS SPECIFIC: NT
########################################################################

$(IPROBE_OBJ)/iprobe_nt.o:		$(IPROBE_NT_SRC)/iprobe_nt.c\
					$(ipr_struct_combo)\
                                        $(IPROBE_NT_INC)\iprobe_nt.h\
					$(IPROBE_COMMON_INC)/iprobe_eventlib.h\
					$(IPROBE_COMMON_INC)/iprobe_hdr.h

$(IPROBE_OBJ)/nt_iprobe.exe:		$(ALL_NT_IPROBE_OBJS)
	link /MAP:$(subst /,\\,$(IPROBE_OBJ))\\nt_iprobe.map /out:$(subst /,\\,$@) /debug:full /debugtype:both $(subst /,\\,$(ALL_NT_IPROBE_OBJS)) $(IPROBE_LIBS) /NODEFAULTLIB 



########################################################################
#OS SPECIFIC: Linux
########################################################################


$(IPROBE_OBJ)/linux_iprobe:		$(ALL_LINUX_IPROBE_OBJS)
	$(CC) -o $@ $(ALL_LINUX_IPROBE_OBJS) -L/lib -L/usr/local/lib -L./lib/obj -Wl,-rpath,/usr/local/lib -lc -llipr 




########################################################################
#OS SPECIFIC: Dunix/Linux
########################################################################


$(IPROBE_OBJ)/iprobe_osf1_linux.o:	$(IPROBE_DULINUX_SRC)/iprobe_osf1_linux.c\
					$(ipr_struct_combo)\
					$(IPROBE_DULINUX_INC)/iprobe_osf1.h \
					$(IPROBE_COMMON_INC)/iprobe_hdr.h



$(IPROBE_OBJ)/iprobe_osf_vms_signal.o:	$(IPROBE_VMSDUNIX_SRC)/iprobe_osf_vms_signal.c\
					$(ipr_struct_combo)

########################################################################
#OS SPECIFIC: Dunix/OSF
########################################################################

$(IPROBE_OBJ)/dunix_iprobe:		$(ALL_DUNIX_IPROBE_OBJS)
	$(CC) -o $@ $(ALL_DUNIX_IPROBE_OBJS)  -L./lib/obj -lm -lipr -lots


########################################################################

clean-iprobe:
	-rm $(IPROBE_OBJ)/*

#This links all of the objects into a single kernel module. 

linux_iprobe:			$(IPROBE_OBJ)/linux_iprobe
linux_iprobe_install:
				cp $(IPROBE_OBJ)/linux_iprobe $(INSTALL_DIR)/bin/iprobe

dunix_iprobe:			$(IPROBE_OBJ)/dunix_iprobe

nt_iprobe: 			$(IPROBE_OBJ)/nt_iprobe.exe
