# ----------------------------------------------------------------
#	libpqc/Makefile
#
#	$Header: Makefile,v 1.2 89/02/04 12:10:58 goh Exp $
# ----------------------------------------------------------------

# ----------------
#    conf.local contains all the configuration definitions
# ----------------

#include "conf.local"

# ----------------
#    libpq sources
# ----------------

SOURCES		=	assert.c \
			blocks.c \
			ccomm.c \
			dumpdata.c \
			error.c \
			exception.c \
			format.c \
			portal.c \
			pqexec.c

# ----------------
#    port.mk contains port-specific information, including
#    PORTSRCDIR and PORTOBJDIR
# ----------------

#include "CONF/port.mk"

# ----------------
#    Derived Sources and Settings
# ----------------
CSOURCES	?=	$(SOURCES:M*.[csy])
LEXSOURCES	?=	$(SOURCES:M*.lex)

COBJS		?=	$(CSOURCES:S/.c/.o/g:S/.s/.o/g:S/.y/.o/g)
LEXOBJS		?=	$(LEXSOURCES:S/.lex/.o/g)

OBJS		?=	$(COBJS) $(LEXOBJS)
DEPENDS		?=	$(COBJS:S/.o/.depend/g)

PMAKE_VPATH_SRCS ?=	./ $(SRCDIR)/$(TARGETDIR) $(PORTSRCDIR)
PMAKE_VPATH_OBJS ?=	./ $(OBJDIR)/$(TARGETDIR) $(PORTOBJDIR)
PMAKE_VPATH_HDRS ?=	$(HDRDIR) \
			$(SRCDIR)/$(TARGETDIR) \
			$(SRCDIR) \
			$(LISPDIR)  $(PORTSRCDIR)

stdout		?=	/dev/tty

# ----------------
#    default.mk contains standard make information like
#    transformation rules, what compiler to use, etc.
#    (and the definition of START)
# ----------------

#include "CONF/default.mk"

# ----------------
#    Targets
# ----------------

HFILES		=	libpq.h

OBJS		=	$(SOURCES:S/.c/.o/g)

IFLAGS=	-I$(HDRDIR)

CFLAGS=	-O $(IFLAGS)

# ----------------
#    taken almost directly from pmake example
# ----------------

.o.a:
	...
	rm -f $(.TARGET:T)

.MAIN:			libpq.a

default: $(START) 	libpq.a

libpq.a: $(START) 	libpq.a($(OBJS))
	ar cru $(.TARGET) $(.OODATE)
	ranlib $(.TARGET)

# ----------------
#    standard instructions...
# ----------------

$(COBJS): $(START) $(CSOURCES)

$(LEXOBJS): $(START) $(LEXSOURCES)

# ----------------
#    Dependencies.mk contains the dependency information
#    (generated by cc -M ..) for the appropriate things
#    in SOURCES.
# ----------------
depends: $(START) Dependencies.mk  
	$(rm) $(DEPENDS)

# ----------------
#    note: we add /dev/null to the cat statement below just in
#    case DEPENDS is null (which is true when there are no sources..)
#
#    also, the awk command is not really necessary but it does compress
#    the size of the dependencies by around 30% so we keep it around..
# ----------------
Dependencies.mk: $(START) $(DEPENDS)  
	$(rm) Dependencies.mk
	$(cat) > Dependencies.mk << E_O_F
	# ----------------
	#    Dependencies for $(TARGETDIR)/Makefile
	#
	#    this file generated by instructions in
	#    $(TARGETDIR)/Makefile for "pmake Depend"
	#    which itself was generated by makecmake.
	# ----------------
	E_O_F
	$(cat) $(DEPENDS) /dev/null | \
	 $(sort) -u | \
	 $(awk) \
	 '{ \
	     if (NF == 2) { \
		if ($1 != prev) { \
		   print rec; \
		   rec = $0; \
		   prev = $1; \
		} else { \
		   if (length(rec $2) > 78) { \
		       print rec; \
		       rec = $0; \
		} else \
		   rec = rec " " $2; \
		} \
	     } \
	  } \
	  END { print rec } ' >> Dependencies.mk
	$(echo) "$(TARGETDIR)/Dependencies.mk created." >> $(stdout)

#ifnmake depends
# ----------------
#    Include dependency information only if we arent in the
#    process of creating it.
# ----------------
#   #include "Dependencies.mk"
#endif

