#$Id: Makefile.in,v 1.91 2002/02/03 10:56:41 dolecek Exp $

# soubor Makefile je generovan skriptem configure na zaklade souboru
# Makefile.in; zmeny tedy provadejte v Makefile.in, jinak budou ztraceny
# pri dalsim spusteni skriptu configure

CC 	= @CC@
LIBS 	= @LIBS@

CDEFS   = -DCSACEK -DCSA_MUTACE_@MUTACE_CANON@
CFLAGS	= @OPT@ @CFLAGS@ $(CDEFS)
TARGET  = @compile_target@
LINT_FLAGS = -ipezghxc

CGI_OBJS    = @CGI_OBJS@
CGI_LINTFILES = @CGI_LINTFILES@
APACHE_SRCS = @APACHE_SRCS@
FILE_OBJS   = @FILE_OBJS@

SHELL 	= @SHELL@
LN_S 	= @LN_S@
STRIP	= @STRIP@
RM	= @RM@
RANLIB	= @RANLIB@
BISON	= @BISON@
LINT	= @LINT@
APXS	= @APXS@
APXS_OPTIONS = -c ${LIBS} mod_csacek.c

SUFFIX 	= @program_suffix@

CGI_CODES = @CGI_CODES@
PARTLIST = @PARTLIST@
MUTACE   = @MUTACE@

# directory, where all the binaries and symbolic links should go
COMPILEDIR = @COMPILEDIR@

TARGET_CODE = ASCII
BINARY = to$(TARGET_CODE)$(SUFFIX)
CGI_TARGET_LINKED = .cgi_target_linked

VERSION  = `grep CSA_VERSION csa_version.h | sed 's/.*\"\(.*\)\".*/\1/'`
TEMPLATEDIR = `grep CSA_TEMPLATEDIR csa_config.h | sed 's/.*\"\(.*\)\".*/\1/'`
CSA_HEADERS = csacek.h csa_config.h csa_defaults.h cstools.h csa_compat.h

.SUFFIXES: .c .o .E .ln

all: $(TARGET)
	@echo
	@echo "   Budovani C-SaCzech $(VERSION), mutace $(MUTACE) hotovo."
	@echo "   Muzete postupovat dale podle instrukci v souboru INSTALL."
	@echo

CGI: $(COMPILEDIR)/$(BINARY) $(CGI_TARGET_LINKED)

$(COMPILEDIR)/$(BINARY): $(COMPILEDIR) $(CGI_OBJS)
	$(RM) -f $(COMPILEDIR)/$(BINARY)
	$(CC) -o $(COMPILEDIR)/$(BINARY) $(CGI_OBJS) $(LIBS)
	-$(STRIP) $(COMPILEDIR)/$(BINARY)

APACHE: mod_csacek.so

mod_csacek.so: mod_csacek.c
	@if echo $(LIBS) | grep lz >/dev/null 2>&1; then \
		echo;					 \
		echo Pouziva se systemova knihovna: -lz; \
		echo;					 \
	 fi
	@echo Kompilace s apxs: ${APXS} ${APXS_OPTIONS}
	@-rm -f $@
	@${APXS} ${APXS_OPTIONS}

mod_csacek.c: $(APACHE_SRCS) $(CSA_HEADERS) csa_version.h
	cat $(APACHE_SRCS) >$@

FILE: ${FILE_OBJS}
	${CC} -o csacek.file ${FILE_OBJS} ${LIBS}

$(CGI_TARGET_LINKED):
	for part in $(PARTLIST) XXX_CSACEK; do \
	  if test $$part = XXX_CSACEK; then\
		part="";\
	  else\
		part=".$$part";\
	  fi;\
	  for code in $(CGI_CODES) GUESS __CHARSET__ whichcode; do \
		if test $$code != whichcode; then \
			code="to$$code";\
		fi;\
		if test X$$part != X -o $$code != to$(TARGET_CODE); then\
	  	    `echo $(LN_S)` $(BINARY) $(COMPILEDIR)/$$code$$part$(SUFFIX); \
		fi;\
	  done; \
	done
	@touch $@

$(COMPILEDIR):
	mkdir $(COMPILEDIR)

clean: $(TARGET)_clean 
	rm -f *.ln csacek_$(TARGET)_linted 

realclean: clean
	rm -f config.cache config.log config.status Makefile csa_config.h

CGI_clean: 
	for code in $(CGI_CODES) GUESS __CHARSET__ whichcode; do \
	  if test $$code != whichcode; then \
                code="to$$code"; \
          fi;\
	  $(RM) -f $(COMPILEDIR)/$$code$(SUFFIX); \
	  for part in $(PARTLIST); do \
            part=".$$part";\
	    $(RM) -f $(COMPILEDIR)/$$code$$part$(SUFFIX) ; \
	  done; \
	done;
	-$(RM) -f $(BINARY).core core *.o $(CGI_TARGET_LINKED)

APACHE_clean:
	$(RM) -f mod_csacek.c mod_csacek.o mod_csacek-so.o mod_csacek.so

FILE_clean:
	${RM} -f ${FILE_OBJS} csacek.file

lint: $(TARGET)_lint

CGI_lint: $(CGI_LINTFILES)
	$(LINT) $(LINT_FLAGS) $> $(LIBS)

APACHE_lint: 
	@echo "Nothing to be linted"

cmds.c: cmds.y
	$(BISON) -p csa_yy -d $<
	sed -f scripts/rmbisonjunk.sed *.tab.c > $@
	sed -f scripts/protectheader.sed *.tab.h >csa_`basename $@ .c`.h 
	$(RM) -f *.tab.?

csa_cmds.h: cmds.c

.c.o: $< $(CSA_HEADERS)
	$(CC) $(CFLAGS) $(DEBUG) -c $<

# to test results of preprocessing
.c.E: $< $(CSA_HEADERS)
	$(CC) $(CFLAGS) $(DEBUG) -E $< > $@

# linting
.c.ln: $< $(CSA_HEADERS)
	$(LINT) $(LINT_FLAGS) $(CDEFS) $<

# dependencies
cmds.o: cmds.c csa_cmds.h
http.o: csa_version.h
info.o: csa_version.h
loop.o: csa_cmds.h csa_version.h
share.o: csa_version.h
