#
#  Makefile fr ild/iar/ifoobar
#

.SUFFIXES: .c .o .cc
.PHONY: all clean distclean

LDFLAGS = cpluslib/cpluslib.a
CFLAGS = -W -Wall -ansi -pedantic -g -O -Icpluslib
CXXFLAGS = $(CFLAGS)
CXX = g++-3.3

OBJECTS_ELFDUMP =  elfdump.o file.o namemap.o parse.o vfile.o
OBJECTS_IAR =  ar-symtab.o archive.o archive1.o file.o iar-d.o iar-ptx.o \
	       iar-r.o iar.o log.o parse.o section1.o \
	       vfile.o
OBJECTS_ILD =  archive.o elfio.o file.o getopt.o got.o ild.o increm.o log.o \
	       namemap.o object.o output.o param.o parse.o script.o section.o \
	       section1.o state.o symbol.o vfile.o vmalloc.o \
	       wildcard.o
OBJECTS_IRANLIB =  ar-symtab.o archive.o archive1.o file.o iranlib.o log.o \
		   parse.o section1.o \
		   vfile.o
OBJECTS_ILDD =  file.o ildd.o vfile.o
OBJECTS_ISIZE =  file.o isize.o

TARGET_ELFDUMP = elfdump
TARGET_IAR = iar
TARGET_ILD = ild
TARGET_IRANLIB = iranlib
TARGET_ILDD = ildd
TARGET_ISIZE = isize

all: elfdump iar ild iranlib ildd isize

depend depend.mak:
	perl scripts/depend.pl -Icpluslib *.cc > depend.mak

clean:
	-rm -f $(OBJECTS_ELFDUMP)
	-rm -f $(OBJECTS_IAR)
	-rm -f $(OBJECTS_ILD)
	-rm -f $(OBJECTS_IRANLIB)
	-rm -f $(OBJECTS_ILDD)
	-rm -f $(OBJECTS_ISIZE)

distclean: clean
	-rm -f $(TARGET_ELFDUMP)
	-rm -f $(TARGET_IAR)
	-rm -f $(TARGET_ILD)
	-rm -f $(TARGET_IRANLIB)
	-rm -f $(TARGET_ILDD)
	-rm -f $(TARGET_ISIZE)
	-rm -f *~

# Executable elfdump
elfdump: $(OBJECTS_ELFDUMP)
	$(CXX) -o elfdump $(OBJECTS_ELFDUMP) $(LDFLAGS)

# Executable iar
iar: $(OBJECTS_IAR)
	$(CXX) -o iar $(OBJECTS_IAR) $(LDFLAGS)

# Executable ild
ild: $(OBJECTS_ILD)
	$(CXX) -o ild $(OBJECTS_ILD) $(LDFLAGS)

# Executable iranlib
iranlib: $(OBJECTS_IRANLIB)
	$(CXX) -o iranlib $(OBJECTS_IRANLIB) $(LDFLAGS)

# Executable ildd
ildd: $(OBJECTS_ILDD)
	$(CXX) -o ildd $(OBJECTS_ILDD) $(LDFLAGS)

# Executable isize
isize: $(OBJECTS_ISIZE)
	$(CXX) -o isize $(OBJECTS_ISIZE) $(LDFLAGS)



include depend.mak

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

.cc.o:
	$(CXX) $(CXXFLAGS) -o $*.o -c $*.cc

.cc.s:
	$(CXX) $(CXXFLAGS) -o $*.s -S $*.cc


