#
# Installation vars
#
afsbackupdir=@afsbackupdir@
afsbosconfigdir=@afsbosconfigdir@
afsconfdir=@afsconfdir@
afsdbdir=@afsdbdir@
afslocaldir=@afslocaldir@
afslogsdir=@afslogsdir@
afssrvbindir=@afssrvbindir@
afskerneldir=@afskerneldir@
afssrvlibexecdir=@afssrvlibexecdir@
afssrvsbindir=@afssrvsbindir@
afsdatadir=@afsdatadir@
bindir=@bindir@
exec_prefix=@exec_prefix@
datarootdir=@datarootdir@
datadir=@datadir@
includedir=@includedir@
libdir=@libdir@
libexecdir=@libexecdir@
localstatedir=@localstatedir@
mandir=@mandir@
prefix=@prefix@
sbindir=@sbindir@
sysconfdir=@sysconfdir@
viceetcdir=@viceetcdir@/
top_builddir=@top_builddir@


#
# Programs and other defines
#
AR = @AR@
AS = @AS@
ASFLAGS = @ASFLAGS@
AFSD_LIBS = @AFSD_LIBS@
AFSD_LDFLAGS = @AFSD_LDFLAGS@
CC = @CC@
CPP = @CPP@
CPPFLAGS_roken = @CPPFLAGS_roken@
CCOBJ = @CCOBJ@
CCXPG2 = @CCXPG2@
CFLAGS = @CFLAGS@
CP = @CP@
DARWIN_INFOFILE=@DARWIN_INFOFILE@
DBG = @DBG@
DEST = @DEST@
DIR_roken = @DIR_roken@
FSINCLUDES = @FSINCLUDES@
GENCAT = @GENCAT@
INCLUDE_LIBINTL = @INCLUDE_libintl@
KERN_DBG = @KERN_DBG@
CTFCONVERT = @CTFCONVERT@
CTFMERGE = @CTFMERGE@
KERN_OPTMZ = @KERN_OPTMZ@
LD = @LD@
LDFLAGS_roken = @LDFLAGS_roken@
LDFLAGS_hcrypto = @LDFLAGS_hcrypto@
LDFLAGS_krb5 = @KRB5_LDFLAGS@
CPPFLAGS_gssapi = @GSSAPI_CPPFLAGS@
LEX = @LEX@
LIB_AFSDB = @LIB_AFSDB@
LIB_crypt = @LIB_crypt@
LIB_curses = @LIB_curses@
LIB_hcrypto = @LIB_hcrypto@
LIB_roken = @LIB_roken@
buildtool_roken = @buildtool_roken@
LIB_krb5 = @KRB5_LIBS@
LIB_gssapi = @GSSAPI_LIBS@
LIBTOOL= @LIBTOOL@
LIBS = @LIBS@
LIB_LIBINTL = @LIB_libintl@
LINUX_KERNEL_PATH = @LINUX_KERNEL_PATH@
LINUX_KERNEL_BUILD = @LINUX_KERNEL_BUILD@
LINUX_LIBAFS_NAME = @LINUX_LIBAFS_NAME@
LINUX_KERNEL_PACKAGING = @LINUX_KERNEL_PACKAGING@
LINUX_VERSION = @LINUX_VERSION@
LINUX_VERS = @LINUX_VERSION@
LWP_OPTMZ = @LWP_OPTMZ@
LWP_DBG = @LWP_DBG@
MKAFS_OSTYPE = @MKAFS_OSTYPE@
AFS_PARAM_COMMON = @AFS_PARAM_COMMON@
MT_CC = @MT_CC@
MT_CFLAGS = @MT_CFLAGS@
MT_LIBS = @MT_LIBS@
MV = @MV@
NO_STRIP_BIN = @NO_STRIP_BIN@
OPTMZ = @OPTMZ@
PAM_CFLAGS = @PAM_CFLAGS@
PAM_LIBS = @PAM_LIBS@
PAM_OPTMZ = @PAM_OPTMZ@
PAM_DBG = @PAM_DBG@
PATH_CPP = @PATH_CPP@
RANLIB = @RANLIB@
REGEX_OBJ = @REGEX_OBJ@
REGEX_OBJ_PIC = @REGEX_OBJ_PIC@
RM = @RM@
RXDEBUG = @RXDEBUG@
ROKEN_HEADERS = @ROKEN_HEADERS@
ROKEN_LTLIBOBJS = @LTLIBOBJS@
SED = @SED@
SHLIB_CFLAGS = @SHLIB_CFLAGS@
SHLIB_LDFLAGS = @SHLIB_LDFLAGS@
SHLIB_LINKER = @SHLIB_LINKER@
SHLIB_SUFFIX = @SHLIB_SUFFIX@
SYS_NAME = @AFS_SYSNAME@
TOP_INCDIR = @TOP_INCDIR@
TOP_LIBDIR = @TOP_LIBDIR@
TOP_JLIBDIR= @TOP_JLIBDIR@
TOP_OBJDIR = @TOP_OBJDIR@
TOP_SRCDIR = @TOP_SRCDIR@
VPATH = ${srcdir}
XCFLAGS64 = @XCFLAGS64@
XCFLAGS = @XCFLAGS@
XLDFLAGS64 = @XLDFLAGS64@
XLDFLAGS = @XLDFLAGS@
XLIBELFA = @XLIBELFA@
XLIBKVM = @XLIBKVM@
XLIBS = @XLIBS@
YACC = @YACC@

#
# Install targets
#

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

#
# Special build targets
#
dest_XFS_SIZE_CHECK = @dest_XFS_SIZE_CHECK@
install_XFS_SIZE_CHECK = @install_XFS_SIZE_CHECK@
XFS_SIZE_CHECK = @XFS_SIZE_CHECK@
AIX32 = @AIX32@
AIX64 = @AIX64@

#
# Paths to build dirs
#
# Could be absolute, but leaving as relative for now
#UKERNELDIR = ${TOP_OBJDIR}/src/libuafs
#KERNELDIR = ${TOP_OBJDIR}/src/libafs
UKERNELDIR = ../libuafs
KERNELDIR = ../libafs

#
# Build helper apps
#
COMPILE_ET = @COMPILE_ET_PATH@
CONFIGTOOL = @CONFIGTOOL_PATH@
RXGEN = @RXGEN_PATH@
SHELL = @SHELL@
LWPTOOL = ${TOP_SRCDIR}/config/lwptool

#
# "Pretty" build line stuff
#

# Default to disabling the "pretty" build lines
# If the user specifies 'V=0', the variables below expand to their _V0
# variants, which enable the "pretty" build lines
V=1

RUNCMD=RUNCMD () { \
	echo "  $$1  $$2"; \
	shift; shift; \
	"$$@" || failcode=$$?; \
	if [ x"$$failcode" != x ] ; then \
		echo >&2; \
		echo "FAILED COMMAND: $$@" >&2; \
		echo >&2; \
		echo "In dir:" >&2; \
		pwd >&2; \
		echo >&2; \
		exit $$failcode; \
	fi; \
	exit 0; \
} ; RUNCMD

RUN_CC_NOQ_V0=${RUNCMD} CC "`pwd`/$@"
RUN_LD_NOQ_V0=${RUNCMD} LD "`pwd`/$@"

# Prefixing a command with $(Q) will suppress that line from being printed
# during a "pretty" make, so the RUNCMD function above can decide itself how
# much to print. The Q is just for "quiet", and Q kinda looks like @.
#
# The _NOQ variants of the RUN_ commands are for when a compiler invocation is
# in the middle of e.g. a switch/case or an if/else, etc. In those cases, we
# want to prefix the _entire_ command with $(Q), not just the compiler, linker,
# etc.
Q_V0=@
Q=$(Q_V$(V))

RUN_CC=$(Q)$(RUN_CC_NOQ_V$(V))
RUN_LD=$(Q)$(RUN_LD_NOQ_V$(V))

RUN_CC_NOQ=$(RUN_CC_NOQ_V$(V))
RUN_LD_NOQ=$(RUN_LD_NOQ_V$(V))

#
# Generate error table header and the source files independently for
# parallel make.
#
COMPILE_ET_H=${COMPILE_ET} -emit h
COMPILE_ET_C=${COMPILE_ET} -emit c

#
# Common/standard cflags/paths/etc
# Cflags defaults, will be overridden later if necessary
#
# -I. and -I${srcdir} are only needed for objdir builds - we should
# conditionalise them on that.

COMMON_INCL=$(MODULE_INCLUDE) -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} \
	    -I${srcdir} -I. 

COMMON_CFLAGS=$(CFLAGS) ${DBG} ${OPTMZ} $(XCFLAGS) \
	      ${COMMON_INCL} ${INCLUDE_LIBINTL} \
	      $(CPPFLAGS_roken) $(ARCHFLAGS)

COMMON_LDFLAGS=$(LDFLAGS) $(LDFLAGS_hcrypto) $(LDFLAGS_roken) $(DBG) $(OPTMZ)

# LWP Flags
LWP_CFLAGS=$(MODULE_CFLAGS) $(COMMON_CFLAGS)
LWP_LDFLAGS=$(MODULE_LDFLAGS) $(COMMON_LDFLAGS) $(XLDFLAGS) $(ARCHFLAGS)
LWP_CCRULE        =$(RUN_CC) $(CCOBJ) $(CPPFLAGS_$(@)) $(LWP_CFLAGS) $(CFLAGS_$(@)) -o $@ -c
LWP_CCRULE_NOQ=$(RUN_CC_NOQ) $(CCOBJ) $(CPPFLAGS_$(@)) $(LWP_CFLAGS) $(CFLAGS_$(@)) -o $@ -c

# Pthreaded
PTH_CFLAGS=$(MODULE_CFLAGS) $(COMMON_CFLAGS) $(MT_CFLAGS)
PTH_LDFLAGS=$(MODULE_LDFLAGS) $(COMMON_LDFLAGS) $(MT_LDFLAGS)
PTH_CCRULE        =$(RUN_CC) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c
PTH_CCRULE_NOQ=$(RUN_CC_NOQ) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c

# Shared
SHD_CFLAGS=$(MODULE_CFLAGS) $(COMMON_CFLAGS) $(MT_CFLAGS) $(SHLIB_CFLAGS)
SHD_LDFLAGS=$(MODULE_LDFLAGS) $(COMMON_LDFLAGS) $(SHLIB_LDFLAGS)
SHD_CCRULE        =$(RUN_CC) $(MT_CC) $(CPPFLAGS_$(@)) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c
SHD_CCRULE_NOQ=$(RUN_CC_NOQ) $(MT_CC) $(CPPFLAGS_$(@)) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c

# Libtool - for objects that are part of pthread-only libraries
LT_CCRULE=$(RUN_CC) $(LIBTOOL) --quiet --mode=compile --tag=CC \
	      $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c

LT_current=0
LT_revision=0
LT_age=0

# Basic rule to link a shared library.
LT_LDLIB_shlib_common=$(LIBTOOL) --quiet --mode=link --tag=CC \
		      $(MT_CC) -rpath $(libdir) \
		      $(PTH_LDFLAGS) $(PTH_CFLAGS) $(LDFLAGS_$(@)) \
		      -o $@ \
		      -version-info $(LT_current):$(LT_revision):$(LT_age)

LT_LDLIB_shlib=$(LT_LDLIB_shlib_common) -export-symbols $(srcdir)/$@.sym

LT_LDLIB_shlib_missing=$(LT_LDLIB_shlib_common) -export-symbols-regex \
	"($$(sed -e 's/^/^/' -e 's/$$/$$|/' -e '$$ s/|$$//' $(srcdir)/$@.sym | \
	tr -d '\n'))"

# Link a static convenience library (contains no PIC code)
LT_LDLIB_static=$(LIBTOOL) --quiet --mode=link --tag=CC \
		 $(MT_CC) -static $(LDFLAGS) $(DBG) $(OPTMZ) \
		 $(LDFLAGS_$(@)) -o $@

# Link a convenience library for use in other libs (contains PIC code)
LT_LDLIB_pic= $(LIBTOOL) --quiet --mode=link --tag=CC \
	       $(MT_CC) $(LDFLAGS) $(DBG) $(OPTMZ) \
	       $(LDFLAGS_$(@)) -o $@

# Libtool - for objects that are built for both pthread and lwp libraries
LTLWP_CCRULE=$(RUN_CC) $(LWPTOOL) --mode compile \
	         --lwpcc "$(CCOBJ)" \
		 --mtcc "$(LIBTOOL) --quiet --mode=compile --tag=CC $(MT_CC) $(MT_CFLAGS)" \
		 -o $@ \
		 -- \
		 $(CPPFLAGS_$(@)) $(MODULE_CFLAGS) $(COMMON_CFLAGS) $(CFLAGS_$(@)) \
		 -c

LT_LDLIB_lwp=$(RUN_LD) $(LWPTOOL) --mode link \
	         --ranlib "$(RANLIB)" \
		 --linker "$(AR) crv" \
		 -o $@ \
		 --

LT_LDLIB_lwp_NOQ=$(RUN_LD_NOQ) $(LWPTOOL) --mode link \
	         --ranlib "$(RANLIB)" \
		 --linker "$(AR) crv" \
		 -o $@ \
		 --

# Use this to link an executable with one or more libtool libraries
LT_LDRULE        = $(RUN_LD) $(LIBTOOL) --quiet --mode=link --tag=CC \
		             $(MT_CC) $(PTH_LDFLAGS) $(PTH_CFLAGS) \
			     $(LDFLAGS_$(@)) -o $@

LT_LDRULE_static = $(RUN_LD) $(LIBTOOL) --quiet --mode=link --tag=CC \
			     $(MT_CC) -static $(PTH_LDFLAGS) $(PTH_CFLAGS) \
			     $(LDFLAGS_$(@)) -o $@

LT_LDRULE_static_NOQ = $(RUN_LD_NOQ) $(LIBTOOL) --quiet --mode=link --tag=CC \
			     $(MT_CC) -static $(PTH_LDFLAGS) $(PTH_CFLAGS) \
			     $(LDFLAGS_$(@)) -o $@

LT_INSTALL_DATA=$(LIBTOOL) --quiet --mode=install $(INSTALL_DATA)
LT_INSTALL_PROGRAM=$(LIBTOOL) --quiet --mode=install $(INSTALL_PROGRAM)

LT_CLEAN=$(RM) -rf .lwp .libs *.la *.lo

# Default rules. These will be overriden if the module Makefile specifically
# includes a particular type (lwp, pthread, or shared)

AFS_LDRULE         =$(RUN_LD) $(CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@
AFS_LDRULE_NOQ =$(RUN_LD_NOQ) $(CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@

RUN_CTFCONVERT=@RUN_CTFCONVERT() { \
    CTFLABEL=$$1 ; \
    CTFDBG=$$2 ; \
    shift ; shift ; \
    if test "x$${CTFDBG}" = "x" ; then exit 0; fi; \
    if test "x${CTFCONVERT}" = "x" ; then exit 0; fi; \
    if test "x${CTFMERGE}" = "x" ; then \
        echo "refusing to run ctfconvert; missing ctfmerge"; \
        exit 1; \
    fi; \
    for t in $$@ ; do \
        echo "${CTFCONVERT} -g -l $${CTFLABEL} $$t"; \
        ${CTFCONVERT} -g -l $${CTFLABEL} $$t; \
    done ; \
} ; RUN_CTFCONVERT

RUN_CTFMERGE=@RUN_CTFMERGE () { \
    CTFLABEL=$$1 ; \
    CTFDBG=$$2 ; \
    shift ; shift ; \
    if test "x$${CTFDBG}" = "x" ; then exit 0; fi; \
    if test "x${CTFMERGE}" = "x" ; then exit 0; fi; \
    if test "x${CTFCONVERT}" = "x" ; then \
        echo "refusing to run ctfmerge; missing ctfconvert"; \
        exit 1; \
    fi; \
    echo "$(CTFMERGE) -g -l $${CTFLABEL} -o $$@"; \
    $(CTFMERGE) -g -l $${CTFLABEL} -o $$@; \
} ; RUN_CTFMERGE

