CC=cc
LDOPTIONS=-shared
LD=ld
CCFLAGS=
LIBS=-lm -ldl -lpthread
OBJS=builder.o conftree.o dynlolib.o execute.o\
     expression.o filesys.o getopt.o lexer.o match.o\
     memory.o myalloc.o options.o reader.o report.o sym.o\
     syntax.o errcodes.o hookers.o modumana.o extops.o\
     uniqfnam.o epreproc.o md5.o scriba.o
COBJS=environ.o external.o file.o function.o goto.o\
      if.o let.o mathfunc.o mathops.o print.o\
      string.o time.o while.o logger.o thread.o hndlptr.o\
      mygmtime.o
CHEADERS=command.h errcodes.h report.h sym.h\
         lexer.h expression.h builder.h memory.h\
         syntax.h execute.h syntax.h myalloc.h filesys.h\
         options.h uniqfnam.h

.PHONY: headers clean install all

all: headers scriba cftc cgi.so hash.so re.so basicc.a 
	sh install.sh

clean :
	rm *.so *.o *.h ./scriba

headers : *.c extensions/cgi/cgi.c
	perl headerer.pl $?

mod_scriba.a : $(OBJS) $(COBJS) mod_scriba.o
	ar -r mod_scriba.a $(OBJS) $(COBJS) mod_scriba.o

mod_scriba.o : variations/apacmodu/mod_scriba.c report.h\
             lexer.h sym.h expression.h syntax.h reader.h myalloc.h\
             builder.h memory.h execute.h buildnum.h conftree.h\
             filesys.h
	$(CC) $(CCFLAGS) -c -o mod_scriba.o variations/apacmodu/mod_scriba.c

scriba	: $(OBJS) $(COBJS) scribacmd.o
	$(CC) -o scriba $(LIBS) $(OBJS) $(COBJS) scribacmd.o
	scriba -v

cftc : cftc.o confpile.o conftree.o lsp.o
	$(CC) -o cftc $(LIBS) cftc.o confpile.o conftree.o lsp.o

cftc.o : cftc.c
	$(CC) $(CCFLAGS) -c -o cftc.o cftc.c

confpile.o : confpile.c
	$(CC) $(CCFLAGS) -c -o confpile.o confpile.c

lsp.o : lsp.c
	$(CC) $(CCFLAGS) -c -o lsp.o lsp.c

hash.so : hash.o
	$(LD) $(LDOPTIONS) -o hash.so hash.o -lc

re.so : reinterf.o regcomp.o regerror.o regexec.o regfree.o
	$(LD) $(LDOPTIONS) -o re.so reinterf.o regcomp.o regerror.o regexec.o regfree.o -lc

cgi.so : cgi.o cgiinterface.o
	$(LD) $(LDOPTIONS) -o cgi.so cgi.o cgiinterface.o -lc

basicc.a : $(OBJS) $(COBJS) basicc.o
	ar -r basicc.a $(OBJS) $(COBJS) basicc.o

scribacmd.o : variations/standard/scribacmd.c getopt.h report.h\
             lexer.h sym.h expression.h syntax.h reader.h myalloc.h\
             builder.h memory.h execute.h buildnum.h conftree.h\
             filesys.h 
	$(CC) $(CCFLAGS) -c -o scribacmd.o variations/standard/scribacmd.c

basicc.o : variations/standalone/basicc.c getopt.h report.h\
             lexer.h sym.h expression.h syntax.h reader.h myalloc.h\
             builder.h memory.h execute.h buildnum.h conftree.h\
             filesys.h 
	$(CC) $(CCFLAGS) -c -o basicc.o variations/standalone/basicc.c

hash.o : extensions/hash/hash.c 
	$(CC) $(CFLAGS) -c -o hash.o extensions/hash/hash.c

reinterf.o : extensions/re/reinterf.c
	$(CC) $(CFLAGS) -c -o reinterf.o extensions/re/reinterf.c

regcomp.o : extensions/re/hsregex/regcomp.c
	$(CC) $(CFLAGS) -c -o regcomp.o extensions/re/hsregex/regcomp.c

regerror.o : extensions/re/hsregex/regerror.c
	$(CC) $(CFLAGS) -c -o regerror.o extensions/re/hsregex/regerror.c

regexec.o : extensions/re/hsregex/regexec.c
	$(CC) $(CFLAGS) -c -o regexec.o extensions/re/hsregex/regexec.c

regfree.o : extensions/re/hsregex/regfree.c
	$(CC) $(CFLAGS) -c -o regfree.o extensions/re/hsregex/regfree.c

cgi.o : extensions/cgi/cgi.c extensions/cgi/cgi.h
	$(CC) $(CFLAGS) -c -o cgi.o extensions/cgi/cgi.c

cgiinterface.o : extensions/cgi/cginterf.c extensions/cgi/cgi.h
	$(CC) $(CFLAGS) -c -o cgiinterface.o extensions/cgi/cginterf.c

scriba.o : scriba.c
	$(CC) $(CCFLAGS) -c -o scriba.o scriba.c

builder.o : builder.c filesys.h report.h lexer.h sym.h\
            expression.h myalloc.h builder.h errcodes.h buildnum.h
	$(CC) $(CCFLAGS) -c -o builder.o builder.c

conftree.o : conftree.c conftree.h errcodes.h filesys.h
	$(CC) $(CCFLAGS) -c -o conftree.o conftree.c

dynlolib.o : dynlolib.c
	$(CC) $(CCFLAGS) -c -o dynlolib.o dynlolib.c

execute.o : execute.c sym.h errcodes.h report.h lexer.h\
            expression.h builder.h memory.h syntax.h execute.h myalloc.h
	$(CC) $(CCFLAGS) -c -o execute.o execute.c

expression.o : expression.c errcodes.h report.h lexer.h\
               sym.h expression.h myalloc.h
	$(CC) $(CCFLAGS) -c -o expression.o expression.c

filesys.o : filesys.c filesys.h errcodes.h
	$(CC) $(CCFLAGS) -c -o filesys.o filesys.c

getopt.o : getopt.c
	$(CC) $(CCFLAGS) -c -o getopt.o getopt.c

lexer.o : lexer.c errcodes.h report.h lexer.h
	$(CC) $(CCFLAGS) -c -o lexer.o lexer.c

match.o : match.c match.h errcodes.h
	$(CC) $(CCFLAGS) -c -o match.o match.c

logger.o : logger.c logger.h
	$(CC) $(CCFLAGS) -c -o logger.o logger.c

mygmtime.o : mygmtime.c mygmtime.h
	$(CC) $(CCFLAGS) -c -o mygmtime.o mygmtime.c

thread.o : thread.c thread.h
	$(CC) $(CCFLAGS) -c -o thread.o thread.c

hndlptr.o : hndlptr.c hndlptr.h
	$(CC) $(CCFLAGS) -c -o hndlptr.o hndlptr.c

memory.o : memory.c errcodes.h memory.h myalloc.h
	$(CC) $(CCFLAGS) -c -o memory.o memory.c

modumana.o : modumana.c basext.h sym.h errcodes.h report.h lexer.h expression.h\
	     builder.h memory.h syntax.h execute.h myalloc.h\
	     dynlolib.h modumana.h
	$(CC) $(CCFLAGS) -c -o modumana.o modumana.c

hookers.o : hookers.c basext.h sym.h errcodes.h report.h lexer.h\
	    expression.h builder.h memory.h syntax.h execute.h\
	    myalloc.h dynlolib.h hookers.h
	$(CC) $(CCFLAGS) -c -o hookers.o hookers.c

myalloc.o : myalloc.c myalloc.h
	$(CC) $(CCFLAGS) -c -o myalloc.o myalloc.c

epreproc.o : epreproc.c epreproc.h myalloc.h
	$(CC) $(CCFLAGS) -c -o epreproc.o epreproc.c

options.o : options.c sym.h errcodes.h report.h lexer.h\
            expression.h builder.h memory.h syntax.h execute.h myalloc.h
	$(CC) $(CCFLAGS) -c -o options.o options.c

reader.o : reader.c filesys.h report.h errcodes.h conftree.h reader.h
	$(CC) $(CCFLAGS) -c -o reader.o reader.c

report.o : report.c report.h errcodes.h
	$(CC) $(CCFLAGS) -c -o report.o report.c

sym.o : sym.c sym.h
	$(CC) $(CCFLAGS) -c -o sym.o sym.c

uniqfnam.o : uniqfnam.c uniqfnam.h
	$(CC) $(CCFLAGS) -c -o uniqfnam.o uniqfnam.c

md5.o : tools/md5.c tools/md5.h tools/global.h
	$(CC) $(CCFLAGS) -c -o md5.o tools/md5.c

errcodes.c : errors.def
	perl generrh.pl

errcodes.o : errcodes.c errcodes.h
	$(CC) $(CCFLAGS) -c -o errcodes.o errcodes.c

syntax.c : syntax.def
	perl syntaxer.pl

syntax.o : syntax.c report.h lexer.h sym.h expression.h syntax.h
	$(CC) $(CCFLAGS) -c -o syntax.o syntax.c

command.h : command.c
	perl headerer.pl command.c

extops.o : commands/extops.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o extops.o commands/extops.c

environ.o : commands/environ.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o environ.o commands/environ.c

external.o : commands/external.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o external.o commands/external.c

file.o : commands/file.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o file.o commands/file.c

function.o : commands/function.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o function.o commands/function.c

goto.o : commands/goto.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o goto.o commands/goto.c

if.o : commands/if.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o if.o commands/if.c

let.o : commands/let.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o let.o commands/let.c

mathfunc.o : commands/mathfunc.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o mathfunc.o commands/mathfunc.c

mathops.o : commands/mathops.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o mathops.o commands/mathops.c

print.o : commands/print.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o print.o commands/print.c

string.o : commands/string.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o string.o commands/string.c

time.o : commands/time.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o time.o commands/time.c

while.o : commands/while.c $(CHEADERS)
	$(CC) $(CCFLAGS) -c -o while.o commands/while.c

