#CC = /usr/local/cs/bin/gcc
CC = gcc
CFLAGS= -O1 -Wall 
CINC =
F32 =-m32 -fno-omit-frame-pointer
F32c =-m32 -march=i686 -msse4 -mfpmath=sse
F64 =-m64


.SUFFIXES: .c .32s .64s .32o .64o .32d .64d .32cs


.c.32s:
	$(CC) $(CFLAGS) $(CINC) -S $(F32) $*.c -o $*.$(MACHINE)32s

.c.32cs:
	$(CC) $(CFLAGS) $(CINC) -S $(F32c) $*.c -o $*.$(MACHINE)32cs

.c.64s:
	$(CC) $(CFLAGS) $(CINC) -S $(F64) $*.c -o $*.$(MACHINE)64s

.c.32d:
	$(CC) $(CFLAGS) $(CINC) $(F32) $*.c -o $*
	objdump -d $* > $*.32d
	rm -f $*

.c.64d:
	$(CC) $(CFLAGS) $(CINC) $(F64) $*.c -o $*
	objdump -d $* > $*.64d
	rm -f $*

files:	align-struct32 align-struct64 align-struct.32s bufdemo.32s bufdemo.32d bufdemo bufdemo-protected bufdemo.32pd bufdemo.32s bufdemo.32ps align

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

align-struct32: align-struct.c
	$(CC) $(CFLAGS) $(CINC) $(F32) align-struct.c -o align-struct32

align-struct64: align-struct.c
	$(CC) $(CFLAGS) $(CINC) $(F64) align-struct.c -o align-struct64

bufdemo: bufdemo.c
	$(CC) $(CFLAGS) $(CINC) $(F32) bufdemo.c -o bufdemo

bufdemo-protected: bufdemo.c
	$(CC) $(CFLAGS) $(CINC) $(F32) -fstack-protector-all bufdemo.c -o bufdemo-protected

bufdemo.32pd: bufdemo-protected
	objdump -d bufdemo-protected > bufdemo.32pd

bufdemo.32ps: bufdemo.c
	$(CC) $(CFLAGS) $(CINC) $(F32) -fstack-protector-all bufdemo.c -S -o bufdemo.32ps

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

exploit.raw: exploit.txt hex2raw
	./hex2raw < exploit.txt > exploit.raw

clean:
	rm -f *~

superclean: clean
	rm -f *.32s *.64s *.32o *.64o *.32d *.64d
	rm -f bufdemo bufdemo-protected

