# IDE_VC4.PM
#
# Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
#


# Makmake-module for creating MAKMAKE MSVC4 IDE makefiles shared by windows platform modules

package Ide_vc4;

# declare variables global for module
my $BaseAddressFlag;
my %IdeBlds=();
my @Win32LibList=();
my $Win32Resrc;

require Exporter;
@ISA=qw(Exporter);

@EXPORT=qw(
	PMHelp_Mmp
	PMPlatProcessMmp

		PMGetCleanFileList
		PMGetWorkPathList

	PMStartBldList
		PMBld
	PMEndBldList
	PMStartSubPrjList
			PMStartSubPrjSrc
			PMSubPrjSrcDepend
				PMStartSubPrjSrcBld
				PMSubPrjSrcBldDepend
				PMEndSubPrjSrcBld
			PMEndSubPrjSrc
			PMSubPrjDoc
			PMStartSubPrjResrc
				PMSubPrjResrcBld
			PMEndSubPrjResrc
	PMEndSubPrjList
);

use Winutl;

sub PMHelp_Mmp {
	&Winutl_Help_Mmp;
}

sub PMPlatProcessMmp {

	&Winutl_DoMmp;
	$BaseAddressFlag=&Winutl_BaseAddress;
	$BaseAddressFlag=~s/^(.+$)$/ \/base:$1/o;
	@Win32LibList=&Winutl_Win32LibList;
	$Win32Resrc=&Winutl_Win32Resrc;
}

sub PMGetCleanFileList {
	&Winutl_GetCleanFileList;
}

sub PMGetWorkPathList {
	&Winutl_GetWorkPathList;
}

sub PMStartBldList {
	my $BaseTrg=&main::BaseTrg;
	my @BldList=&main::BldList;
	my $GenTrgType=&main::GenTrgType;
	my $TrgType=&main::TrgType;

	#create the required deffile
	if ($TrgType=~/^APP$/o) {
		my $ExtraFile=join '',&main::SysDefDir,'APP.DEF';
		&main::CreateExtraFile($ExtraFile,'EXPORTS ?NewApplication@@YAPAVCApaApplication@@XZ @1 NONAME');
	}
	if ($TrgType=~/^FSY$/o) {
		my $ExtraFile=join '',&main::SysDefDir,'FSY.DEF';
		&main::CreateExtraFile($ExtraFile,'EXPORTS CreateFileSystem @1 NONAME');
	}
	elsif ($TrgType=~/^LDD$/o) {
		my $ExtraFile=join '',&main::SysDefDir,'LDD.DEF';
		&main::CreateExtraFile($ExtraFile,'EXPORTS ?CreateLogicalDevice@@YAPAVDLogicalDevice@@XZ @1 NONAME');
	}
	elsif ($TrgType=~/^PDD$/o) {
		my $ExtraFile=join '',&main::SysDefDir,'PDD.DEF';
		&main::CreateExtraFile($ExtraFile,'EXPORTS ?CreatePhysicalDevice@@YAPAVDPhysicalDevice@@XZ @1 NONAME');
	}

	#set up global IDE builds variable
	%IdeBlds= (
		REL	=> "$BaseTrg - Win32 Release",
		DEB => "$BaseTrg - Win32 Debug",
		UREL=> "$BaseTrg - Win32 Uni Release",
		UDEB=> "$BaseTrg - Win32 Uni Debug",
	);

	# SET DEFAULT CFG IF NO CFG SPECIFIED
	#------------------------------------
	&main::Output(
		"# Microsoft Developer Studio Generated NMAKE File, Format Version 4.00\n",
		"# ** DO NOT EDIT **\n",
		"\n"
	);

	if ($GenTrgType=~/^DLL$/o) {
		&main::Output(
			"# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\n"
		);
	}
	elsif ($GenTrgType=~/^EXE$/o) {
		if (not &main::Plat=~/^WINC$/o) {
			&main::Output(
				"# TARGTYPE \"Win32 (x86) Application\" 0x0101\n"
			);
		}
		else {
			&main::Output(
				"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n"
			);
		}
	}
	elsif ($GenTrgType=~/^LIB$/o) {
		&main::Output(
			"# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\n"
		);
	}
	
	&main::Output(
		"\n",
		"!IF \"\$(CFG)\" == \"\"\n",
		"CFG=",$IdeBlds{DEB},"\n",
		"!MESSAGE No configuration specified.  Defaulting to ",$IdeBlds{DEB},".\n",
		"!ENDIF \n",
		"\n"
	);

	# HANDLE INVALID CONFIGURATION SPECIFICATION
	#-------------------------------------------
	&main::OutFormat(
		"!IF \"\$(CFG)\" != \"",$IdeBlds{$BldList[0]},"\""
	);
	my $Count=1;
	while ($Count<=$#BldList) {
		&main::OutFormat(
			" && \"\$(CFG)\" != \"",$IdeBlds{$BldList[$Count]},"\""
		);
		$Count++;
	}
	&main::Output(
		"!MESSAGE Invalid configuration \"\$(CFG)\" specified.\n",
		"!MESSAGE You can specify a configuration when running NMAKE on this makefile\n",
		"!MESSAGE by defining the macro CFG on the command line.  For example:\n",
		"!MESSAGE \n",
		"!MESSAGE NMAKE /f \"$BaseTrg.MAK\" CFG=\"".$IdeBlds{DEB}."\"\n",
		"!MESSAGE \n",
		"!MESSAGE Possible choices for configuration are:\n",
		"!MESSAGE \n"
	);
	if ($GenTrgType=~/^DLL$/o) {
		foreach (@BldList) {
			&main::Output(
				"!MESSAGE \"",$IdeBlds{$_},"\" (based on \"Win32 (x86) Dynamic-Link Library\")\n"
			);
		}
	}
	elsif ($GenTrgType=~/^EXE$/o) {
		if (not &main::Plat=~/^WINC$/o) {
			foreach (@BldList) {
				&main::Output(
					"!MESSAGE \"",$IdeBlds{$_},"\" (based on \"Win32 (x86) Application\")\n"
				);
			}
		}
		else {
			foreach (@BldList) {
				&main::Output(
					"!MESSAGE \"",$IdeBlds{$_},"\" (based on \"Win32 (x86) Console Application\")\n"
				);
			}
		}
	}
	elsif ($GenTrgType=~/^LIB$/o) { # static libraries should probably be dealt with another way
		foreach (@BldList) {
			&main::Output(
				"!MESSAGE \"",$IdeBlds{$_},"\" (based on \"Win32 (x86) Static Library\")\n"
			);
		}
	}
	&main::Output(
		"!MESSAGE \n",
		"!ERROR An invalid configuration is specified.\n",
		"!ENDIF \n",
		"\n"
	);

	# SET NULL
	#---------
	&main::Output(
		"!IF \"\$(OS)\" == \"Windows_NT\"\n",
		"NULL=\n",
		"!ELSE \n",
		"NULL=nul\n",
		"!ENDIF \n"
	);

	# BEGIN THE PROJECT
	#------------------
	&main::Output(
		"#"x80,"\n",
		"# Begin Project\n",
		"RSC=rc.exe\n",
		"MTL=mktyplib.exe\n",
		"CPP=cl.exe\n",
		"\n"
	);
}

sub PMBld {

	my $BaseFirstObj=&main::BaseFirstObj;
	my @BaseObjList=&main::BaseObjList;
	my @BaseSrcList=&main::BaseSrcList;
	my $BaseTrg=&main::BaseTrg;
	my $Bld=&main::Bld;
	my @BldList=&main::BldList;
	my $ChopBldPath=&main::Path_ChopPath(&main::BldPath);
	my $ChopRelPath=&main::Path_ChopPath(&main::RelPath);
	my @ChopSysIncPaths=&main::Path_ChopPath(&main::SysIncPaths);
	my @ChopUserIncPaths=&main::Path_ChopPath(&main::UserIncPaths);
	my $GenTrgType=&main::GenTrgType;
	my @LibList=&main::LibList;
	my @MacroList=&main::MacroList;
	my $Trg=&main::Trg;
	my $TrgPath=&main::TrgPath;
	my $TrgType=&main::TrgType;

	my $DefFile=&main::DefFile;

	my $NotUseWin32LibsFlag="";
	if (not @Win32LibList) {
		$NotUseWin32LibsFlag=" /X"; # standard include directories not to be used
	}


	if ($Bld eq $BldList[0]) {
		&main::Output(
			"!IF  \"\$(CFG)\" == \"",$IdeBlds{$Bld},"\"\n",
			"\n"
		);
	}
	else {
		&main::Output(
			"!ELSEIF  \"\$(CFG)\" == \"",$IdeBlds{$Bld},"\"\n",
			"\n"
		);
	}
	&main::Output(
		"# PROP BASE Use_MFC 0\n"
	);
	if ($Bld=~/^U?REL$/o) {
		&main::Output(
			"# PROP BASE Use_Debug_Libraries 0\n"
		);
		if (not $Bld=~/^U/o) {
			&main::Output(
				"# PROP BASE Output_Dir \"WinRel\"\n",
				"# PROP BASE Intermediate_Dir \"WinRel\"\n"
			);
		}
		else {
			&main::Output(
				"# PROP BASE Output_Dir \"Win32_Un\"\n",
				"# PROP BASE Intermediate_Dir \"Win32_Un\"\n"
			);
		}
	}
	elsif ($Bld=~/^U?DEB$/o) {
		&main::Output(
			"# PROP BASE Use_Debug_Libraries 1\n"
		);
		if (not $Bld=~/^U/o) {
			&main::Output(
				"# PROP BASE Output_Dir \"WinDebug\"\n",
				"# PROP BASE Intermediate_Dir \"WinDebug\"\n"
			);
		}
		else {
			&main::Output(
				"# PROP BASE Output_Dir \"Win32_U0\"\n",
				"# PROP BASE Intermediate_Dir \"Win32_U0\"\n"
			);
		}
	}
	&main::Output(
			"# PROP Use_MFC 0\n"
	);
	if ($Bld=~/^U?REL$/o) {
		&main::Output(
			"# PROP Use_Debug_Libraries 0\n"
			);
	}
	elsif ($Bld=~/^U?DEB$/o) {
		&main::Output(
			"# PROP Use_Debug_Libraries 1\n"
		);
	}
	&main::Output(
		"# PROP Output_Dir \"$ChopRelPath\"\n",
		"# PROP Intermediate_Dir \"$ChopBldPath\"\n",
		"OUTDIR=$ChopRelPath\n",
		"INTDIR=$ChopBldPath\n"
	);
	if ($TrgType=~/^LIB$/o) {
		&main::Output(
			"# Begin Custom Macros\n",
			"OutDir=$ChopRelPath\n",
			"# End Custom Macros\n"
		);
	}

	&main::Output(
		"\n"
	);
	if (not $GenTrgType=~/^LIB$/o) {
		&main::Output(
			"ALL : \"$ChopRelPath\\$TrgPath$Trg\""
		);
	}
	else {
		&main::Output(
			"ALL : \"\$(OUTDIR)\\$BaseTrg.lib\""
		);
		if ($TrgType=~/^LIB$/o) {
			&main::Output(
				" \"\$(OUTDIR)\\$BaseTrg.obj\""
			);
		}
	}
	if ($Bld=~/^U?DEB$/o) {
		&main::Output(
			" \"\$(OUTDIR)\\$BaseTrg.bsc\""
		);
	}

	&main::Output(
		"\n",
		"\n",
		"CLEAN : \n"
	);
	foreach (&PMGetCleanFileList) {
		next if (($Bld=~/^U?REL$/o) && (/\.(BSC|SBR|ILK|PDB)$/o));
		&main::Output(
			"\t-\@erase \"$_\"\n"
		);
	}

	&main::Output(
			"\n",
			"\"\$(OUTDIR)\" :\n",
			"    if not exist \"\$(OUTDIR)/\$(NULL)\" mkdir \"\$(OUTDIR)\"\n",
			"\n",
			"\"\$(INTDIR)\" :\n",
			"    if not exist \"\$(INTDIR)/\$(NULL)\" mkdir \"\$(INTDIR)\"\n",
			"\n",
			"\$(OUTDIR)/$BaseTrg.bsc : \$(OUTDIR)  \$(BSC32_SBRS)\n",
	);


	&main::Output(
		"# ADD CPP /nologo /Zp4"
	);
	if ($GenTrgType=~/^EXE$/o) {
		&main::Output(
			" /ML"
		);
	}
	elsif ($GenTrgType=~/^(DLL|LIB)$/o) {
		&main::Output(
			" /MD"
		);
	}
	if ($Bld=~/^U?DEB$/o) {
		&main::Output(
			"d"
		);
	}
	&main::Output(
		" /W4"
	);
	if ($Bld=~/^U?REL$/o) {
		&main::Output(
			" /O1 /Ob1"
		);
	}
	elsif ($Bld=~/^U?DEB$/o) {
		&main::Output(
			" /Zi /Od"
		);
	}
	&main::Output(
		"$NotUseWin32LibsFlag"
	);
	foreach (@ChopUserIncPaths,@ChopSysIncPaths) {
		&main::Output(
			" /I \"$_\""
		);
	}
	foreach (@MacroList) {
		&main::Output(
			" /D \"$_\""
		);
	}
	if ($Bld=~/^U?DEB$/o) {
		&main::Output(
			" /FR"
		);
	}
	&main::Output(
		" /c\n",
	);

	&main::OutFormat(
		"CPP_PROJ=/nologo /Zp4"
	);
	if ($GenTrgType=~/^EXE$/o) {
		&main::OutFormat(
			" /ML"
		);
	}
	elsif ($GenTrgType=~/^(DLL|LIB)$/o) {
		&main::OutFormat(
			" /MD"
		);
	}
	if ($Bld=~/^U?DEB$/o) {
		&main::OutFormat(
			"d"
		);
	}
	&main::OutFormat(
		" /W4"
	);
	if ($Bld=~/^U?REL$/o) {
		&main::OutFormat(
			" /O1 /Ob1"
		);
	}
	elsif ($Bld=~/^U?DEB$/o) {
		&main::OutFormat(
			" /Zi /Od"
		);
	}
	&main::OutFormat(
		"$NotUseWin32LibsFlag"
	);
	foreach (@ChopUserIncPaths,@ChopSysIncPaths) {
		&main::OutFormat(
			" /I \"$_\""
		);
	}
	foreach (@MacroList) {
		&main::OutFormat(
			" /D \"$_\""
		);
	}
	if ($Bld=~/^U?DEB$/o) {
		&main::OutFormat(
			" /FR\"\$(INTDIR)/\""
		);
	}
	&main::OutFormat(
		" /Fo\"\$(INTDIR)/\"",
	);
	if ($Bld=~/^U?DEB$/o) {
		&main::OutFormat(
			" /Fd\"\$(OUTDIR)/$BaseTrg.pdb\""
		);
	}
	&main::OutFormat(
		" /c"
	);

	&main::Output(
		"CPP_OBJS=$ChopBldPath/\n"
	);
	&main::Output(
		"CPP_SBRS="
	);
	if ($Bld=~/^U?DEB$/o) {
		&main::Output(
			"$ChopBldPath/"
		);
	}
	&main::Output(
		"\n",
	);

	if ($GenTrgType=~/^DLL$/o) {
		&main::Output(
			"# ADD MTL /nologo /D"
		);
		if ($Bld=~/^U?DEB$/o) {
			&main::Output(
				" \"_DEBUG\""
			);
		}
		&main::Output(
			" /win32\n"
		);

		&main::Output(
			"MTL_PROJ=/nologo /D"
		);
		if ($Bld=~/^U?DEB$/o) {
			&main::Output(
				" \"_DEBUG\""
			);
		}
		&main::Output(
			" /win32\n"
		);
	}

	&main::Output(
		"# ADD BASE RSC /l 0x809\n",
		"# ADD RSC /l 0x809"
	);
	if ($Bld=~/^U?REL$/o) {
		&main::Output(
			" /d \"NDEBUG\""
		);
	}
	elsif ($Bld=~/^U?DEB$/o) {
		&main::Output(
			" /d \"_DEBUG\""
		);
	}
	&main::Output(
		"\n"
	);
	if ($Win32Resrc) {
		&main::Output(
			"RSC_PROJ=/l 0x809 /fo\"\$(INTDIR)/",&main::Path_Split('Base',$Win32Resrc),".res\""
		);
		if ($Bld=~/^U?REL$/o) {
			&main::Output(
				" /d \"NDEBUG\""
			);
		}
		elsif ($Bld=~/^U?DEB$/o) {
			&main::Output(
				" /d \"_DEBUG\""
			);
		}
		&main::Output(
			"\n"
		);
	}

	&main::Output(
		"BSC32=bscmake.exe\n",
		"# ADD BSC32 /nologo\n",
		"BSC32_FLAGS=/nologo /o\"\$(OUTDIR)/$BaseTrg.bsc\" \n"
	);

	&main::Output(
		"BSC32_SBRS="
	);

	if ($Bld=~/^U?DEB$/o) {
		foreach (@BaseSrcList) {
			&main::Output(
				" \\\n",
				"\t\"\$(INTDIR)/$_.sbr\""
			);
		}
		&main::Output(
			"\n",
			"\n",
			"\"\$(OUTDIR)\\",$BaseTrg,".bsc\" : \"\$(OUTDIR)\" \$(BSC32_SBRS)\n",
			"    \$(BSC32) \@<<\n",
			"  \$(BSC32_FLAGS) \$(BSC32_SBRS)\n",
			"<<\n"
		);
	}
	&main::Output(
		"\n"
	);

	if ($GenTrgType=~/^LIB$/o) {
		&main::Output(
			"LIB32=link.exe -lib\n",
			"# ADD LIB32 /nologo /out:\"\$(OUTDIR)\\$BaseTrg.lib\"\n",
			"LIB32_FLAGS=/nologo /out:\"\$(OUTDIR)\\$BaseTrg.lib\"\n",
			"LIB32_OBJS="
		);
		foreach (@BaseSrcList) {
			&main::Output(
				" \\\n",
				"\t\"\$(INTDIR)/",$_,".obj\""
			);
		}
		&main::Output(
			"\n",
			"\n",
			"\"\$(OUTDIR)\\$BaseTrg.lib\" : \"\$(OUTDIR)\" \$(DEF_FILE) \$(LIB32_OBJS)\n",
			"    \$(LIB32) \@<<\n",
			"  \$(LIB32_FLAGS) \$(DEF_FLAGS) \$(LIB32_OBJS)\n",
			"<<\n",
			"\n"
		);
		if ($TrgType=~/^LIB$/o) {
			&main::Output(
				"# Begin Custom Build - Copying object file to \\Epoc32\\Release\n",
				"IntDir=$ChopBldPath\n",
				"OutDir=$ChopRelPath\n",
				"InputPath=$ChopRelPath\\$BaseTrg.lib\n",
				"SOURCE=\$(InputPath)\n",
				"\n",
				"\"\$(OutDir)\\$BaseTrg.obj\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"\n",
				"   copy \$(IntDir)\\$BaseSrcList[0].obj \$(OutDir)\\$BaseTrg.obj\n",
				"\n",
				"# End Custom Build\n",
				"\n"
			);
		}
	}
	else {
		&main::Output(
			"LINK32=link.exe\n",
			"# ADD LINK32"
		);
		&main::Output(
			" $ChopRelPath\\$BaseFirstObj.obj"
		);
		foreach (@BaseObjList) {
			&main::Output(
				" ",$ChopRelPath,"\\",$_,".obj"
			);
		}
		foreach (@Win32LibList) {
			&main::Output(
				" ",lc $_
			);
		}
		foreach (@LibList) {
			&main::Output(
				" $ChopRelPath\\",lc $_
			);
		}
		&main::Output(
			" /nologo"
		);
		if ($GenTrgType=~/^EXE$/o) {
			&main::Output(
				" /entry:\"_E32Startup\""
			);
		}
		elsif ($GenTrgType=~/^DLL$/o) {
			&main::Output(
				"$BaseAddressFlag /entry:\"_E32Dll\""
			);
		}
		if (&main::Plat=~/^WINC$/o && $GenTrgType=~/^EXE$/o) {
			&main::Output(
				" /subsystem:console"
			);
		}
		else {
			&main::Output(
				" /subsystem:windows"
			);
		}
		if ($GenTrgType=~/^DLL$/o) {
			&main::Output(
				" /dll"
			);
		}
		if ($Bld=~/^U?REL$/o) {
			&main::Output(
				" /incremental:no"
			);
		}
		elsif ($Bld=~/^U?DEB$/o) {
			&main::Output(
				" /incremental:yes /pdb:\"$ChopRelPath\\$BaseTrg.pdb\" /debug"
			);
		}
		&main::Output(
			" /machine:IX86 /nodefaultlib"
		);
		if ($DefFile) {
			&main::Output(
				" /def:\"$DefFile\""
			);
		}
		elsif ($TrgType=~/^APP$/o) {
			&main::Output(
				" /def:\"",&main::SysDefDir,"APP.DEF\""
			);
		}
		elsif ($TrgType=~/^FSY$/o) {
			&main::Output(
				" /def:\"",&main::SysDefDir,"FSY.DEF\""
			);
		}
		elsif ($TrgType=~/^LDD$/o) {
			&main::Output(
				" /def:\"",&main::SysDefDir,"LDD.DEF\""
			);
		}
		elsif ($TrgType=~/^PDD$/o) {
			&main::Output(
				" /def:\"",&main::SysDefDir,"PDD.DEF\""
			);
		}
		&main::Output(
			" /out:\"$ChopRelPath\\$TrgPath$Trg\""
		);
		if ($GenTrgType=~/^DLL$/o) {
			&main::Output(
				" /implib:\"$ChopRelPath/$BaseTrg.lib\""
			);
		}
		&main::Output(
			' /WARN:3',
			"\n"
		);

		&main::OutFormat(
			"LINK32_FLAGS="
		);
		&main::OutFormat(
			"$ChopRelPath\\$BaseFirstObj.obj"
		);
		foreach (@BaseObjList) {
			&main::OutFormat(
				" ",$ChopRelPath,"\\",$_,".obj"
			);
		}
		foreach (@Win32LibList) {
			&main::OutFormat(
				" ",lc $_
			);
		}
		foreach (@LibList) {
			&main::OutFormat(
				" $ChopRelPath\\",lc $_
			);
		}
		&main::OutFormat(
			" /nologo"
		);
		if ($GenTrgType=~/^EXE$/o) {
			&main::OutFormat(
				" /entry:\"_E32Startup\""
			);
		}
		elsif ($GenTrgType=~/^DLL$/o) {
			&main::OutFormat(
				"$BaseAddressFlag /entry:\"_E32Dll\""
			);
		}
		if (&main::Plat=~/^WINC$/o && $GenTrgType=~/^EXE$/o) {
			&main::OutFormat(
				" /subsystem:console"
			);
		}
		else {
			&main::OutFormat(
				" /subsystem:windows"
			);
		}
		if ($GenTrgType=~/^DLL$/o) {
			&main::OutFormat(
				" /dll"
			);
		}
		if ($Bld=~/^U?REL$/o) {
			&main::OutFormat(
				" /incremental:no"
			);
		}
		elsif ($Bld=~/^U?DEB$/o) {
			&main::OutFormat(
				" /incremental:yes /pdb:\"$ChopRelPath/$BaseTrg.pdb\" /debug"
			);
		}
		&main::OutFormat(
			" /machine:IX86 /nodefaultlib"
		);
		if ($DefFile) {
			&main::OutFormat(
				" /def:\"$DefFile\""
			);
		}
		elsif ($TrgType=~/^APP$/o) {
			&main::OutFormat(
				" /def:\"",&main::SysDefDir,"APP.DEF\""
			);
		}
		elsif ($TrgType=~/^FSY$/o) {
			&main::OutFormat(
				" /def:\"",&main::SysDefDir,"FSY.DEF\""
			);
		}
		elsif ($TrgType=~/^LDD$/o) {
			&main::OutFormat(
				" /def:\"",&main::SysDefDir,"LDD.DEF\""
			);
		}
		elsif ($TrgType=~/^PDD$/o) {
			&main::OutFormat(
				" /def:\"",&main::SysDefDir,"PDD.DEF\""
			);
		}
		&main::OutFormat(
			" /out:\"$ChopRelPath\\$TrgPath$Trg\""
		);
		if ($GenTrgType=~/^DLL$/o) {
			&main::OutFormat(
				" /implib:\"$ChopRelPath/$BaseTrg.lib\""
			);
		}
		&main::OutFormat(
			' /WARN:3'
		);

		&main::Output(
			"LINK32_OBJS="
		);
		foreach (@BaseSrcList) {
			&main::Output(
				" \\\n",
				"\t\"\$(INTDIR)/",$_,".obj\""
			);
		}
		if ($Win32Resrc) {
			&main::Output(
				" \\\n",
				"\t\"\$(INTDIR)/",&main::Path_Split('Base',$Win32Resrc),".res\""
			);
		}
		&main::Output(
			"\n",
			"\n",
			"\"$ChopRelPath\\$TrgPath$Trg\" : \"\$(OUTDIR)\" \$(DEF_FILE) \$(LINK32_OBJS)\n", # outdir a dependency so that it is created if it doesn't exist
			"    \$(LINK32) \@<<\n",		# this is just putting the flags and args in a temp inline file?
			"  \$(LINK32_FLAGS) \$(LINK32_OBJS)\n",
			"<<\n",
			"\n"
		);
	}
}

sub PMEndBldList {
	my $GenTrgType=&main::GenTrgType;

	# CLOSE THE !IF ... !ENDIF LOOP
	#------------------------------
	&main::Output(
		"!ENDIF \n"
	);
	if ($GenTrgType eq "EXE") {
		&main::Output(
			"MTL_PROJ=\n"
		);
	}
	&main::Output(
		"\n",
		".c{\$(CPP_OBJS)}.obj:\n",
		"   \$(CPP) \$(CPP_PROJ) \$<  \n",
		"\n",
		".cpp{\$(CPP_OBJS)}.obj:\n",
		"   \$(CPP) \$(CPP_PROJ) \$<  \n",
		"\n",
		".cxx{\$(CPP_OBJS)}.obj:\n",
		"   \$(CPP) \$(CPP_PROJ) \$<  \n",
		"\n",
		".c{\$(CPP_SBRS)}.sbr:\n",
		"   \$(CPP) \$(CPP_PROJ) \$<  \n",
		"\n",
		".cpp{\$(CPP_SBRS)}.sbr:\n",
		"   \$(CPP) \$(CPP_PROJ) \$<  \n",
		"\n",
		".cxx{\$(CPP_SBRS)}.sbr:\n",
		"   \$(CPP) \$(CPP_PROJ) \$<  \n",
		"\n",
	);
}

sub PMStartSubPrjList {

	my @BldList=&main::BldList;

	&main::Output(
		("#"x80),"\n",
		"# Begin Target\n",
		"\n"
	);
	foreach (@BldList) {
		&main::Output(
			"# Name \"".$IdeBlds{$_}."\"\n"
		);
	}
	&main::Output(
		"\n",
		"!IF  \"\$(CFG)\" == \"".$IdeBlds{$BldList[0]}."\"\n",
		"\n"
	);
	my $Count=1;
	while ($Count<=$#BldList) {
		&main::Output(
			"!ELSEIF  \"\$(CFG)\" == \"".$IdeBlds{$BldList[$Count]}."\"\n",
			"\n"
		);
		$Count++;
	}
	&main::Output(
		"!ENDIF \n",
		"\n"
	);
}

sub PMStartSubPrjSrc {    

	&main::Output(
		"#"x80,"\n",
		"# Begin Source File\n\n",
		"SOURCE=",&main::SubPrj,&main::Src,"\n"
	);
}

sub PMSubPrjSrcDepend {

	my @DepList=&main::DepList;
	&main::Output(
		"DEP_CPP_",substr(&main::BaseSrc,0,5),"=\\\n"
	);
	foreach (@DepList) {
		&main::Output(
			"\t\"$_\"\\\n"
		);
	}
	&main::Output(
		"\t\n",
		"\n"
	);
}

sub PMStartSubPrjSrcBld {

	my @BldList=&main::BldList;
	my $Bld=&main::Bld;

	if ($Bld eq $BldList[0]) { &main::Output("!IF  \"\$(CFG)\" == \"".$IdeBlds{$Bld}."\""); }
	else { &main::Output("!ELSEIF  \"\$(CFG)\" == \"".$IdeBlds{$Bld}."\""); }
	&main::Output(
		"\n",
		"\n",
		"\n"
	);
}

sub PMSubPrjSrcBldDepend {

	my @DepList=&main::DepList;

	&main::Output(
		"DEP_CPP_",substr(&main::BaseSrc,0,5),"=\\\n"
	);
	foreach (@DepList) {
		&main::Output(
			"\t\"$_\"\\\n"
		);
	}
	&main::Output(
		"\t\n",
		"\n"
	);
}

sub PMEndSubPrjSrcBld {

	my $Bld=&main::Bld;
	my $BaseSrc=&main::BaseSrc;
	my $TruncBaseSrc=substr($BaseSrc,0,5);

	if ($Bld=~/REL$/o) {
		&main::Output(
			"\"\$(INTDIR)\\".$BaseSrc.".obj\" : \$(SOURCE) \$(DEP_CPP_$TruncBaseSrc) \"\$(INTDIR)\"\n",
			"   \$(CPP) \$(CPP_PROJ) \$(SOURCE)\n",
			"\n"
		);
	}
	else {
		&main::Output(
			"BuildCmds= \\\n",
			"\t\$(CPP) \$(CPP_PROJ) \$(SOURCE) \\\n",
			"\n",
			"\n",
			"\"\$(INTDIR)\\".$BaseSrc.".obj\" : \$(SOURCE) \$(DEP_CPP_$TruncBaseSrc) \"\$(INTDIR)\"\n",
			"   \$(BuildCmds)\n",
			"\n",
			"\"\$(INTDIR)\\".$BaseSrc.".sbr\" : \$(SOURCE) \$(DEP_CPP_$TruncBaseSrc) \"\$(INTDIR)\"\n",
			"   \$(BuildCmds)\n",
			"\n"
		);
	}
}

sub PMEndSubPrjSrc {

	&main::Output(
		"!ENDIF \n",
		"\n",
		"# End Source File\n"
	);
}

sub PMSubPrjDoc {    

	my $SrcPath=&main::SubPrj;
	my $Doc=&main::Doc;

	&main::Output(
		"#"x80,"\n",
		"# Begin Source File\n",
		"\n",
		"SOURCE=",$SrcPath,$Doc,"\n",
		"# PROP Exclude_From_Bld 1\n",
		"# End Source File\n"
	);
}

sub PMStartSubPrjResrc {

	my $Resrc=&main::Resrc;
	my $SrcPath=&main::SubPrj;

	&main::Output(
		("#"x80),"\n",
		"# Begin Source File\n",
		"\n",
		"SOURCE=",$SrcPath,$Resrc,"\n",
		"\n",
		"\n"
	);
}

sub PMSubPrjResrcBld {

	my $Bld=&main::Bld;
	my @BldList=&main::BldList;


	if ($Bld eq $BldList[0]) {
		&main::Output(
			"!IF  \"\$(CFG)\" == \"",$IdeBlds{$Bld},"\"\n"
		);
	}
	else {
		&main::Output(
			"!ELSEIF  \"\$(CFG)\" == \"",$IdeBlds{$Bld},"\"\n"
		);
	}
	&main::Output(
		"\n",
		"\n"
	);
}

sub PMEndSubPrjResrc {

	&main::Output(
		"!ENDIF \n",
		"\n",
		"# End Source File\n"
	);
}

sub PMEndSubPrjList {

	my $PathBaseMak=&main::MakeFilePath.&main::BaseMak;

	if ($Win32Resrc) {
		my $BaseResrc=&main::Path_Split('Base',$Win32Resrc);
		my @BldList=&main::BldList;
		my @DepList=&main::Deps_GenDependsL($Win32Resrc);

		&main::Output(
			("#"x80),"\n",
			"# Begin Source File\n",
			"\n",
			"SOURCE=$Win32Resrc\n",
			"DEP_RSC_",substr($BaseResrc,0,5),"=\\\n"
		);
		foreach (@DepList) {
			&main::Output(
				"\t\"$_\"\\\n"
			);
		}
		&main::Output(
			"\t\n",
			"\n"
		);

		my $Bld;
		foreach $Bld (@BldList) {
			if ($Bld eq $BldList[0]) {
				&main::Output(
					"!IF  \"\$(CFG)\" == \"",$IdeBlds{$Bld},"\"\n"
				);
			}
			else {
				&main::Output(
					"!ELSEIF  \"\$(CFG)\" == \"",$IdeBlds{$Bld},"\"\n"
				);
			}
			&main::Output(
				"\n",
				"\n"
			);
			&main::Output(
				"\"\$(INTDIR)\\$BaseResrc.res\" : \$(SOURCE) \$(DEP_RSC_",substr($BaseResrc,0,5),") \"\$(INTDIR)\"\n",
				"   \$(RSC) /l 0x809 /fo\"\$(INTDIR)/$BaseResrc.res\" /i \"",&main::Path_ChopPath(&main::Path_Split('Path',$Win32Resrc)),"\""
			);
			if ($Bld=~/^U?REL$/o) {
				&main::Output(
					" /d \"NDEBUG\""
				);
			}
			elsif ($Bld=~/^U?DEB$/o) {
				&main::Output(
					" /d \"_DEBUG\""
				);
			}
			&main::Output(
				"\\\n",
				" \$(SOURCE)\n",
				"\n"
			);
		}
		&main::Output(
			"!ENDIF \n",
			"\n",
			"# End Source File\n"
		);
	}

	&main::Output(
		"# End Target\n",
		"# End Project\n",
		"#"x80
		);

	&main::Path_DelFiles("$PathBaseMak.mdp","$PathBaseMak.ncb");
}

1;
