#####################################################################
#
#   Makefile for the GNU cfengine
#
#####################################################################

HEADERS = cf.defs.h conf.h cfd.h

OBJ = cfengine.o             \
      client.o               \
      process.o              \
      ifconf.o               \
      image.o                \
      item.o                 \
      item-extended.o        \
      2Dlist.o               \
      globals.o              \
      classes.o              \
      misc.o                 \
      parse.o                \
      edittools.o            \
      patches.o              \
      install.o              \
      link.o                 \
      tidy.o                 \
      filedir.o              \
      eval.o                 \
      modes.o                \
      locks.o                \
      mount.o                \
      macro.o                \
      shared.o               \
      varstring.o            \
      wildcard.o             \
      cfparse.o              \
      comparray.o            \
      checksums.o            \
      proto.o                \
      cflex.o                \
      df.o

SERVER_OBJ = cfd.o       \
             parse.o     \
             install.o   \
             cfparse.o   \
             cflex.o     \
             item.o      \
             item-extended.o \
             varstring.o \
             globals.o   \
             shared.o      \
             macro.o     \
             eval.o      \
             classes.o   \
             misc.o      \
             2Dlist.o    \
             modes.o     \
             locks.o     \
             wildcard.o  \
             link.o

CFRUN_OBJ =  cfrun.o     \
             item.o      \
             shared.o    \
             locks.o     \
             proto.o     \
             globals.o

#
# For IRIX (since configure is used, can this be removed?)
#

SCI_CC = -cckr

#
# General stuff
#

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@

CC= @CC@

YACC= @YACC@
YFLAGS= -d

LEX= @LEX@
LEXLIB = @LEXLIB@

LDFLAGS= @LDFLAGS@
LIBS= @LIBS@

DEFS= @DEFS@
CFLAGS= @CFLAGS@
CPPFLAGS= @CPPFLAGS@

INSTALL= @INSTALL@
INSTALL_PROGRAM= @INSTALL_PROGRAM@

MKINSTALLDIR= @top_srcdir@/bin/mkinstalldirs

RM = rm -f

#####################################################################
# Rules
######################################################################

all: cfengine cfd cfrun
	chmod 755 cfengine cfd cfrun

cfengine: ${OBJ} ../pub/libcfpub.a
	${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS} ${LEXLIB}
 
cfd: ${SERVER_OBJ}
	${CC} ${LDFLAGS} -o $@ ${SERVER_OBJ} ${LIBS} ${LEXLIB}

cfrun: ${CFRUN_OBJ}
	${CC} ${LDFLAGS} -o $@ ${CFRUN_OBJ} ${LIBS} ${LEXLIB}

${OBJ}: ${HEADERS}

${SERVER_OBJ}: ${HEADERS}

../pub/libcfpub.a:
	(cd ../pub;	$(MAKE) all)

y.tab.h:
	touch y.tab.h

#######################################################################
# Suffix rule
#######################################################################

.c.o: 
	${CC} -c ${CPPFLAGS} ${CFLAGS} ${DEFS} $<

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

clean:
	${RM} ${OBJ} ${SERVER_OBJ} ${CFRUN_OBJ}
	${RM} y.tab.c lex.yy.c y.tab.h
	${RM} y.tab lex.yy cflex.c
	${RM} *% *~ *.o
	${RM} *.tab.c *.tab.h a.out

mostlyclean: clean
	${RM} *.tar.*

distclean: mostlyclean
	${RM} cfengine conf.h Makefile cfd cfrun

install: all
	${MKINSTALLDIR} ${bindir}
	${INSTALL_PROGRAM} cfengine ${bindir}
	${INSTALL_PROGRAM} cfd ${bindir}
	${INSTALL_PROGRAM} cfrun ${bindir}

dist:
	(cd ${top_srcdir}; $(MAKE) dist)
