Include multiple directories in RCFLAGS - makefile

I am using nmake to compile a makefile.msc file
I have to include the below directories
c:\Program Files (x86)\Windows Kits\8.1\Include\um
C:\Program Files (x86)\Windows Kits\8.1\Include\shared
C:\Program Files (x86)\Windows Kits\8.1\Include\winrt
in the /I atrribute of the RCFLAGS
What I have tried are below :
1st try:
RCFLAGS = /I "c:\Program Files (x86)\Windows Kits\8.1\Include\um" /I "C:\Program Files (x86)\Windows Kits\8.1\Include\shared" /I "C:\Program Files (x86)\Windows Kits\8.1\Include\winrt"
2nd try:
RCPATH = "'c:\Program Files (x86)\Windows Kits\8.1\Include\um':'C:\Program Files (x86)\Windows Kits\8.1\Include\shared':'C:\Program Files (x86)\Windows Kits\8.1\Include\winrt'"
RCFLAGS = /I $(RCPATH)
Everytime, RC complaints about different missing headers.
Please give a guideline on how to achieve what I am trying to do.
Many thanks in advance.
Edit : Many resources elaborate how to do this with CFLAGS but are
not specific about RCFLAGS. Moreover, there is little help if I do
a rc /?.

Finally resolved it by the below format :
-I "c:\Program Files (x86)\Windows Kits\8.1\Include\shared" -I "c:\Program Files (x86)\Windows Kits\8.1\Include\winrt" -I "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include"
Sounds silly though since the delimiter / is accepted for the first RCFLAGS attribute which is /dWIN32.

Related

Simple batch file only fails when called from nmake.exe

I have a simple batch file foo.bat:
#ECHO OFF
setlocal
echo %PATH%
WHERE /Q wsl.exe
if %ERRORLEVEL%% NEQ 0 (
echo No find wsl.exe %ERRORLEVEL%
exit /B
)
When I just run it in cmd or explicitly with cmd.exe /C foo.bat I have no problems. But if I put it into a nmake.exe Makefile:
all:
call foo.bat
.PHONY : all
and call it with nmake.exe /f Makefile all it will fail:
C:\cmder_mini\bin;C:\cmder_mini\vendor\bin;C:\cmder_mini\vendor\conemu-maximus5\ConEmu\Scripts;C:\cmder_mini\vendor\conemu-maximus5;C:\cmder_mini\vendor\conemu-maximus5\ConEmu;E:\VisualStudio\Common7\IDE\\Extensions\Microsoft\IntelliCode\CLI;E:\VisualStudio\VC\Tools\MSVC\14.30.30705\bin\HostX86\x86;E:\VisualStudio\Common7\IDE\VC\VCPackages;E:\VisualStudio\Common7\IDE\CommonExtensions\Microsoft\TestWindow;E:\VisualStudio\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;E:\VisualStudio\MSBuild\Current\bin\Roslyn;E:\VisualStudio\Team Tools\Performance Tools;C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\\x86;C:\Program Files (x86)\Windows Kits\10\bin\\x86;E:\VisualStudio\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework\v4.0.30319;E:\VisualStudio\Common7\IDE\;E:\VisualStudio\Common7\Tools\;C:\Program Files\CMake\bin;C:\Program Files\Python310\Scripts\;C:\Program Files\Python310\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;E:\home\nat\mulle-clang-project\13.0.0.1\bin;C:\Users\nat\AppData\Local\Microsoft\WindowsApps;E:\VisualStudio\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;E:\VisualStudio\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;E:\VisualStudio\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\cmder_mini
No find wsl.exe 1
NMAKE : fatal error U1077: 'call' : return code '0x1'
When I diff the output of the working script and the failing nmake run I get
1,5d0
<
< Microsoft (R) Program Maintenance Utility Version 14.30.30709.0
< Copyright (C) Microsoft Corporation. All rights reserved.
<
< call foo.bat
7,9d1
< No find wsl.exe 1
< NMAKE : fatal error U1077: 'call' : return code '0x1'
< Stop.
So the PATH is identical. Once it finds "wsl.exe" in PATH and once it doesn't ? I have no clue here...

I am not able to use the where command for program files

i want to use
where /r C:\Program Files (x86)\ used.cs
but it says i can't use them! how can i use the program files x86 without that error!
please help fast
You forgot to quote your path, otherwise where can't know that Files or (x86) is part of the path and used.cs is not!
where /r "C:\Program Files (x86)" used.cs

How to get each string in a list of strings?

I have a List of String separated by a space and enclosed in double quotes.
"D:\oracle\product\10.2.0\db_1\bin" "C:\ORACLE_HOME\bin" "C:\Program Files (x86)\Common Files\Oracle\Java\javapath" "C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\" "C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\" "C:\WINDOWS\system32" "C:\WINDOWS" "C:\WINDOWS\System32\Wbem" "C:\WINDOWS\System32\WindowsPowerShell\v1.0\" "C:\WINDOWS\System32\OpenSSH\" "C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL" "C:\Program Files\Intel\Intel(R) Management Engine Components\DAL" "C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT" "C:\Program Files\Intel\Intel(R) Management Engine Components\IPT" "C:\ProgramData\chocolatey\bin" "C:\Program Files\Git\cmd" "C:\Program Files\nodejs\" "C:\Program Files\OpenVPN\bin" "C:\Program Files\dotnet\" "C:\Users\admin\Desktop\hello\tasm\lib" "C:\Program Files\Java\jdk1.8.0_212\bin" "C:\MinGW\bin" "C:\src\flutter\bin" ""D:\oracle\product\10.2.0\db_1\bin" "C:\ORACLE_HOME\bin" "C:\Program Files (x86)\Common Files\Oracle\Java\javapath" "C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\" "C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\" "C:\WINDOW"" "C:\Users\admin\AppData\Local\Android\sdk\tools" "C:\Users\admin\AppData\Local\Android\sdk\platform-tools" "C:\Program Files\Java\jdk1.8.0_212\bin" "C:\Users\admin\anaconda3\condabin" ""
I want to get each one of them using a for loop in batch file.
I was trying to debug an batch file from another software (since it crashed because of the space between \Common Files\)
rmpath.cmd (Code)
#echo off
SETLOCAL ENABLEDELAYEDEXPANSION
if _%1==_ goto USAGE
set fqElement=%~fs1
set fpath="%PATH:;=" "%"
echo %fpath%
for %%p in (%fpath%) do (
set p2=%%~fsp
if /i NOT "!p2!"=="%fqElement%" (
if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
)
set path=!tpath!
ENDLOCAL & set path=%tpath%

How can I find the latest Visual Studio Developer Command Prompt in a batch file?

I need to write a batch file to complete a pre-build step in Visual Studio. As part of it, I need to call the Visual Studio Developer Command Prompt.
I know that for VS2015, the developer command prompt is located in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat.
Unfortunately, our build server has a different version of VS. Is there a simple way to find the latest VSDevCmd.bat for all (or most) versions of Visual Studio in a batch file, so the pre-build step will work on both environments?
You should use vswhere provided by the Microsoft Visual Studio Installer. You copy vswhere.exe to a known location. The wiki has a description on how to start the developer command prompt:
#if not defined _echo echo off
for /f "usebackq delims=" %%i in (`vswhere.exe -prerelease -latest -property installationPath`) do (
if exist "%%i\Common7\Tools\vsdevcmd.bat" (
%comspec% /k "%%i\Common7\Tools\vsdevcmd.bat" %*
exit /b
)
)
rem Instance or command prompt not found
exit /b 2
The thing that I do for CI-CD machines is use vcvarsall for non 2017 machines and vsdevcmd for 2017 ones. Script snippet below:
rem vsvarsall.bat does not work if there are quoted paths on %PATH%
set path=%path:"=%
rem this will work for non VS 2017 build machines
if exist "c:\progra~2\Micros~1.0\vc\vcvarsall.bat" (
call c:\progra~2\Micros~1.0\vc\vcvarsall.bat && goto :SetVSEnvFinished
)
echo vcvarsall.bat not found, looking for vsdevcmd.bat
rem Find and run vsdevcmd.bat
set "VS_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017"
rem The 2017 folder will not be present in Visual Studio 2017 Preview machines (such as 15.8 preview)
if not exist "%VS_PATH%" (
set "VS_PATH=C:\Program Files (x86)\Microsoft Visual Studio"
)
if not exist "%VS_PATH%" (
echo "%VS_PATH%" not found. Is Visual Studio installed? && goto :ErrorExit
)
for /f "delims=" %%F in ('dir /b /s "%VS_PATH%\vsdevcmd.bat" 2^>nul') do set VSDEVCMD_PATH=%%F
echo ********Executing %VSDEVCMD_PATH%********
call "%VSDEVCMD_PATH%"
goto :SetVSEnvFinished
:ErrorExit
exit /b 1
:SetVSEnvFinished
So for non 2017 ones, it will execute vcvarsall.bat (which sets up the VS environment). For 2017 versions, it will search for vsdevcmd.bat (in specific folder to reduce search time) and run it.
Hope this helps.
I've managed to cobble together a batch file that looks at parameters, then at the filesystem to try to figure out what version of VSDevCmd should be used. $(DevEnvDir) is sometimes *Undefined*, so we need to check for that too.
Tested on VS2015 Professional, VS2017 Professional, and VS2017 Enterprise.
REM Usage in VS build event: call "$(SolutionDir)\find_vsdevcmd.bat" "$(DevEnvDir)"
SET vsversion=
REM Get Visual Studio version, either from command prompt, or newest on filesystem
if [%1] == [] (
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Enterprise"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Professional"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Community"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2015"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2013"
) else goto :eof
) else if [%1] == ["*Undefined*"] (
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Enterprise"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Professional"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Community"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2015"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2013"
) else goto :eof
) else (
if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\"] (
SET vsversion="VS2017 Enterprise"
) else if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\"] (
SET vsversion="VS2017 Professional"
) else if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\"] (
SET vsversion="VS2017 Community"
) else if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\" (
SET vsversion="VS2015"
) else if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\" (
SET vsversion="VS2013"
) else goto :eof
)
if %vsversion% == "VS2017 Enterprise" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
ECHO VS2017 Enterprise
) else if %vsversion% == "VS2017 Professional" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat"
ECHO VS2017 Professional
) else if %vsversion% == "VS2017 Community" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"
ECHO VS2017 Community
) else if %vsversion% == "VS2015" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
ECHO VS2015
) else if %vsversion% == "VS2013" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat"
ECHO VS2013
) else goto :eof
call %vsdevcmd%

Echoing path variable in windows displaying twice

When i am trying to echo the system path variable it is showing the same thing twice.
My system path variable:
C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program Files
(x86)\PC Connectivity Solution\;C:\Program Files\Common
Files\MicrosoftShared\Windows Live;C:\Program Files
(x86)\CommonFiles\MicrosoftShared\WindowsLive;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Dell\DW WLAN Card;C:\Program Files\WIDCOMM\Bluetooth
Software\;C:\Program Files\WIDCOMM\Bluetooth
Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;
And when i echo it on cmd
echo %Path% it displays this
C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program Files
(x86)\PC Connectivity Solution\;C:\Program Files\Common
Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common
Files\Microsoft
Shared\WindowsLive;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Dell\DW WLAN Card;C:\ProgramFiles\WIDCOMM\Bluetooth
Software\;C:\Program Files\WIDCOMM\Bluetooth
Software\syswow64;C:\Program
Files(x86)\WindowsLive\Shared;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program
Files (x86)\PC ConnectivitySolution\;C:\Program Files\Common
Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common
Files\Microsoft Shared\Windows
Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Dell\DW WLAN Card;C:\Program Files\WIDCOMM\Bluetooth
Software\;C:\Program Files\WIDCOMM\Bluetooth
Software\syswow64;C:\Program Files
(x86)\WindowsLive\Shared;F:\Java\jdk1.6.0_38\bin\
Can anybody help why is it displaying same values twice? And is there side effects of this?
P.S: I have created a local Path variable as
%Path%F:\Java\jdk1.6.0_38\bin\
Sometime between WindosXP and Windows7 the interpretation of the user level PATH variable changed. Now it automatically appends the path to the system defined path rather than replacing it the way it previously did.
Thus your local path ends up being %PATH%;%PATH%;F:\Java\jdk1.6.0_36\bin
The good news is it works -- you find the desired files. The bad news is it takes slighly longer to find your java bin files.
Edit: The annoying news is that you can no longer override system defined commands. Defining user level PATH as mybin;%PATH% does not produce the desired results.
If you're doing this in the console you can create a batch script with the following content:
for /F "tokens=2* delims= " %%f IN ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path ^| findstr /i path') do set OLD_SYSTEM_PATH=%%g
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_SZ /d "%OLD_SYSTEM_PATH%;F:\Java\jdk1.6.0_36\bin"
Which basically takes the Path value from the registry and add your path to it. Note that also there is a limit of around 1024 characters in the Path length if you set it in the console with the Set command, and this code workaround this limit.

Resources