# 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 -DSMB_UNICODE
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_volstat.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)\cm_memmap.h \
	$(INCFILEDIR)\cm_performance.h \
        $(INCFILEDIR)\cm_nls.h \
        $(INCFILEDIR)\afsd_eventlog.h \
        $(INCFILEDIR)\afsd_eventmessages.h \
        $(INCFILEDIR)\afskfw.h \
        $(INCFILEDIR)\afsicf.h

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

CONFOBJS=$(OUT)\cm_config.obj \
         $(OUT)\cm_dns.obj \
         $(OUT)\cm_nls.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) $(AFSDEV_AUXMIDLFLAGS) /app_config $?

AFSDOBJS=\
        $(OUT)\rawops.obj \
	$(OUT)\afsd_init.obj \
        $(OUT)\cm_btree.obj \
	$(OUT)\cm_cell.obj \
	$(OUT)\cm_server.obj \
	$(OUT)\cm_volume.obj \
        $(OUT)\cm_volstat.obj \
	$(OUT)\cm_config.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)\cm_memmap.obj \
        $(OUT)\cm_performance.obj \
        $(OUT)\cm_nls.obj \
	$(OUT)\afsrpc_s.obj \
!IFDEF OSICRASH
	$(OUT)\afsdcrash.obj \
!ENDIF
        $(OUT)\cm_freelance.obj \
        $(OUT)\afsd_eventlog.obj \
        $(OUT)\afsd_flushvol.obj \
        $(OUT)\afsicf.obj

$(AFSDOBJS):

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

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

CMDBGOBJS=$(OUT)\cmdebug.obj

$(CMDBGOBJS): $(AFSROOT)\src\venus\cmdebug.c
	$(C2OBJ) -DAFS_PTHREAD_ENV /Fo$@ $**

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" \
           /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 mpr.lib shell32.lib
        $(_VC_MANIFEST_EMBED_DLL)
	$(DLLPREP)
        $(CODESIGN_USERLAND)
	$(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)\logon_ad.obj \
    $(OUT)\afslogon.res \
    $(OUT)\cm_nls.obj

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

LOGON_DLLSDKLIBS =\
        dnsapi.lib \
        netapi32.lib \
        mpr.lib \
	advapi32.lib \
	secur32.lib \
	strsafe.lib \
	oleaut32.lib \
	ole32.lib \
	adsiid.lib \
	activeds.lib \
	user32.lib \
        userenv.lib \
        shell32.lib

$(LOGON_DLLFILE): $(LOGON_DLLOBJS) $(LOGON_DLLLIBS)
	$(DLLGUILINK) $(LOGONLINKFLAGS) -def:afslogon.def $(LOGON_DLLSDKLIBS)
        $(_VC_MANIFEST_EMBED_DLL)
	$(DLLPREP)
        $(CODESIGN_USERLAND)
	$(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 mpr.lib
	$(DLLPREP)
	$(COPY) $*.lib $(DESTDIR)\lib
	$(DEL) $*.lib $*.exp

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

install_objs: $(OUT)\cm_dns.obj $(OUT)\cm_config.obj $(OUT)\cm_nls.obj $(LANAHELPERLIB) $(OUT)\afsicf.obj
     $(COPY) $(OUT)\cm_dns.obj $(DESTDIR)\lib
     $(COPY) $(OUT)\cm_nls.obj $(DESTDIR)\lib
     $(COPY) $(OUT)\cm_config.obj $(DESTDIR)\lib
     $(COPY) $(OUT)\afsicf.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_service.exe \
	$(EXEDIR)\fs.exe \
        $(EXEDIR)\symlink.exe \
        $(EXEDIR)\afsdacl.exe \
	$(LOGON_DLLFILE) \
	$(EXEDIR)\afsshare.exe \
	$(DESTDIR)\bin\kpasswd.exe $(EXEDIR)\cmdebug.exe $(EXEDIR)\afscpcc.exe

install9X: install_headers $(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) $(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 $(EXEDIR)\cmdebug.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\afs\afsvldb.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 \
        $(DESTDIR)\lib\cm_nls.obj

EXELIBS2 = \
        $(DESTDIR)\lib\afsrpc.lib \
	$(DESTDIR)\lib\afs\afsprot.lib \
	$(DESTDIR)\lib\afs\afspioctl.lib \
	$(DESTDIR)\lib\afs\afscom_err.lib \
	$(DESTDIR)\lib\afs\afscmd.lib \
	$(DESTDIR)\lib\afs\afsutil.lib \
	$(DESTDIR)\lib\afsubik.lib \
	$(DESTDIR)\lib\afsrxkad.lib \
	$(DESTDIR)\lib\afsdes.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 mpr.lib iphlpapi.lib shell32.lib
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)

# tokens.exe
$(EXEDIR)\tokens.exe: $(OUT)\ctokens.obj $(OUT)\tokens.res $(EXELIBS)
	$(EXECONLINK) dnsapi.lib mpr.lib iphlpapi.lib shell32.lib
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)

# unlog.exe
$(EXEDIR)\unlog.exe: $(OUT)\cunlog.obj $(OUT)\unlog.res $(EXELIBS)
	$(EXECONLINK) dnsapi.lib mpr.lib iphlpapi.lib shell32.lib
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)

# afscpcc.exe
$(EXEDIR)\afscpcc.exe: $(OUT)\afscpcc.obj $(OUT)\afscpcc.res $(LOGON_DLLLIBS)
	$(EXECONLINK) dnsapi.lib mpr.lib iphlpapi.lib shell32.lib userenv.lib
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)


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

AFSD_SDKLIBS =\
	netapi32.lib \
        dnsapi.lib \
        mpr.lib \
	rpcrt4.lib \
	user32.lib \
        Dbghelp.lib \
        strsafe.lib \
        mpr.lib \
        secur32.lib \
        ole32.lib \
        oleaut32.lib \
        iphlpapi.lib shell32.lib

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

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

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

# fs.exe
$(EXEDIR)\fs.exe: $(FSOBJS) $(OUT)\fs.res $(EXELIBS)
	$(EXECONLINK) dnsapi.lib mpr.lib iphlpapi.lib shell32.lib
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)

# cmdebug.exe
$(EXEDIR)\cmdebug.exe: $(CMDBGOBJS) $(OUT)\cmdebug.res $(EXELIBS2)
	$(EXECONLINK) $(EXELIBS2) dnsapi.lib mpr.lib iphlpapi.lib shell32.lib rpcrt4.lib
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)

# symlink.exe
$(EXEDIR)\symlink.exe: $(SLOBJS) $(OUT)\symlink.res  $(EXELIBS)
	$(EXECONLINK) dnsapi.lib mpr.lib iphlpapi.lib shell32.lib
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)

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

# afsdacl.exe
$(EXEDIR)\afsdacl.exe: $(OUT)\afsdacl.obj $(OUT)\afsdacl.res
	$(EXECONLINK)
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)

# 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)
        $(_VC_MANIFEST_EMBED_EXE)
	$(EXEPREP)
        $(CODESIGN_USERLAND)


############################################################################
# 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

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

afsd_eventmessages.rc: $(INCFILEDIR)\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) afsd_eventmessages.rc
        $(DEL) MSG?????.bin
	$(DEL) $(CONF_DLLFILE)
	$(DEL) $(LOGON_DLLFILE)
	$(DEL) $(LOG95_DLLFILE)

mkdir:
