PA = $(PROCESSOR_ARCHITECTURE) # Use a shorter name

!if "$(PA)"=="x86"
TOOLDIR = ..\libw32\tools\i386
!else
TOOLDIR = ..\libw32\tools\$(PA)
!endif

# if doing a 64-bit CRT build on a 32-bit system, use the native 32-bit
# compiler, not a 64-bit-targetting cross-compiler

!if "$(LLP64)" != "1" || "$(PA)" == "IA64" || "$(PA)" == "ALPHA64"
CC = cl
BLDFLAG =
!else
CC = $(V6TOOLS)\bin\cl
!if "$(PA)" == "x86"
BLDFLAG = -D_BUILD_IA64
!elseif "$(PA)" == "ALPHA"
BLDFLAG = -D_BUILD_ALPHA64
!else
!error Unknown platform for 64-bit targetted CRT build
!endif
!endif

!if "$(LLP64)" == "1"
MKCLNMKFFLAGS = -sys -64
!elseif "$(BLD_SYSCRT)" == "1"
MKCLNMKFFLAGS = -sys
!else
MKCLNMKFFLAGS =
!endif

!if "$(NOCLEAN)" == "1"
MKCLNMKFFLAGS = $(MKCLNMKFFLAGS) -noclean
!endif

all:	makefile.pre makefile.rel

pd-d:	pd-b
	sed "/\\$$/!d" pd-b > pd-d

pd-f:	pd-b
	sed "/\\$$/d" pd-b > pd-f

mkdirs.i: pd-d mkdirs.sed
	sed -f mkdirs.sed pd-d > mkdirs.i

mkfiles.i: pd-f mkfiles.sed
	sed -f mkfiles.sed pd-f > mkfiles.i

cleanlst.i: mkfiles.i
	copy nul cleanlst.i

copy_lst.i: mkfiles.i
	copy mkfiles.i copy_lst.i

mkclnmkf.exe: mkclnmkf.c makefile
	$(CC) -nologo -Gi- -W3 -WX -Za -X -I$(V6TOOLS)\include $(BLDFLAG) $*.c \
	-link -nod:libc.lib -nod:kernel32.lib \
	$(V6TOOLS)\lib\libc.lib $(V6TOOLS)\lib\kernel32.lib

makefile.pre makefile.rel: mkclnmkf.exe copy_lst.i cleanlst.i mkdirs.i
	if exist makefile.pre del makefile.pre
	if exist makefile.rel del makefile.rel
	mkclnmkf $(MKCLNMKFFLAGS) \crt %CRT_BUILDDIR%\crt\prebuild %CRT_BUILDDIR%\crt\src copy_lst.i cleanlst.i mkdirs.i makefile.pre makefile.rel
	if exist makefile.tmp del makefile.tmp
	ren makefile.rel makefile.tmp
	sed "s/DST)\\i386/DST)\\intel/g" makefile.tmp > makefile.rel
	del makefile.tmp