### Makefile.in - Persistent CGI configuration ###

### start of system configuration section ###

prefix=		@prefix@
exec_prefix=	@exec_prefix@

BINDIR=	$(exec_prefix)/bin

srcdir=	@srcdir@
VPATH = @srcdir@
VERSION=	@VERSION@
MACHDEP=	@MACHDEP@

CC = @CC@

DEFS= @DEFS@ -DUNIX -DOPT_NO_STDERR -DCLOSE_FDS

LIBS= @LIBS@

creosotedir = $(srcdir)/MrCreosote
testdir = $(srcdir)/Test
utildir = $(srcdir)/Util

### end of system configuration section ###

.c.o:
	$(CC) -c $(CPPFLAGS) $(DEFS) -I. -I$(srcdir) $(CFLAGS) $<

PROGS = pcgi-wrapper $(creosotedir)/pcgi-creosote $(testdir)/parseinfo
SRCS = pcgi-wrapper.c parseinfo.c $(creosotedir)/creosote.c
OBJS1 = pcgi-wrapper.o parseinfo.o 
OBJS2 = $(creosotedir)/pcgi-wrapper.o parseinfo.o $(creosotedir)/creosote.o
OBJS3 = $(srcdir)/pcgi-wrapper.o $(testdir)/parseinfo.o
HDRS = pcgi.h $(creosotedir)/creosote.h

# --with-XXX options for configure
WITH=

MANIFEST=$(srcdir)/manifest

# default path permission settings
DIRMODE=	775                                                             
EXEMODE=	755                                                             
FILEMODE=	644                                                             
                                                                                
# Portable install script (configure doesn't always guess right)                
INSTALL=	./install-sh -c                                                 
INSTALL_PROGRAM=${INSTALL} -m $(EXEMODE)                                        
INSTALL_DATA=   ${INSTALL} -m $(FILEMODE)                                       

##################################################

all:	pcgi-wrapper $(testdir)/parseinfo
	
pcgi-wrapper.o:	pcgi-wrapper.c pcgi.h
	$(CC) -c -I. -I$(srcdir) $(CFLAGS) -DPCGI_WRAPPER_MAIN -DVERSION=\"$(VERSION)\" $(DEFS) $(srcdir)/pcgi-wrapper.c

parseinfo.o: parseinfo.c pcgi.h
	$(CC) -c -I. -I$(srcdir) $(CFLAGS) $(DEFS) $(srcdir)/parseinfo.c

pcgi-wrapper: pcgi-wrapper.o parseinfo.o
	$(CC) $(LIBS) $(LDFLAGS) -o pcgi-wrapper $(OBJS1)

### begin CREOSOTE stuff ###

$(creosotedir)/creosote.o: $(creosotedir)/creosote.c $(creosotedir)/creosote.h
	$(CC) -c -o $(creosotedir)/creosote.o -I. -I$(srcdir) -I$(creosotedir) $(CFLAGS) -DCREOSOTE $(DEFS) $(creosotedir)/creosote.c

$(creosotedir)/pcgi-wrapper.o: $(srcdir)/pcgi-wrapper.c
	$(CC) -c -o $(creosotedir)/pcgi-wrapper.o -I. -I$(srcdir) -I$(creosotedir) $(CFLAGS) -DPCGI_WRAPPER_MAIN -DCREOSOTE $(DEFS) $(srcdir)/pcgi-wrapper.c

creosote: $(creosotedir)/pcgi-creosote

$(creosotedir)/pcgi-creosote: $(creosotedir)/pcgi-wrapper.o parseinfo.o $(creosotedir)/creosote.o
	$(CC) $(LIBS) $(LDFLAGS) -o $(creosotedir)/pcgi-creosote $(OBJS2)

### end CREOSOTE stuff ###

### begin TEST stuff ###

$(testdir)/parseinfo.o: $(srcdir)/parseinfo.c
	$(CC) -c -o $(testdir)/parseinfo.o -I. -I$(srcdir) -I$(testdir) $(CFLAGS) -DMAIN_PARSEINFO $(DEFS) $(srcdir)/parseinfo.c

$(testdir)/pcgi-wrapper.o: $(srcdir)/pcgi-wrapper.c
	$(CC) -c -o $(testdir)/pcgi-wrapper.o -I. -I$(srcdir) -I$(testdir) $(CFLAGS) $(DEFS) $(srcdir)/pcgi-wrapper.c

parseinfo: $(testdir)/parseinfo	

$(testdir)/parseinfo: $(testdir)/parseinfo.o $(testdir)/pcgi-wrapper.o
	$(CC) $(LIBS) $(LDFLAGS) -o $(testdir)/parseinfo $(testdir)/parseinfo.o $(testdir)/pcgi-wrapper.o

### end TEST stuff ###

install:	bininstall

bininstall:	altbininstall
	cp pcgi-wrapper $(BINDIR)
	chmod a+rx $(BINDIR)/pcgi-wrapper
	-if test -f $(BINDIR)/pcgi-wrapper; \
	then rm -f $(BINDIR)/pcgi-wrapper; \
	else true; \
	fi
	(cd $(BINDIR); ln pcgi-wrapper$(VERSION) pcgi-wrapper)

altbininstall:	pcgi-wrapper
	@for i in $(BINDIR); \
	do \
		if test ! -d $$i; then \
			echo "Creating directory $$i"; \
			mkdir $$i; \
			chmod $(DIRMODE) $$i; \
		else	true; \
		fi; \
	done
	$(INSTALL_PROGRAM) pcgi-wrapper $(BINDIR)/pcgi-wrapper$(VERSION)

clean:
	rm -f $(PROGS) *.o *.out core $(creosotedir)/*.o $(testdir)/*.o $(utildir)/*.o Win32/*.obj

distclean:	clean
	rm -f Makefile autoconf.h config.status config.cache config.log *~

tarball:
	cd $(srcdir); mkdir pcgi-$(VERSION)
	cpio -pd < $(MANIFEST) pcgi-$(VERSION)
	tar -czf $(srcdir)/pcgi-$(VERSION).tgz pcgi-$(VERSION)
	rm -rf pcgi-$(VERSION)

# Build the toplevel Makefile
#Makefile:	Makefile.in config.status
#		CONFIG_FILES=Makefile $(SHELL) config.status

# Run the configure script, calling it with --recheck if config.status exists
#config.status:	$(srcdir)/configure
#		if test -f config.status; \
#		then $(SHELL) config.status --recheck; \
#		     $(SHELL) config.status; \
#		else $(SHELL) $(srcdir)/configure $(WITH); \
#		fi

# Rebuild the configure script from configure.in
autoconf:
		(cd $(srcdir); autoconf)
		(cd $(srcdir); autoheader)

