# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html

AFSDEV_AUXCDEFINES = $(AFSDEV_AUXCDEFINES) /D"_AFXDLL"  -I..\kfw\inc\loadfuncs -I..\kfw\inc\krb5 -I..\kfw\inc\leash
AFSDEV_NETGUI = 1
RELDIR=WINNT\afsd
!INCLUDE ..\..\config\NTMakefile.$(SYS_NAME)
!INCLUDE ..\..\config\NTMakefile.version

EXEDIR = $(DESTDIR)\root.client\usr\vice\etc

############################################################################
# Definitions for installing header files

INCFILEDIR = $(DESTDIR)\include\afs  # header file install directory

# afsdicon and below added for WINNT\extra support

INCFILES =\
	$(INCFILEDIR)\afsd.h \
	$(INCFILEDIR)\cm.h \
	$(INCFILEDIR)\cm_buf.h \
	$(INCFILEDIR)\cm_cell.h \
	$(INCFILEDIR)\cm_config.h \
	$(INCFILEDIR)\cm_conn.h \
	$(INCFILEDIR)\cm_ioctl.h \
	$(INCFILEDIR)\cm_scache.h \
	$(INCFILEDIR)\cm_server.h \
	$(INCFILEDIR)\cm_user.h \
	$(INCFILEDIR)\cm_dns.h \
	$(INCFILEDIR)\cm_utils.h \
	$(INCFILEDIR)\fs_utils.h \
	$(INCFILEDIR)\krb.h \
	$(INCFILEDIR)\krb_prot.h \
	$(INCFILEDIR)\cm_dir.h \
	$(INCFILEDIR)\smb.h \
	$(INCFILEDIR)\smb3.h \
	$(INCFILEDIR)\smb_iocons.h \
	$(INCFILEDIR)\smb_ioctl.h \
	$(INCFILEDIR)\afsmsg95.h \
	$(INCFILEDIR)\afsrpc.h \
!IFDEF OSICRASH
	$(INCFILEDIR)\afsdcrash.h \
!ENDIF
	$(INCFILEDIR)\cm_dns_private.h \
	$(INCFILEDIR)\lanahelper.h \
	$(INCFILEDIR)\afsdicon.h \
	$(INCFILEDIR)\cm_callback.h \
	$(INCFILEDIR)\cm_aclent.h \
	$(INCFILEDIR)\cm_volume.h \
	$(INCFILEDIR)\cm_dcache.h \
	$(INCFILEDIR)\cm_access.h \
	$(INCFILEDIR)\cm_vnodeops.h \
	$(INCFILEDIR)\cm_dir.h \
	$(INCFILEDIR)\cm_utils.h \
	$(INCFILEDIR)\cm_daemon.h \
	$(INCFILEDIR)\cm_ioctl.h \
	$(INCFILEDIR)\cm_dnlc.h \
	$(INCFILEDIR)\cm_buf.h \
	$(INCFILEDIR)\cm_freelance.h \
    $(INCFILEDIR)\afsd_eventlog.h \
    $(INCFILEDIR)\afsd_eventmessages.h \
    $(INCFILEDIR)\afskfw.h

IDLFILES =\
	afsrpc.h $(OUT)\afsrpc_c.obj

CONFOBJS=$(OUT)\cm_config.obj \
         $(OUT)\cm_dns.obj

$(CONFOBJS):

RXOBJS = $(OUT)\xdr_int32.obj $(OUT)\xdr_int64.obj

$(RXOBJS):

RX= ..\..\rx

$(RXOBJS): $(RX)\$$(@B).c
	$(C2OBJ) -I$(RX) $**

$(IDLFILES):afsrpc.idl
	midl $(MIDL_FLAGS) /no_robust $(AFSDEV_AUXMIDLFLAGS) /app_config $?

AFSDOBJS=\
	$(OUT)\afsd_init.obj \
	$(OUT)\cm_cell.obj \
	$(OUT)\cm_server.obj \
	$(OUT)\cm_volume.obj \
	$(OUT)\cm_conn.obj \
	$(OUT)\cm_user.obj \
	$(OUT)\cm_buf.obj \
	$(OUT)\cm_scache.obj \
	$(OUT)\cm_dcache.obj \
	$(OUT)\cm_access.obj \
	$(OUT)\cm_callback.obj \
	$(OUT)\cm_vnodeops.obj \
	$(OUT)\cm_dir.obj \
	$(OUT)\cm_utils.obj \
	$(OUT)\largeintdotnet.obj \
	$(OUT)\smb.obj \
	$(OUT)\smb3.obj \
	$(OUT)\smb_ioctl.obj \
	$(OUT)\cm_ioctl.obj \
	$(OUT)\cm_daemon.obj \
	$(OUT)\cm_aclent.obj \
	$(OUT)\cm_dnlc.obj \
	$(OUT)\cm_rpc.obj \
	$(OUT)\afsrpc_s.obj \
!IFDEF OSICRASH
	$(OUT)\afsdcrash.obj \
!ENDIF
    $(OUT)\cm_freelance.obj \
    $(OUT)\afsd_eventlog.obj \
    $(OUT)\afsd_flushvol.obj

$(AFSDOBJS):

$(OUT)\cm_conn.obj: cm_conn.c
	$(C2OBJ) -DAFS_PTHREAD_ENV /Fo$@ $**

FSOBJS=$(OUT)\fs.obj $(OUT)\fs_utils.obj

SLOBJS=$(OUT)\symlink.obj $(OUT)\fs_utils.obj

ILIBDIR = $(DESTDIR)\lib

#                                                    
# Rules for message compiler info for logging events 
#                                                    
$(INCFILEDIR)\afsd_eventmessages.h:  afsd_eventmessages.mc         
	mc afsd_eventmessages.mc                           
                                                     
############################################################################
#
# Flags for linking LOGON DLL'S
#

LOGONLINKFLAGS = -entry:DllEntryPoint


############################################################################
#
# IDL COMPILATION
#

MIDL_FLAGS=/app_config \
	   /Zp4 \
	   /cpp_cmd $(cc) \
	   /cpp_opt "-E" \
	   /no_robust \
           /nologo

.SUFFIXES: .h .idl

.idl.h:
	midl $(MIDL_FLAGS) $(AFSDEV_AUXMIDLFLAGS) $<

############################################################################
# libafsconf.dll

CONF_DLLFILE = $(DESTDIR)\root.client\usr\vice\etc\libafsconf.dll

CONF_DLLLIBS = \
    $(DESTDIR)\lib\afs\afsutil.lib \
    $(DESTDIR)\lib\afs\afsreg.lib

$(CONF_DLLFILE): $(CONFOBJS) $(OUT)\libafsconf.res $(CONF_DLLLIBS)
	$(DLLGUILINK) -def:libafsconf.def dnsapi.lib
	$(DLLPREP)
	$(COPY) $*.lib $(ILIBDIR)
	$(DEL) $*.lib $*.exp

############################################################################
# lanahelper.lib

LANAHELPERLIB = $(DESTDIR)\lib\lanahelper.lib

LANAHELPERLIB_OBJS =\
      $(OUT)\lanahelper.obj

$(LANAHELPERLIB_OBJS):

$(LANAHELPERLIB): $(LANAHELPERLIB_OBJS)
      $(LIBARCH) netapi32.lib

############################################################################
# afskfw.lib

AFSKFWLIB = $(DESTDIR)\lib\afskfw.lib

AFSKFWLIB_OBJS =\
      $(OUT)\afskfw.obj

$(AFSKFWLIB_OBJS):

$(AFSKFWLIB): $(AFSKFWLIB_OBJS)
      $(LIBARCH)

############################################################################
# afslogon.dll

LOGON_DLLFILE = $(DESTDIR)\root.client\usr\vice\etc\afslogon.dll

LOGON_DLLOBJS =\
	$(OUT)\afslogon.obj \
	$(OUT)\afslogon.res

LOGON_DLLLIBS =\
	$(DESTDIR)\lib\afsauthent.lib \
	$(DESTDIR)\lib\libafsconf.lib \
    $(DESTDIR)\lib\afsrxkad.lib \
    $(DESTDIR)\lib\afsdes.lib \
    $(AFSKFWLIB)

$(LOGON_DLLFILE): $(LOGON_DLLOBJS) $(LOGON_DLLLIBS)
	$(DLLGUILINK) $(LOGONLINKFLAGS) -def:afslogon.def dnsapi.lib secur32.lib
	$(DLLPREP)
	$(COPY) $*.lib $(DESTDIR)\lib
	$(DEL) $*.lib $*.exp

############################################################################
# afslog95.dll

LOG95_DLLFILE = $(DESTDIR)\root.client\usr\vice\etc\afslog95.dll

LOG95_DLLOBJS =\
	$(OUT)\afslog95.obj \
	$(OUT)\afslog95.res

LOG95_DLLLIBS =\
	$(DESTDIR)\lib\afsauthent.lib \
	$(DESTDIR)\lib\libafsconf.lib

$(LOG95_DLLFILE): $(LOG95_DLLOBJS) $(LOG95_DLLLIBS)
	$(DLLGUILINK) $(LOGONLINKFLAGS) -def:afslog95.def dnsapi.lib
	$(DLLPREP)
	$(COPY) $*.lib $(DESTDIR)\lib
	$(DEL) $*.lib $*.exp

############################################################################
# Install target; primary makefile target

install_objs: $(OUT)\cm_dns.obj $(OUT)\cm_config.obj $(LANAHELPERLIB)
     $(COPY) $(OUT)\cm_dns.obj $(DESTDIR)\lib
     $(COPY) $(OUT)\cm_config.obj $(DESTDIR)\lib

install_headers: $(IDLFILES) $(INCFILES)

install: install_headers install_objs $(CONF_DLLFILE) \
	$(EXEDIR)\klog.exe \
	$(EXEDIR)\tokens.exe \
	$(EXEDIR)\unlog.exe $(EXEDIR)\afsd.exe $(EXEDIR)\afsd_service.exe \
	$(EXEDIR)\fs.exe $(EXEDIR)\symlink.exe \
	$(LOGON_DLLFILE) \
	$(EXEDIR)\afsshare.exe \
	$(DESTDIR)\bin\kpasswd.exe

install9X: install_headers $(CONF_DLLFILE) \
	$(EXEDIR)\klog.exe \
	$(EXEDIR)\tokens.exe \
	$(EXEDIR)\unlog.exe $(EXEDIR)\afsd_service.exe \
	$(EXEDIR)\fs.exe $(EXEDIR)\symlink.exe \
	$(LOGON_DLLFILE) $(LOG95_DLLFILE) \
	$(EXEDIR)\afsshare.exe \
	$(DESTDIR)\bin\kpasswd.exe

install_libutils: install_headers $(CONF_DLLFILE) \
	$(EXEDIR)\klog.exe \
	$(EXEDIR)\tokens.exe \
	$(EXEDIR)\unlog.exe \
	$(EXEDIR)\fs.exe $(EXEDIR)\symlink.exe \
	$(EXEDIR)\afsshare.exe \
	$(DESTDIR)\bin\kpasswd.exe

############################################################################
# Local clean target; augments predefined clean target

############################################################################
# assorted exe's

EXELIBS = \
	$(DESTDIR)\lib\afs\afsauth.lib \
	$(DESTDIR)\lib\afs\afskauth.lib \
	$(DESTDIR)\lib\afs\afsprot.lib \
	$(DESTDIR)\lib\afs\afspioctl.lib \
	$(DESTDIR)\lib\afs\afsaudit.lib \
	$(DESTDIR)\lib\afs\afsutil.lib \
	$(DESTDIR)\lib\afs\afscom_err.lib \
	$(DESTDIR)\lib\afs\afsreg.lib \
	$(DESTDIR)\lib\afs\afscmd.lib \
	$(DESTDIR)\lib\afsubik.lib \
	$(DESTDIR)\lib\afsrxkad.lib \
	$(DESTDIR)\lib\afsdes.lib \
	$(DESTDIR)\lib\afsrx.lib \
	$(DESTDIR)\lib\afslwp.lib \
	$(DESTDIR)\lib\libosi.lib \
	$(DESTDIR)\lib\libafsconf.lib

# klog.exe
$(EXEDIR)\klog.exe: $(OUT)\cklog.obj $(OUT)\klog.res $(EXELIBS)
	$(EXECONLINK) dnsapi.lib
	$(EXEPREP)

# tokens.exe
$(EXEDIR)\tokens.exe: $(OUT)\ctokens.obj $(OUT)\tokens.res $(EXELIBS)
	$(EXECONLINK) dnsapi.lib
	$(EXEPREP)

# unlog.exe
$(EXEDIR)\unlog.exe: $(OUT)\cunlog.obj $(OUT)\unlog.res $(EXELIBS)
	$(EXECONLINK) dnsapi.lib
	$(EXEPREP)

# afsd.exe
AFSD_EXEFILE = $(EXEDIR)\afsd.exe

AFSD_SDKLIBS =\
	largeint.lib \
	netapi32.lib \
    mpr.lib \
    dnsapi.lib \
	rpcrt4.lib \
	user32.lib \
    Dbghelp.lib

AFSD_EXELIBS =\
	$(DESTDIR)\lib\libosi.lib \
	$(DESTDIR)\lib\afsrpc.lib \
    $(DESTDIR)\lib\afsrx.lib \
	$(DESTDIR)\lib\afsauthent.lib \
	$(DESTDIR)\lib\afs\mtafsvldb.lib \
	$(DESTDIR)\lib\afs\mtafsint.lib \
	$(DESTDIR)\lib\libafsconf.lib \
	$(DESTDIR)\lib\afs\afsreg.lib \
    $(LANAHELPERLIB)

$(AFSD_EXEFILE): $(OUT)\afsd.obj $(AFSDOBJS) $(OUT)\afsd.res  $(RXOBJS) $(AFSD_EXELIBS)
	$(EXEGUILINK) $(AFSD_SDKLIBS)
	$(EXEPREP)

# afsd_service.exe
$(EXEDIR)\afsd_service.exe: $(OUT)\afsd_service.obj $(AFSDOBJS) $(OUT)\afsd_service.res  $(RXOBJS) $(AFSD_EXELIBS)
	$(EXECONLINK) $(AFSD_SDKLIBS) /MAP 
	$(EXEPREP)

# fs.exe
$(EXEDIR)\fs.exe: $(FSOBJS) $(OUT)\fs.res $(EXELIBS)
	$(EXECONLINK) dnsapi.lib
	$(EXEPREP)

# symlink.exe
$(EXEDIR)\symlink.exe: $(SLOBJS) $(OUT)\symlink.res  $(EXELIBS)
	$(EXECONLINK) dnsapi.lib
	$(EXEPREP)

# afsshare.exe
$(EXEDIR)\afsshare.exe: $(OUT)\afsshare.obj $(OUT)\afsshare.res
	$(EXECONLINK)
	$(EXEPREP)

# kpasswd.exe - built in kauth, but rebuild here to make pthread-based,
#    which is required for Windows 95.  At some point it would be nice
#    for all commands to be pthread based, in which case they should
#    be built in a separate directory (perhaps tbin ala tviced) or
#    libafsauthent should be built earlier so that each command can
#    be built in its native directory.

KAUTH = ..\..\kauth

KPASSWD_OBJS =\
	$(OUT)\kpasswd.obj \
	$(OUT)\kkids.obj \
	$(OUT)\kautils.obj \
	$(OUT)\$(KAUTH)\kpasswd.res

KPASSWD_LIBS =\
	$(DESTDIR)\lib\afsauthent.lib \
	$(DESTDIR)\lib\afsrpc.lib \
    $(DESTDIR)\lib\afsrx.lib \
	$(DESTDIR)\lib\afs\afscmd.lib \
	$(DESTDIR)\lib\afsdes.lib \
	$(DESTDIR)\lib\afs\afsutil.lib

$(OUT)\kpasswd.obj: $(KAUTH)/kpasswd.c
	$(C2OBJ) -DAFS_PTHREAD_ENV /Fo$@ $**

$(OUT)\kkids.obj: $(KAUTH)/kkids.c
	$(C2OBJ) -DAFS_PTHREAD_ENV /Fo$@ $**

$(OUT)\kautils.obj: $(KAUTH)/kautils.c
	$(C2OBJ) -DAFS_PTHREAD_ENV /Fo$@ $**

$(OUT)\kpasswd.res: $(KAUTH)\kpasswd.rc
    $(RC) /Fo$@ $**

$(DESTDIR)\bin\kpasswd.exe: $(KPASSWD_OBJS) $(KPASSWD_LIBS)
	$(DEL) $(DESTDIR)\bin\kpasswd.exe
	$(EXECONLINK)
	$(EXEPREP)


############################################################################
# generate versioninfo resources

$(OUT)\afsshare.res: afsshare.rc AFS_component_version_number.h

$(OUT)\fs.res: fs.rc AFS_component_version_number.h

$(OUT)\symlink.res: symlink.rc AFS_component_version_number.h

$(OUT)\klog.res: klog.rc AFS_component_version_number.h

$(OUT)\tokens.res: tokens.rc AFS_component_version_number.h

$(OUT)\unlog.res: unlog.rc AFS_component_version_number.h

afsd_eventmessages.rc: afsd_eventmessages.h

$(OUT)\afsd_service.res: afsd_service.rc afsd_eventmessages.rc AFS_component_version_number.h

$(OUT)\afslogon.res: afslogon.rc AFS_component_version_number.h

$(OUT)\afslog95.res: afslog95.rc AFS_component_version_number.h

$(OUT)\libafsconf.res: libafsconf.rc AFS_component_version_number.h

############################################################################
clean::
	$(DEL) $(OUT)\*.res
	$(DEL) afsrpc.h
	$(DEL) afsrpc_?.*
    $(DEL) afsd_eventmessages.h
	$(DEL) $(CONF_DLLFILE)
	$(DEL) $(LOGON_DLLFILE)
	$(DEL) $(LOG95_DLLFILE)

mkdir:
