
# Revision History:
#
#               P. Ezolt                                ??-Jul-1997
#                       Original version
#
#               J. Goddard                      10-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			10-Sep-1998
#			Merged the makefiles of all four OSs. (This is THE RIGHT THING to do..)
#
#
#------------------------------------------------------------------------------------------
#
# REP 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                 Yanked out the symbol processing code that used files and arrays
#                                 and replaced it with a doubly linkedlist scheme. Symbols are
#                                 now accumulated in memory in ascending order on a doubly linked list.
#                                      
#               2                 modified the 'duplicate symbols' message output as per request
#                                 by John Henning. The duplicate symbol messageno longer appears
#                                 unless you also use the -l switch.
#
#               3                 Reworked symbol list processing...the function/module name lists no
#                                 longer exist. Instead the names are placed directly into the
#                                 symbol node
#
#               4                 update copyright date in help text
#
#               5                 fix -i switch symbol merge (use ferror() instead of feof() for I/O
#                                 error check. clarify -i help.
#
#               6                 correct scanf format in AppendRepFiles...was hard coded whcih was changed
#                                 to SCAN_INPUT
#
#               7                 fix 'whitespace in function name' problem (NT only) and speed up REP
#
#               8                 fix resolution problem caused by #7 above
#                                             



#
# NT likes "\" and unix likes "/". (Of course unix is right.. :-)) In any event,
# All of the "$(subst /,\\,$(REP_INCLUDE)) " sprinkled through out the makefile
# simply converts the unix style paths into NT style paths.  For some reason
# "\" doesn't appear to substitute correctly, so I have to use "\\".  It isn't
# harmfull, it is just a little ugly.  If I get time, I'll try to fix it. 
#
# --P. Ezolt

# Clean doesn't yet work on NT.  Fixing this will involve moving the
# clean rule into the os_specific places, and then telling it to 
# use "del" for nt and "rm" for unix.
# --P. Ezolt

# Now, everything includes everything else.  This is bad.  Things should
# Only include what they belong to.  For example
# NT should not know about Digital unix's includes.
#


##############
#Common Flags#
##############
REP_OBJ = $(TOPDIR)/rep/obj

REP_COMMON_INC = $(TOPDIR)/rep/inc/common
REP_DUNIX_INC = $(TOPDIR)/rep/inc/dunix
REP_DULINUX_INC = $(TOPDIR)/rep/inc/dunix_linux
REP_VMSDUNIX_INC = $(TOPDIR)/rep/inc/vms_dunix
REP_VMSDULINUX_INC = $(TOPDIR)/rep/inc/vms_dunix_linux
REP_NT_INC = $(TOPDIR)/rep/inc/nt

REP_COMMON_SRC = $(TOPDIR)/rep/src/common
REP_LINUX_SRC = $(TOPDIR)/rep/src/linux
REP_DUNIX_SRC = $(TOPDIR)/rep/src/dunix
REP_DULINUX_SRC = $(TOPDIR)/rep/src/dunix_linux
REP_VMSDUNIX_SRC = $(TOPDIR)/rep/src/vms_dunix
REP_NT_SRC = $(TOPDIR)/rep/src/nt

REP_DEFS = $(SUITE_DEFS)

REP_VPATH =  $(REP_COMMON_SRC):$(REP_DUNIX_SRC):$(REP_LINUX_SRC):$(REP_DULINUX_SRC):$(REP_NT_SRC)

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

REP_INCLUDE = $(INC) -I$(REP_COMMON_INC) -I$(REP_NT_INC)

REP_LIB = $(TOPDIR)\\rep\\nt_libs

REP_LIBS = $(REP_LIB)\\imagehlp.lib $(REP_LIB)\\psapi.lib $(REP_LIB)\\msdbi50.lib libc.lib kernel32.lib advapi32.lib winmm.lib user32.lib    

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

REP_CFLAGS = $(subst /,\\,$(REP_INCLUDE)) -Dnt -D_ALPHA_=1 -D__NT -DWIN32_LEAN_AND_MEAN $(REP_DEFS) 


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

endif

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

ifeq ($(OSTYPE),OSF1)

REP_CFLAGS = -migrate -g -show all -source_listing -Dunix -Dosf -D__OSF1__ -DOSF  -verbose $(INC) -I$(REP_VMSDUNIX_INC) -I$(REP_VMSDULINUX_INC) -I$(REP_COMMON_INC) -I$(REP_DUNIX_INC) -I$(REP_DULINUX_INC) $(REP_DEFS) 

$(REP_OBJ)/%.o: %.c
	$(CC) $(REP_CFLAGS) -c -o $@ $<

endif


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

ifeq ($(OSTYPE),Linux)

REP_CFLAGS = -D__LINUX__ -I/usr/src/linux/include $(INC) -I$(REP_VMSDULINUX_INC) -I$(REP_COMMON_INC) -I$(REP_DULINUX_INC) $(REP_DEFS) -g

$(REP_OBJ)/%.o: %.c
	$(CC) $(REP_CFLAGS) -c -o $@ $<

endif


#
# rep sources
#


ALL_COMMON_REP_OBJS =			$(REP_OBJ)/rep_resolve_addresses.o\
					$(REP_OBJ)/rep_cmdln.o \
					$(REP_OBJ)/rep_files.o \
					$(REP_OBJ)/structs.o 

ALL_NT_REP_OBJS = 			$(ALL_COMMON_REP_OBJS) \
					$(REP_OBJ)/rep_nt.o \
					$(REP_OBJ)/rep_nt_image.o \
					$(REP_OBJ)/rep_nt_readpdb.o 


ALL_LINUX_REP_OBJS = 			$(ALL_COMMON_REP_OBJS) \
					$(REP_OBJ)/rep_linux.o 

ALL_DUNIX_REP_OBJS = 			$(ALL_COMMON_REP_OBJS) \
					$(REP_OBJ)/rep_osf.o 


#
# Headers for REP.EXE
#

$(REP_OBJ)/structs.o:			$(REP_COMMON_SRC)/structs.c 

$(REP_OBJ)/rep_resolve_addresses.o:	$(REP_COMMON_SRC)/rep_resolve_addresses.c

# "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.

$(REP_OBJ)/rep_cmdln.o:			FORCE \
					$(REP_COMMON_SRC)/rep_cmdln.c 

$(REP_OBJ)/structs.o:			$(REP_COMMON_SRC)/structs.c 

$(REP_OBJ)/rep_files.o:			$(REP_COMMON_SRC)/rep_files.c 


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

$(REP_OBJ)/rep_nt.o:		$(REP_NT_SRC)/rep_nt.c

$(REP_OBJ)/nt_rep.exe:		$(ALL_NT_REP_OBJS)
	link /MAP:$(subst /,\\,$(REP_OBJ))\\nt_rep.map /out:$(subst /,\\,$@) /debug:full /debugtype:both $(subst /,\\,$(ALL_NT_REP_OBJS)) $(REP_LIBS) /NODEFAULTLIB   


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

$(REP_OBJ)/rep_linux.o:		$(REP_LINUX_SRC)/rep_linux.c

$(REP_OBJ)/linux_rep:		$(ALL_LINUX_REP_OBJS)
	$(CC) -o $@ $(ALL_LINUX_REP_OBJS) -L/usr/lib -L. -lc -lm -lbfd -liberty


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

$(REP_OBJ)/rep_osf.o:		$(REP_DUNIX_SRC)/rep_osf.c

$(REP_OBJ)/dunix_rep:		$(ALL_DUNIX_REP_OBJS)
	$(CC) -g -call_shared -Wl,-expect_unresolved,ldr_process_context \
	-o $@ $(ALL_DUNIX_REP_OBJS) -lxproc -lst -lmld -lots 



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

clean-rep:
	-rm $(REP_OBJ)/*

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

linux_rep:			$(REP_OBJ)/linux_rep
linux_rep_install:
	cp $(REP_OBJ)/linux_rep $(INSTALL_DIR)/bin/rep


dunix_rep:			$(REP_OBJ)/dunix_rep
nt_rep:				$(REP_OBJ)/nt_rep.exe





