!include ..\include\common.inc

!ifndef PACKAGE
!error Macro PACKAGE is not defined.
!endif

!ifndef PACKAGEDIR
PACKAGEDIR=$(SRCROOT)\dist
!endif

BUILDIDPATH="$(PACKAGEDIR)\twapi_buildid.tcl"

# Mandatory files. twapi.tcl must come first since this
# is the order in which files are combined as well.
BASE_TCLFILES=twapi.tcl base.tcl handle.tcl metoo.tcl osinfo.tcl apputil.tcl security.tcl process.tcl disk.tcl win.tcl

# Desktop files
DESKTOP_TCLFILES= ui.tcl input.tcl sound.tcl clipboard.tcl nls.tcl shell.tcl com.tcl

# Server files
SERVER_TCLFILES= services.tcl eventlog.tcl

# Files for full build
EXTRA_TCLFILES= \
	adsi.tcl pdh.tcl process2.tcl accounts.tcl share.tcl \
        network.tcl synch.tcl winsta.tcl \
        printer.tcl mstask.tcl msi.tcl crypto.tcl \
        device.tcl power.tcl namedpipe.tcl resource.tcl rds.tcl \
	wmi.tcl etw.tcl

TCLFILES = $(BASE_TCLFILES)

!IFNDEF DESKTOPONLY
TCLFILES = $(TCLFILES) $(SERVER_TCLFILES)
!ENDIF

!IFNDEF SERVERONLY
TCLFILES = $(TCLFILES) $(DESKTOP_TCLFILES)
!ENDIF

!IFNDEF LEAN
TCLFILES = $(TCLFILES) $(EXTRA_TCLFILES)
!ENDIF

!if "x$(PACKAGESTYLE)" == "xtm"
# Note tm package style has no pkgIndex.tcl file.
distribution: twapi_version.tcl $(BUILDIDPATH) $(TCLFILES)
        -@mkdir "$(PACKAGEDIR)"
	@for %f in (twapi_version.tcl $(TCLFILES)) do @xcopy /q /y %f "$(PACKAGEDIR)"
!else
distribution: pkgIndex.tcl twapi_version.tcl $(BUILDIDPATH) $(TCLFILES)
        -@mkdir "$(PACKAGEDIR)"
	@for %f in (pkgIndex.tcl twapi_version.tcl $(TCLFILES)) do @xcopy /q /y %f "$(PACKAGEDIR)"
!endif

!ifdef COMBINEOUTPUT
COMBINEFLAGS = -force -outfile $(COMBINEOUTPUT)
!endif
# Combines all Tcl scripts into one. Note pkgIndex.tcl is not included
combine: twapi_version.tcl twapi_buildid.tcl $(TCLFILES)
        -@mkdir "$(PACKAGEDIR)"
	@for %f in (twapi_version.tcl $(TCLFILES)) do @xcopy /q /y %f "$(PACKAGEDIR)"
	cd $(PACKAGEDIR) && $(TCLSH) "$(TOOLDIR)\createtmfile.tcl" $(COMBINEFLAGS) -compact $(PACKAGE) $(MODULEVERSION) $**

twapi_version.tcl : makefile
        echo <<$@
# This file is automatically generated and will be overwritten
namespace eval twapi {
    variable version $(MODULEMAJOR).$(MODULEMINOR)
    variable patchlevel $(MODULEVERSION)
    variable package_name $(PACKAGE)
    if {$$::tcl_platform(machine) eq "amd64"} {
        variable dll_base_name $(PACKAGE)64
    } else {
        variable dll_base_name $(PACKAGE)
    }
}
<<KEEP

twapi_buildid.tcl : $(BUILDIDPATH)

$(BUILDIDPATH) : 
        -@mkdir "$(PACKAGEDIR)"
        echo puts "namespace eval twapi {variable build_id [clock seconds]}" | $(TCLSH) >> $@

makefile: ..\include\common.inc

clean:
        -del *.*~
        -rmdir/s/q dist
