REVISION	= $(shell sh ./evalrev)
REVFLAGS        = -D_REVISION=$(REVISION)

CC              = gcc
CFLAGS          ?= -g -W -Wall -O3
OPTFLAGS        = -D_FILE_OFFSET_BITS=64

destdir         = 
prefix          = /usr/local
bindir          = $(prefix)/bin

BINFILES        = aircrack-ng.exe airdecap-ng.exe packetforge-ng.exe ivstools.exe kstats.exe makeivs.exe

ZIPFILE		= aircrack-ng-win.zip
REVFILE		= r$(REVISION)
CYGWINDLL	= cygwin1.dll

default: all

all: aircrack-ng airdecap-ng packetforge-ng ivstools kstats makeivs

aircrack-ng: src/aircrack-ng.c src/crypto.c src/sha1-mmx.S src/common.c src/aircrack-ptw-lib.c
	$(CC) $(CFLAGS) $(OPTFLAGS) $(REVFLAGS) src/aircrack-ng.c src/crypto.c src/sha1-mmx.S src/common.c src/aircrack-ptw-lib.c -o aircrack-ng -lpthread

airdecap-ng: src/airdecap-ng.c src/crypto.c src/common.c src/crc.c
	$(CC) $(CFLAGS) $(OPTFLAGS) $(REVFLAGS) src/airdecap-ng.c src/crypto.c src/common.c src/crc.c -o airdecap-ng
	
packetforge-ng: src/packetforge-ng.c src/common.c src/crc.c
	$(CC) $(CFLAGS) $(OPTFLAGS) $(REVFLAGS) src/packetforge-ng.c src/common.c src/crc.c -o packetforge-ng

ivstools: src/ivstools.c src/common.c
	$(CC) $(CFLAGS) $(OPTFLAGS) $(REVFLAGS) src/ivstools.c src/common.c -o ivstools

kstats: src/kstats.c
	$(CC) $(CFLAGS) $(OPTFLAGS) $(REVFLAGS) src/kstats.c  -o kstats

makeivs: test/makeivs.c
	$(CC) $(CFLAGS) $(OPTFLAGS) $(REVFLAGS) test/makeivs.c -o makeivs

strip: all
	strip $(BINFILES) $(TESTFILES)

install: all
	install -d $(destdir)$(bindir)
	install -m 755 $(BINFILES) $(destdir)$(bindir)

uninstall:
	-rm -f $(destdir)$(bindir)/aircrack-ng.exe
	-rm -f $(destdir)$(bindir)/airdecap-ng.exe
	-rm -f $(destdir)$(bindir)/arpforge.exe
	-rm -f $(destdir)$(bindir)/packetforge-ng.exe
	-rm -f $(destdir)$(bindir)/ivstools.exe
	-rm -f $(destdir)$(bindir)/kstats.exe
	-rm -f $(destdir)$(bindir)/makeivs.exe
	
zip: all
	-rm -f /$(CYGWINDLL)
	-rm -f $(ZIPFILE)
	cp /bin/$(CYGWINDLL) /
	touch $(REVFILE)
	zip -9 -D $(ZIPFILE) /$(CYGWINDLL) $(REVFILE) $(BINFILES)
	-rm -f $(REVFILE)
	-rm -f /$(CYGWINDLL)

clean:
	-rm -f $(BINFILES) $(TESTFILES)
