# $Header: /home/amb/cxref/RCS/Makefile 1.20 1996/06/29 16:43:38 amb Exp $
#
# C Cross Referencing & Documentation tool. Version 1.2.
#
# Program Makefile.
#
# Written by Andrew M. Bishop
#
# This file Copyright 1995,96 Andrew M. Bishop
# It may be distributed under the GNU Public License, version 2, or
# any higher version.  See section COPYING of the GNU Public license
# for conditions under which this file may be redistributed.
#

CC=gcc
CFLAGS=-O2

INCLUDES=

LIB=

COMPILE=$(CC) -c $(CFLAGS)

LINK=$(CC) 

YACC=bison -y -l

LEX=flex

LATEX=latex

# For the default cpp (gcc -E -C -dD)
#CPP_TO_USE=

# For the modified cpp
CPP_TO_USE=/home/amb/cxref/cpp/cxref-cpp -C -dD

########

program : cxref cxref-cpp cxref-query
	@

docs : readme
	$(MAKE) -C doc

all : program docs
	@

####

OBJ_FILES=cxref.o \
          func.o type.o var.o preproc.o comment.o file.o \
          slist.o memory.o \
          xref.o \
          warn-raw.o latex.o latex-style.o \
          html.o \
          parse-lex.o parse-yacc.o

cxref : $(OBJ_FILES)
	$(LINK) $(OBJ_FILES) -o $@ $(LIB)

####

cxref-cpp :
ifeq ($(CPP_TO_USE),)
	@
else
	$(MAKE) -C cpp cxref-cpp
endif

####

cxref-query :
	$(MAKE) -C query cxref-query

####

readme : cxref cxref-cpp README.c
	./cxref -Odoc -NREADME -html -latex README.c
	cp doc/README.c.html README.c.html
	cp doc/README.c.tex  README_c.tex
	$(LATEX) README.tex
	$(LATEX) README.tex
	@rm README.aux README.log README.toc doc/README.*

########

parse-yacc.c : parse.y
	$(YACC) -d $<
	-@mv y.tab.c  parse-yacc.c
	@echo Created parse-yacc.c

parse-yacc.h : parse-yacc.c
	-@if ( cmp -s parse-yacc.h y.tab.h ) ; then : ; else \
           cp y.tab.h parse-yacc.h ; \
	   echo Created parse-yacc.h ; \
        fi

########

parse-lex.c : parse.l
	$(LEX) $<
	-@mv lex.yy.c parse-lex.c
	@echo Created parse-lex.c

########

latex-style.c : doc/fonts.sty doc/page.sty doc/cxref.sty
	@echo '/** The style files needed for LaTeX. **/' >  latex-style.c
	@echo ''                                          >> latex-style.c
	@echo '/*+ The fonts style file as a string. +*/' >> latex-style.c
	@echo 'char *latex_fonts_style='                  >> latex-style.c
	@sed -e 's/\\/\\\\/g' doc/fonts.sty \
	|awk '{print "\"" $$0 "\\n\""}'                   >> latex-style.c
	@echo ';'                                         >> latex-style.c
	@echo ''                                          >> latex-style.c
	@echo '/*+ The page style file as a string. +*/'  >> latex-style.c
	@echo 'char *latex_page_style='                   >> latex-style.c
	@sed -e 's/\\/\\\\/g' doc/page.sty  \
	|awk '{print "\"" $$0 "\\n\""}'                   >> latex-style.c
	@echo ';'                                         >> latex-style.c
	@echo ''                                          >> latex-style.c
	@echo '/*+ The cxref style file as a string. +*/' >> latex-style.c
	@echo 'char *latex_cxref_style='                  >> latex-style.c
	@sed -e 's/\\/\\\\/g' doc/cxref.sty \
	|awk '{print "\"" $$0 "\\n\""}'                   >> latex-style.c
	@echo ';'                                         >> latex-style.c
	@echo Created latex-style.c

########

%.o:%.c
	$(COMPILE) $< -o $@ $(INCLUDES)

cxref.o      : cxref.c      cxref.h datatype.h   memory.h parse-yy.h
ifeq ($(CPP_TO_USE),)
	$(COMPILE) $< -o $@ $(INCLUDES)
else
	$(COMPILE) $< -o $@ '-DCXREF_CPP="$(CPP_TO_USE)"' $(INCLUDES)
endif

func.o       : func.c       cxref.h datatype.h   memory.h
type.o       : type.c       cxref.h datatype.h   memory.h
var.o        : var.c        cxref.h datatype.h   memory.h
comment.o    : comment.c    cxref.h datatype.h   memory.h
file.o       : file.c       cxref.h datatype.h   memory.h
preproc.o    : preproc.c    cxref.h datatype.h   memory.h

slist.o      : slist.c      cxref.h datatype.h   memory.h
memory.o     : memory.c                          memory.h

xref.o       : xref.c       cxref.h datatype.h   memory.h
warn-raw.o   : warn-raw.c   cxref.h datatype.h   memory.h
latex.o      : latex.c      cxref.h datatype.h   memory.h
latex-style.o : latex-style.c
html.o       : html.c       cxref.h datatype.h   memory.h

parse-yacc.o : parse-yacc.c cxref.h parse-yacc.h memory.h parse-yy.h
parse-lex.o  : parse-lex.c  cxref.h parse-yacc.h memory.h parse-yy.h

########

clean :
	-rm -f core *.o *~ parse-lex.* parse-yacc.* lex.*.c y.tab.* latex-style.c

########
