# $Id: PTMakefile,v 1.1 1999/03/11 15:00:33 carlo Exp $
#
# ProtoType Test Makefile
#
# Copyright (C) 1999
#
# 1024/624ACAD5 1997/01/26 Carlo Wood, Run on IRC <carlo@runaway.xs4all.nl>
# Key fingerprint = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
#
# All rights reserved.
#
# See the file LICENSE for copyright information.
#
# This file may be distributed under the terms of the Q Public License 1.0
# as defined by Troll Tech AS of Norway and appearing in the file LICENSE.QPL
# included in the packaging of this file.
#
#-----------------------------------------------------------------------------
#
# Edit $PROTODIR/Makedefs.h to get it working for your system
#

include ${PROTODIR}/Makedefs.h

OBJS:=$(shell echo "${SRC}" | sed -e 's%\.c %.o %g' -e 's%\.c$$%.o%' -e 's%\.cc %.o %g' -e 's%\.cc$$%.o%')

MAIN=${OBJS:.o=}

LIBRTESTMAKEFILE="yes"

.PHONY: all build subdirs printobjs clean depend ${STATICLIBS}
.SUFFIXES:

%.o: %.c Makefile ${PROTODIR}/Makedefs.h
	${CC} ${CFLAGS} ${INCLUDEFLAGS} -I- ${SYSTEMINCLUDEFLAGS} -c $*.c

%.o: %.cc Makefile ${PROTODIR}/Makedefs.h
	${CC} ${CFLAGS} ${INCLUDEFLAGS} -I- ${SYSTEMINCLUDEFLAGS} -c $*.cc

all:
	${MAKE} -r -C ${BASEDIR} all

build:: .depend subdirs ${MAIN}

subdirs:
	@for i in ${SUBDIRS}; do ${MAKE} -C $$i build || exit; done

# The trick with the 'ifeq' is necessary because '$@' isn't understood as dependency.
# Otherwise we could have used '$@' instead of ${EXECUTABLE_NAME} everywhere.
ifeq ($(EXECUTABLE_NAME),)
${MAIN}: phony
	@${MAKE} EXECUTABLE_NAME=$@ $@
phony:
else
# Assume all libraries are up to date
${MAIN}: ${EXECUTABLE_NAME}.o ${EXTRA_OBJS}
	${CC} ${LDFLAGS} ${EXECUTABLE_NAME}.o ${EXTRA_OBJS} ${STATICLIBS} \
	    ${LIBFLAGS} ${SHAREDLIBS} -o ${EXECUTABLE_NAME}
	${CHMOD} ${MODE} ${EXECUTABLE_NAME}
endif

printobjs:

clean::
	${RM} -f *.o core *.orig ${MAIN} gmon.out .depend*
	@for i in ${SUBDIRS}; do ${MAKE} -C $$i clean; done

depend:: .depend
	@for i in ${SUBDIRS}; do ${MAKE} -C $$i depend || exit; done

.depend: ${SRC}
	@${RM} -f .depend
	@echo '# Program dependencies' >.depend
	@if ${TEST} ! -z "${SRC}"; then \
	  ${MAKEDEPEND} ${CFLAGS} ${INCLUDEFLAGS} -I- ${SYSTEMINCLUDEFLAGS} ${SRC} >> .depend; \
        fi

#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
