WHAT=unix
CFLAGS = $(CCOPTS) $(DEFS) $(DEFINES)
DEFINES=-I$(srcdir)/../../include/kerberosIV

##DOSBUILDTOP = ..\..\..
##DOSLIBNAME=..\krb5.lib
##DOS!include $(BUILDTOP)\config\windows.in

EHDRDIR=$(BUILDTOP)$(S)include

.c.o:
	$(CC) $(CFLAGS) -c $(srcdir)/$*.c
@SHARED_RULE@

OBJS	= \
	cr_auth_repl.$(OBJEXT) \
	cr_ciph.$(OBJEXT) \
	cr_tkt.$(OBJEXT) \
	debug.$(OBJEXT) \
	decomp_tkt.$(OBJEXT) \
	err_txt.$(OBJEXT) \
	g_ad_tkt.$(OBJEXT) \
	g_in_tkt.$(OBJEXT) \
	g_phost.$(OBJEXT) \
	g_pw_in_tkt.$(OBJEXT) \
	g_pw_tkt.$(OBJEXT) \
	g_tkt_svc.$(OBJEXT) \
	gethostname.$(OBJEXT) \
	getst.$(OBJEXT) \
	kname_parse.$(OBJEXT) \
	mk_auth.$(OBJEXT) \
	mk_err.$(OBJEXT) \
	mk_priv.$(OBJEXT) \
	mk_req.$(OBJEXT) \
	mk_safe.$(OBJEXT) \
	month_sname.$(OBJEXT) \
	one.$(OBJEXT) \
	pkt_cipher.$(OBJEXT) \
	pkt_clen.$(OBJEXT) \
	rd_err.$(OBJEXT) \
	rd_priv.$(OBJEXT) \
	rd_safe.$(OBJEXT) \
	send_to_kdc.$(OBJEXT) \
	stime.$(OBJEXT) \
	rd_preauth.$(OBJEXT) \
	mk_preauth.$(OBJEXT) \
	unix_time.$(OBJEXT) \
	$(CACHEOBJS) $(SETENVOBJS) $(STRCASEOBJS) $(SHMOBJS) \
	$(LIB_KRB_HOSTOBJS) $(SERVER_KRB_OBJS) $(NETIO_OBJS) $(REALMDBOBJS)

SRCS = \
	$(srcdir)/cr_auth_repl.c \
	$(srcdir)/cr_ciph.c \
	$(srcdir)/cr_tkt.c \
	$(srcdir)/debug.c \
	$(srcdir)/decomp_tkt.c \
	$(srcdir)/g_ad_tkt.c \
	$(srcdir)/g_pw_in_tkt.c \
	$(srcdir)/g_phost.c \
	$(srcdir)/g_pw_tkt.c \
	$(srcdir)/g_tkt_svc.c \
	$(srcdir)/getst.c \
	$(srcdir)/gethostname.c \
	$(srcdir)/kname_parse.c \
	$(srcdir)/err_txt.c \
	$(srcdir)/g_in_tkt.c \
	$(srcdir)/mk_auth.c \
	$(srcdir)/mk_err.c \
	$(srcdir)/mk_priv.c \
	$(srcdir)/mk_req.c \
	$(srcdir)/mk_safe.c \
	$(srcdir)/month_sname.c \
	$(srcdir)/one.c \
	$(srcdir)/pkt_cipher.c \
	$(srcdir)/pkt_clen.c \
	$(srcdir)/rd_err.c \
	$(srcdir)/rd_priv.c \
	$(srcdir)/rd_safe.c \
	$(srcdir)/send_to_kdc.c \
	$(srcdir)/stime.c \
	$(srcdir)/rd_preauth.c \
	$(srcdir)/mk_preauth.c \
	$(srcdir)/unix_time.c \
	$(CACHESRCS) $(SETENVSRCS) $(STRCASESRCS) $(SHMSRCS) \
	$(LIB_KRB_HOSTSRCS) $(SERVER_KRB_SRCS) $(NETIO_SRCS) $(REALMDBSRCS)


LIB_SUBDIRS= .
LIBDONE= DONE
#
# Depends on libcrypto and KRB4_CRYPTO_LIB, expect one unresolved symbol:
#	_et_list.
#
KRB4_CRYPTO_LIBS=@KRB4_CRYPTO_LIB@
DEPKRB4_LIBS=@DEPKRB4_CRYPTO_LIB@
DEPLIBS=$(TOPLIBD)/libcrypto.$(SHEXT)
SHLIB_LIBS=$(KRB4_CRYPTO_LIBS) -lcrypto -lcom_err
SHLIB_LDFLAGS= $(LDFLAGS) @SHLIB_RPATH_DIRS@ 
SHLIB_LIBDIRS= @SHLIB_LIBDIRS@

#
# These objects implement ticket cacheing for Unix.  They are
# replaced by other files when compiling for Windows or Mac.
#
CACHESRCS=$(srcdir)/tf_util.c $(srcdir)/dest_tkt.c $(srcdir)/in_tkt.c \
	$(srcdir)/tkt_string.c $(srcdir)/g_tf_fname.c \
	$(srcdir)/g_tf_realm.c $(srcdir)/g_cred.c $(srcdir)/save_creds.c
CACHEOBJS=tf_util.$(OBJEXT) dest_tkt.$(OBJEXT) in_tkt.$(OBJEXT) \
	tkt_string.$(OBJEXT) g_tf_fname.$(OBJEXT) g_tf_realm.$(OBJEXT) \
	g_cred.$(OBJEXT) save_creds.$(OBJEXT)

#
# These objects implement Kerberos realm<->host database lookup.
# They read config files and/or network databases in various ways
# on various platforms.
#
REALMDBSRCS= $(srcdir)/g_cnffile.c $(srcdir)/g_krbhst.c $(srcdir)/g_krbrlm.c \
	$(srcdir)/g_admhst.c $(srcdir)/realmofhost.c 
REALMDBOBJS= g_cnffile.$(OBJEXT) g_krbhst.$(OBJEXT) g_krbrlm.$(OBJEXT) \
	g_admhst.$(OBJEXT) realmofhost.$(OBJEXT) 

#
# These objects are only used on server or debug implementations of Kerberos,
# and they cause some major or minor sort of trouble for some
# client-only platform (Mac or Windows).
#
SERVER_KRB_SRCS=$(srcdir)/klog.c $(srcdir)/kuserok.c $(srcdir)/log.c \
		$(srcdir)/kntoln.c $(srcdir)/fgetst.c $(srcdir)/rd_svc_key.c \
		$(srcdir)/cr_err_repl.c $(srcdir)/rd_req.c \
		$(srcdir)/g_svc_in_tkt.c $(srcdir)/recvauth.c \
		krb_err.c $(srcdir)/ad_print.c \
		$(srcdir)/cr_death_pkt.c $(srcdir)/kparse.c \
		$(srcdir)/put_svc_key.c $(srcdir)/sendauth.c 
SERVER_KRB_OBJS=klog.$(OBJEXT) kuserok.$(OBJEXT) log.$(OBJEXT) \
		kntoln.$(OBJEXT) \
		fgetst.$(OBJEXT) rd_svc_key.$(OBJEXT) cr_err_repl.$(OBJEXT) \
		rd_req.$(OBJEXT) g_svc_in_tkt.$(OBJEXT) recvauth.$(OBJEXT) \
		krb_err.$(OBJEXT) ad_print.$(OBJEXT) cr_death_pkt.$(OBJEXT) \
		kparse.$(OBJEXT) put_svc_key.$(OBJEXT) sendauth.$(OBJEXT)
#
# These objects are included on Unix and Windows (for kstream and kadm)
# but not under Mac (there are no file descriptors).
#
NETIO_SRCS=$(srcdir)/netread.c $(srcdir)/netwrite.c
NETIO_OBJS=netread.$(OBJEXT) netwrite.$(OBJEXT)

#
# These objects glue the Kerberos library to the operating system
# (time-of-day access, etc).  They are replaced in Mac and Windows
# by other _glue.* routines.
#
LIB_KRB_HOSTSRCS=$(srcdir)/unix_glue.c
LIB_KRB_HOSTOBJS=unix_glue.$(OBJEXT)

LIBNAME=libkrb4.$(STEXT)

ARCHIVEARGS= $@ $(OBJS)

CODE=$(SRCS) Makefile.in krb_err.et

all:: all-really

#### include configury here
##DOS!include ..\..\config\common
##DOS!include ..\..\config\mt-win

# We only have a final value of $(WHAT) at this point, and Microsoft
# NMAKE expands the macros in dependency lines before it finishes reading
# the whole file (sigh)...
all-really:: all-$(WHAT)
install:: install-$(WHAT)

# We want *library* compiler options...
DBG=$(DBG_LIB)

all-unix:: shared  krb_err.h includes

shared:
	mkdir shared

# comp_et_depend(krb_err)
krb_err.h:: krb_err.et
krb_err.c: krb_err.et

krb_err.o: krb_err.c
	$(CC) $(CFLAGS) -c krb_err.c
@SHARED_RULE_LOCAL@

depend:: krb_err.h
#

depend:: $(CODE) 

#install-unix::
#	$(INSTALL_DATA) krb_err.h $(DESTDIR)$(KRB5_INCDIR)/kerberosIV/krb_err.h


DEFINES=$(FALLBACK) $(OLD_SRVTAB) $(OLD_KLOGIN) -I$(srcdir)/../../include/kerberosIV

$(LIBNAME): $(OBJS)
	$(RM) $@
	$(ARCHIVE) $(ARCHIVEARGS)
	$(RANLIB) $@

#
# What we build for `all' and `install' targets on Windows
#
all-windows: winsock.lib kerberos.lib kerberos.dll

install-windows:
	copy winsock.lib  ..\..\floppy
	copy kerberos.lib ..\..\floppy
	copy kerberos.dll ..\..\floppy

#
# The "Import Library" definitions for MS-Windows
#
kerberos.lib: kerberos.dll
	implib /nologo $@ $(@R).dll

winsock.lib:  winsock.def
	implib /nologo winsock.lib winsock.def

#
# The Kerberos "Dynamic Link Library" for MS-Windows
#
kerberos.dll: kerberos.def winsock.lib \
	$(DES_LIB_FOR_DLL) $(KADM_LIB_FOR_DLL) $(KSTREAM_LIB_FOR_DLL) \
	$(LIBNAME)
	$(RM) $@
# this a.def and a.dll stuff is for line-too-long crap
	copy kerberos.def a.def
	copy $(DES_LIB_FOR_DLL)     a.lib
	copy $(KADM_LIB_FOR_DLL)    b.lib
	copy $(KSTREAM_LIB_FOR_DLL) c.lib
	link /nologo /noe debug, $@,,\
		$(LIBNAME) a.lib b.lib c.lib\
		winsock ldllcew libw, $(@R).def
	del a.lib
	del b.lib
	del c.lib
	rc /p /k $@

clean:: clean-$(WHAT)
	-$(RM) $(LIBNAME)
	-$(RM) *.$(OBJEXT)

clean-:: clean-unix
clean-unix::
	-$(RM) krb_err.c
	-$(RM) krb_err.h
	-$(RM) ../../include/krb_err.h
	-$(RM) shared/*

clean-windows::
	-$(RM) kerberos.lib
	-$(RM) kerberos.bak
	-$(RM) kerberos.dll
	-$(RM) kerberos.lst
	-$(RM) kerberos.map
	-$(RM) libkrb.lst
	-$(RM) libkrb.bak
	-$(RM) winsock.lib
	-$(RM) msvc.pdb
	-$(RM) proj.err
	-$(RM) ..\..\floppy\winsock.lib
	-$(RM) ..\..\floppy\kerberos.lib
	-$(RM) ..\..\floppy\kerberos.dll

install-unix::
	$(INSTALL_DATA) $(LIBNAME) $(DESTDIR)$(KRB5_LIBDIR)/$(LIBNAME)
	$(CHMOD) 644 $(DESTDIR)$(KRB5_LIBDIR)/$(LIBNAME)
	$(RANLIB)    $(DESTDIR)$(KRB5_LIBDIR)/$(LIBNAME)
	$(CHMOD) 444 $(DESTDIR)$(KRB5_LIBDIR)/$(LIBNAME)


check:: check-$(WHAT)

check-unix:: $(TEST_PROGS)
check-mac:: $(TEST_PROGS)

check-windows::

