# Makefile for the cstrings tool by Eric S. Raymond

VERS=$(shell sed <cstrings.spec -n -e '/Version: \(.*\)/s//\1/p')

CFLAGS=-O
LDFLAGS=-s

# Stock lex works too, but gives a "Non-portable Character Class\" warning 
# and may choke on the %option yylineno in cstrings.l
LEX=flex

cstrings: cstrings.l
	$(LEX) cstrings.l
	mv lex.yy.c cstrings.c
	$(CC) $(CFLAGS) cstrings.c $(LDFLAGS) -o cstrings

cstrings.1: cstrings.xml
	xmlto man cstrings.xml

install: cstrings.1 uninstall
	cp cstrings /usr/bin
	cp cstrings.1 /usr/share/man/man1/cstrings.1

uninstall:
	rm -f /usr/bin/cstrings /usr/share/man/man1/cstrings.1

clean:
	rm -f lex.yy.c cstrings cstrings.c *~ cstrings.tar.gz
	rm -f *.rpm cstrings-*.tar.gz cstrings.1 

SOURCES = READ.ME COPYING cstrings.xml Makefile cstrings.l cstrings.spec

cstrings-$(VERS).tar.gz: $(SOURCES) cstrings.1
	@ls $(SOURCES) cstrings.1 | sed s:^:cstrings-$(VERS)/: >MANIFEST
	@(cd ..; ln -s cstrings cstrings-$(VERS))
	(cd ..; tar -czvf cstrings/cstrings-$(VERS).tar.gz `cat cstrings/MANIFEST`)
	@(cd ..; rm cstrings-$(VERS))

dist: cstrings-$(VERS).tar.gz
