# General macro definitions

###############################################################################
#
# If building on HPUX, uncomment the following line:
#
#CFLAGS		= $(CCFLAGS) -I$(SOMDIR) $(DEFS) -DPA_2_0 -Aa -D_HPUX_SOURCE +e +DA1.1 +DS2.0
###############################################################################

###############################################################################
# If building on Linux, uncomment the following line:
CFLAGS 		= $(CCFLAGS) -I$(SOMDIR) $(DEFS) -DPA_2_0 -D_HPUX_SOURCE -Ihpux -g -DLINUX
#
# This ugliness will go away when I start using autoconf
###############################################################################

SHELL   	= /bin/bash
CC		= cc
GENCAT  	= gencat


BUILD_OPT 	= -DBUILD_STAMP="\"EXP $$(date +%y%m%d)\""

DEFS		= -DFDP_CODE -DOBS_FEATURES_WARN -DTSD -D__hp9000s800 -DNO_MADVISE
LDFLAGS 	= -z -L.

CCLDFLAGS 	= $(CCFLAGS) $(LDFLAGS)

LIBS            =

OBJS 		= allocate.o bv_dense.o embed.o fixups.o libraries.o linker.o \
		  subspaces.o symbols.o util.o \
		  opt.o output.o spaces.o ld_strings.o \
		  stubs.o o2n_driver.o o2n_tally.o fgetword.o fdp.o hash.o \
		  debug_opt.o dead_proc.o annotate.o comdat.o fe_error.o \
		  elf_detector.o get_text_off.o \
                  ld_linkmap.o linuxutil.o \

SOMDIR		= som

SOMHDRS 	= $(SOMDIR)/aouthdr.h \
		  $(SOMDIR)/aouttypes.h \
		  $(SOMDIR)/compunit.h \
		  $(SOMDIR)/filehdr.h \
		  $(SOMDIR)/initptr.h \
		  $(SOMDIR)/lst.h \
		  $(SOMDIR)/reloc.h \
		  $(SOMDIR)/scnhdr.h \
		  $(SOMDIR)/spacehdr.h \
		  $(SOMDIR)/syms.h \
		  $(SOMDIR)/shl.h \
		  $(SOMDIR)/dl.h

SRC 		= .


ld:		$(OBJS) version.o driver.o
	$(CC)  $(CFLAGS) $(CCLDFLAGS) -o $@ version.o driver.o $(OBJS) $(LIBS) 

# err_hpux.src:	err.src
# 	sed -e 's/!\([1-9]\)/%\1$$s/g' < err.src > err_hpux.src
# 
# ld.cat:		err_hpux.src
# 	$(GENCAT) $@ err_hpux.src

version.o:	version.h subvers.h
	$(CC) -c $(CFLAGS) $(BUILD_OPT) version.c

driver.o:	driver.c std.h linker.h ld_strings.h \
		$(SOMHDRS) errors.h driver.h \
		util.h embed.h ldlimits.h \
		symbols.h dead_proc.h annotate.h
	$(CC) -c $(CFLAGS) driver.c

allocate.o:	allocate.c std.h $(SOMHDRS) linker.h \
		subspaces.h fixups.h stubs.h \
		symbols.h errors.h driver.h util.h \
		libraries.h spaces.h embed.h \
		ldlimits.h dead_proc.h annotate.h
	$(CC) -c $(CFLAGS) allocate.c

bv_dense.o:	bv_dense.c std.h util.h 
	$(CC) -c $(CFLAGS) bv_dense.c

comdat.o:	comdat.c symbols.h subspaces.h \
		std.h comdat.h $(SOMHDRS) ldlimits.h \
		driver.h
	$(CC) -c $(CFLAGS) comdat.c

embed.o:	embed.c std.h util.h spaces.h \
		ldlimits.h
	$(CC) -c $(CFLAGS) embed.c

dead_proc.o:	dead_proc.c std.h  fixups.h \
		$(SOMHDRS) spaces.h subspaces.h symbols.h \
		util.h dead_proc.h ldlimits.h \
		driver.h
	$(CC) -c $(CFLAGS) dead_proc.c

fixups.o:	fixups.c std.h linker.h $(SOMHDRS) \
		subspaces.h fixups.h symbols.h \
                stubs.h stub_inst.h o2n_tally.h \
                errors.h driver.h  util.h \
		libraries.h spaces.h ldlimits.h \
		debug_opt.h annotate.h
	$(CC) -c $(CFLAGS) fixups.c

get_text_off.o:	get_text_off.c
	$(CC) -c $(CFLAGS) get_text_off.c

libraries.o:	libraries.c std.h linker.h \
		$(SOMHDRS) symbols.h errors.h driver.h \
		util.h ldlimits.h \
		libraries.h spaces.h subspaces.h
	$(CC) -c $(CFLAGS) libraries.c

linker.o:	linker.c std.h $(SOMHDRS) \
		linker.h subspaces.h errors.h \
		driver.h  util.h ldlimits.h \
		libraries.h spaces.h symbols.h \
		debug_opt.h annotate.h
	$(CC) -c $(CFLAGS) linker.c

o2n_driver.o:	o2n_driver.c std.h $(SOMHDRS) linker.h \
		ld_strings.h subspaces.h fixups.h \
		o2n_tally.h symbols.h util.h \
                errors.h driver.h spaces.h \
		ldlimits.h
	$(CC) -c $(CFLAGS) o2n_driver.c

o2n_tally.o:	o2n_tally.c $(SOMHDRS) std.h \
		fixups.h util.h errors.h driver.h \
		ldlimits.h symbols.h linker.h \
		o2n_tally.h
	$(CC) -c $(CFLAGS) o2n_tally.c

opt.o:	opt.c std.h driver.h errors.h \
		fixups.h subspaces.h symbols.h \
		opt.h util.h ldlimits.h
	$(CC) -c $(CFLAGS) opt.c

output.o:	output.c std.h $(SOMHDRS) linker.h \
		output.h subspaces.h fixups.h \
		stubs.h symbols.h stub_inst.h \
                errors.h driver.h  util.h \
		libraries.h spaces.h ldlimits.h \
		debug_opt.h annotate.h
	$(CC) -c $(CFLAGS) output.c

spaces.o:	spaces.c std.h $(SOMHDRS) linker.h \
                subspaces.h errors.h driver.h  \
		util.h spaces.h ldlimits.h
	$(CC) -c $(CFLAGS) spaces.c

ld_strings.o:	ld_strings.c std.h $(SOMHDRS) linker.h \
                errors.h driver.h  util.h ldlimits.h
	$(CC) -c $(CFLAGS) ld_strings.c

stubs.o:	stubs.c std.h linker.h $(SOMHDRS) \
		subspaces.h fixups.h stubs.h \
		linker.h stub_inst.h symbols.h \
                errors.h driver.h  util.h \
		libraries.h spaces.h ldlimits.h \
		annotate.h
	$(CC) -c $(CFLAGS) stubs.c

subspaces.o:	subspaces.c std.h linker.h \
		$(SOMHDRS) subspaces.h symbols.h errors.h \
		driver.h  util.h libraries.h \
		spaces.h ldlimits.h
	$(CC) -c $(CFLAGS) subspaces.c

symbols.o:	symbols.c std.h $(SOMHDRS) linker.h \
		symbols.h subspaces.h stubs.h \
                errors.h driver.h  util.h \
		libraries.h ldlimits.h
	$(CC) -c $(CFLAGS) symbols.c

util.o:		util.c std.h $(SOMHDRS) subspaces.h \
		symbols.h stubs.h errors.h \
		driver.h  util.h ldlimits.h
	$(CC) -c $(CFLAGS) util.c

fdp.o:	fdp.c std.h linker.h \
		$(SOMHDRS) subspaces.h symbols.h errors.h \
		driver.h  util.h libraries.h \
		spaces.h ldlimits.h
	$(CC) -c $(CFLAGS) fdp.c

hash.o:	hash.c std.h util.h
	$(CC) -c $(CFLAGS) hash.c

fgetword.o:	fgetword.c std.h
	$(CC) -c $(CFLAGS) fgetword.c

debug_opt.o:	debug_opt.c debug_opt.h \
		std.h linker.h $(SOMHDRS) \
		subspaces.h fixups.h symbols.h \
                stubs.h stub_inst.h o2n_tally.h \
                errors.h driver.h  util.h \
		libraries.h spaces.h ldlimits.h
	$(CC) -c $(CFLAGS) debug_opt.c

annotate.o:	annotate.c annotate.h
	$(CC) -c $(CFLAGS) annotate.c

elf_detector.o:	elf_detector.h
	$(CC) -c $(CFLAGS) elf_detector.c

fe_error.o: fe_error.c
	$(CC) -c $(CFLAGS) fe_error.c

# cnx_link_info.o: std.h ldlimits.h spaces.h \
# 		 subspaces.h cnx_link_info.h \
# 		 libraries.h driver.h linker.h
# 	$(CC) -c $(CFLAGS) cnx_link_info.c

linuxutil.o: linuxutil.c
	$(CC) -c $(CFLAGS) linuxutil.c

ld_linkmap.o: ld_linkmap.c std.h ldlimits.h \
		 spaces.h subspaces.h ld_linkmap.h \
		 ld_linkmap_int.h \
		 libraries.h driver.h linker.h \
		 output.h util.h linkmap.h 
	$(CC) -c $(CFLAGS) ld_linkmap.c

