# Flawfinder.  Released under the General Public License (GPL).
# (C) 2001 David A. Wheeler.

# To change version number, edit this here, the beginning of the
# "flawfinder" script, flawfinder.spec, setup.py, and index.html.
# Eventually switch to using DistUtils to autogenerate.

NAME=flawfinder
VERSION=0.21
RPM_VERSION=1
VERSIONEDNAME=$(NAME)-$(VERSION)
ARCH=i386
# Copied to "noarch".

SAMPLE_DIR=/usr/src/linux-2.2.16

INSTALL_DIR=/usr/local
INSTALL_DIR_BIN=$(INSTALL_DIR)/bin
INSTALL_DIR_MAN=$(INSTALL_DIR)/man/man1

# For Cygwin on Windows, set EXE=.exe
EXE=

all: flawfinder.pdf flawfinder.1.gz
	chmod -R a+rX *


# This installer doesn't install the compiled Python bytecode.
install:
	cp flawfinder$(EXE) $(INSTALL_DIR_BIN)
	cp flawfinder.1 $(INSTALL_DIR_MAN)

uninstall:
	rm $(INSTALL_DIR_BIN)/flawfinder$(EXE)
	rm $(INSTALL_DIR_MAn)/flawfinder.1

flawfinder.1.gz: flawfinder.1
	gzip -c9 < flawfinder.1 > flawfinder.1.gz

flawfinder.ps: flawfinder.1
	man -t ./flawfinder.1 > flawfinder.ps

flawfinder.pdf: flawfinder.ps
	ps2pdf flawfinder.ps flawfinder.pdf


clean:
	rm -f *.pyc
	rm -f flawfinder-$(VERSION).tar.gz
	rm -f *.tar

distribute: clean
	chmod -R a+rX *
	mkdir ,1
	cp -p [a-zA-Z]* ,1
	rm -f ,1/*.tar.gz
	rm -f ,1/*.rpm
	# We don't need both "flawfinder" and "flawfinder.py":
	rm -f ,1/flawfinder.py
	mv ,1 flawfinder-$(VERSION)
	tar cvfz flawfinder-$(VERSION).tar.gz flawfinder-$(VERSION)
	chown --reference=. flawfinder-$(VERSION).tar.gz
	rm -fr flawfinder-$(VERSION)


time:
	echo "Timing the program. First, time taken:"
	time ./flawfinder $(SAMPLE_DIR)/*/*.[ch] > /dev/null
	echo "Lines examined:"
	wc -l $(SAMPLE_DIR)/*/*.[ch] | tail -2

test:
	./flawfinder test.c

profile:
	/usr/lib/python1.5/profile.py ./flawfinder > profile-results $(SAMPLE_DIR)/*/*.[ch] > profile-results 


rpm: distribute
	chmod -R a+rX *
	cp $(VERSIONEDNAME).tar.gz /usr/src/redhat/SOURCES
	cp flawfinder.spec /usr/src/redhat/SPECS
	cd /usr/src/redhat/SPECS
	rpm -ba flawfinder.spec
	chmod a+r /usr/src/redhat/RPMS/$(ARCH)/$(VERSIONEDNAME)-$(RPM_VERSION)*.rpm
	chmod a+r /usr/src/redhat/SRPMS/$(VERSIONEDNAME)-$(RPM_VERSION)*.src.rpm
	rpm -ivh /usr/src/redhat/RPMS/$(ARCH)/$(VERSIONEDNAME)-$(RPM_VERSION)*.rpm
	# cp -p /usr/src/redhat/RPMS/$(ARCH)/$(VERSIONEDNAME)-$(RPM_VERSION)*.rpm .
	cp -p /usr/src/redhat/RPMS/$(ARCH)/$(VERSIONEDNAME)-$(RPM_VERSION)*.rpm  $(VERSIONEDNAME)-$(RPM_VERSION).noarch.rpm
	cp -p /usr/src/redhat/SRPMS/$(VERSIONEDNAME)-$(RPM_VERSION)*.src.rpm .
	echo "Use rpm -e $(NAME) to remove the package"
	chown --reference=. *.rpm


# When I switch to using "DistUtils", I may need to move the MANIFEST.in
# file into a subdirectory (named flawfinder-versionnumber).
# I can then create all the distribution files by just typing:
#  python setup.py bdist_rpm

