#!/bin/bash
# The next line finds the path. \
MFPATH=$(cd `dirname $0`; /bin/pwd)/`basename $0`
# The next line restarts with make. \
exec make -f $MFPATH MAKEFILE=$MFPATH "$@"

#############################################
# From here on, this file is parsed by make.
#############################################
# $Id#

EXT=gwlnk
TEMPLATE=/etc/gopherweblink-template.m4

# Run gopherweblink RECURSE=yes if you want to enable recursion.

# RECURSE=yes

####

SRCS := $(wildcard *.$(EXT))
HTML := $(patsubst %.$(EXT),%.html,$(SRCS))

# We do this for the info so it won't complain if there's no .info.

INFOSRC := $(wildcard .info)
INFOLNKS := $(patsubst .info,.infolinks,$(INFOSRC))
DIRS := $(shell if [ "$(RECURSE)" = "yes" ]; then find . -type d -maxdepth 1 | grep -v '^\.$$'; fi)

all: $(HTML) $(INFOLNKS) subdirs $(DIRS)

%.html: %.gwlnk $(TEMPLATE)
	cat $< $(TEMPLATE) | m4 -P > $@

.PHONY: subdirs $(DIRS)

.infolinks: .info $(MAKEFILE)
	perl -x/ $(MAKEFILE) < $< > $@

subdirs: $(DIRS)

$(DIRS):
	$(MAKE) -C $@ -f $(MAKEFILE)

ifeq "BLACK" "WHITE"

#!/usr/bin/perl		[fodder for -x]
$number = 0;
while (defined($line = <STDIN>)) {
	chomp $line;
	$number++;
	print <<"EOF";
Name=$line
Type=i
Path=fake
Numb=$number

EOF
}

__END__
endif
