# Makefile for sbox.
# 1. Change the definition of CGI_DIRECTORY to point to your site-wide
#    cgi-bin directory
# 2. Review the INSTALL_OPTS definitions if you need to (will install
#    sbox SUID to root)
# 3. Change CFLAGS and CC definitions if you need to.
# 4. "make"
# 5. "make install"
VERSION= 1.07

CC = gcc
#CC = cc

COPTS = -O -g
#COPTS = -g -DDEBUG
#COPTS = -W -Wall -ansi -pedantic

STATIC_FLAG = -static

INSTALL_OPTS = -o root -g bin -m 4111 -s
INSTALL_DIRECTORY = $(DESTDIR)/usr/lib/cgi-bin
#INSTALL_DIRECTORY = /usr/local/www/cgi-bin

CFLAGS = $(COPTS) -DVERSION=$(VERSION)
INSTALL = install
LYNX    = lynx
PURIFY  = purify -chain-length="10" cc -g 

default: sbox

all: sbox env

sbox: sbox.o
	$(CC) $(LDOPTS) -o sbox sbox.o
	strip sbox
	strip -R .comment -R .note sbox
	chmod 4711 sbox

sbox.o: sbox.c sbox.h Makefile

sbox_pure: sbox.o
	$(PURIFY) -o $@ sbox.o

env: env.o
	$(CC) $(STATIC_FLAG) -o env env.o

README.txt: README.html
	$(LYNX) -nolist -underscore -dump $< > $@

clean:
	rm -rf *.o core sbox env *~ CVS_sbox* *.tar.gz  build debian/tmp debian/substvars debian/files configure-stamp build-stamp
#        @-echo "OK, clean :)"

install: sbox
	mkdir -p $(INSTALL_DIRECTORY)
	$(INSTALL) $(INSTALL_OPTS) sbox $(INSTALL_DIRECTORY)

dist:	README.txt sbox.h sbox.c env.c Makefile
	-mkdir sbox-$(VERSION)
	cp README.html README.txt sbox.h sbox.c env.c Makefile sbox-$(VERSION)
	tar cvf - sbox-$(VERSION) | gzip -9c > sbox-$(VERSION).tgz
	rm -rf sbox-$(VERSION)
