BINUTILS  = $(HOME)/src/binutils-2.20.1
ZLIB      = $(HOME)/src/zlib-1.2.5
LIBIBERTY = $(BINUTILS)/libiberty
BINUTIL   = $(BINUTILS)/binutils
OPCODES   = $(BINUTILS)/opcodes
BFD       = $(BINUTILS)/bfd
BIN       = ~/bin
CC        = gcc

WARN_CFLAGS = -W -Wall -Wstrict-prototypes -Wmissing-prototypes

CFLAGS  = -g -I. -I$(BINUTILS)/include -I$(BINUTIL) -I$(BFD) \
 -DHAVE_CONFIG_H \
 -D_GNU_SOURCE  \
 -DLOCALEDIR="\"/usr/local/share/locale\"" \
 -Dbin_dummy_emulation=bin_vanilla_emulation \
 -D_LARGEFILE64_SOURCE \
 -DDISASSEMBLER_NEEDS_RELOCS \
 $(WARN_CFLAGS)

OBJECTS = \
 asxo.o \
 $(BINUTIL)/debug.o \
 $(BINUTIL)/stabs.o \
 $(BINUTIL)/ieee.o \
 $(BINUTIL)/rdcoff.o \
 $(BINUTIL)/bucomm.o \
 $(BINUTIL)/filemode.o \
 $(OPCODES)/disassemble.o \
 $(OPCODES)/dis-buf.o  \
 $(OPCODES)/dis-init.o \
 $(OPCODES)/i386-dis.o

# Note early versions of binutils do not need zlib.a

LIBRARIES = \
 $(BFD)/libbfd.a \
 $(LIBIBERTY)/libiberty.a \
 $(ZLIB)/libz.a 

asxo : $(OBJECTS) $(LIBRARIES) main.o
	@rm -f asxo
	gcc -o asxo -g $(WARN_CFLAGS) $(OBJECTS) main.o $(LIBRARIES)

asxo.E : asxo.c
	cpp $(CFLAGS) asxo.c > asxo.E

main.o : main.c
	gcc -c $(CFLAGS) main.c

asxo.o : asxo.c
	gcc -c $(CFLAGS) asxo.c 

$(BINUTIL)/budemang.o : $(BINUTIL)/budemang.c
	cd $(BINUTIL); make budemang.o

$(BINUTIL)/prdbg.o : $(BINUTIL)/prdbg.c
	cd $(BINUTIL); make prdbg.o

$(BINUTIL)/rddbg.o : $(BINUTIL)/rddbg.c
	cd $(BINUTIL); make rddbg.o

$(BINUTIL)/debug.o : $(BINUTIL)/debug.c
	cd $(BINUTIL); make debug.o

$(BINUTIL)/stabs.o : $(BINUTIL)/stabs.c
	cd $(BINUTIL); make stabs.o

$(BINUTIL)/ieee.o : $(BINUTIL)/ieee.c
	cd $(BINUTIL); make ieee.o

$(BINUTIL)/rdcoff.o : $(BINUTIL)/rdcoff.c
	cd $(BINUTIL); make rdcoff.o

$(BINUTIL)/bucomm.o : $(BINUTIL)/bucomm.c
	cd $(BINUTIL); make bucomm.o

$(BINUTIL)/version.o : $(BINUTIL)/version.c
	cd $(BINUTIL); make version.o

$(BINUTIL)/filemode.o : $(BINUTIL)/filemode.c
	cd $(BINUTIL); make filemode.o

$(OPCODES)/disassemble.o : $(OPCODES)/disassemble.c
	cd $(OPCODES); make disassemble.o

$(OPCODES)/dis-buf.o : $(OPCODES)/dis-buf.c
	cd $(OPCODES); make dis-buf.o

$(OPCODES)/dis-init.o : $(OPCODES)/dis-init.c
	cd $(OPCODES); make dis-init.o

$(OPCODES)/i386-dis.o : $(OPCODES)/i386-dis.c
	cd $(OPCODES); make i386-dis.o

tests : test test1 test2 test3 test4 test5

test : asxo asxo.o
	./asxo asxo.o > asxo.o.asxo

test1 : asxo 
	./asxo $(OPCODES)/.libs/libopcodes.a > libopcodes.a.asxo

test2 : asxo 
	./asxo ../asx.o > asx.o.asxo

test3 : asxo
	./asxo /usr/lib/libkdesu.so  > libkdesu.so.asxo

test4 : asxo
	./asxo asxo > asxo.asxo

test5 : asxo
	./asxo ../asx > asx.asxo

install: asxo
	cp asxo $(BIN)/asxo
	chmod 755 $(BIN)/asxo

clean :
	rm -f *.o *.asxo asxo
