Skip to content

Instantly share code, notes, and snippets.

@iki
Last active December 29, 2015 00:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iki/7584101 to your computer and use it in GitHub Desktop.
Save iki/7584101 to your computer and use it in GitHub Desktop.
Getting started in a m.e.a.n. way (MongoDB, Express, AngularJS, Node.js)
@echo off
setlocal enableextensions
::: echo === "%~f0" %* >&2
set vcArgs=%*
set vcVersions=11 10
call :poparg vcArgs vcVersions 10 10 %1 && shift
call :poparg vcArgs vcVersions 11 11 %1 && shift
call :test vcVarsAll
for %%v in (%vcVersions%) do (
call :test vcVarsAll "%ProgramFiles%\Microsoft Visual Studio %%v.0\VC"
call :test vcVarsAll "%ProgramFiles(x86)%\Microsoft Visual Studio %%v.0\VC"
)
if not defined vcVarsAll echo "Could not locate Visual Studio %vcVersions: =/%." >&2 && exit /b 1
set vcArch=
if defined PROCESSOR_ARCHITECTURE set vcArch=%PROCESSOR_ARCHITECTURE%
if defined PROCESSOR_ARCHITEW6432 set vcArch=%PROCESSOR_ARCHITECTURE%_%PROCESSOR_ARCHITEW6432%
call :poparg vcArgs vcArch x86 32 %1 && shift
call :poparg vcArgs vcArch amd64 64 %1 && shift
call :poparg vcArgs vcArch x86_amd64 3264 %1 && shift
for %%a in (x86 x64 amd64 arm x86_arm x86_amd64) do call :poparg vcArch %%a %%a %1 && shift
if "%~1"=="" goto shell
echo === "%vcVarsAll%" %vcArch% >&2
call "%vcVarsAll%" %vcArch%
if errorlevel 1 exit /b %errorlevel%
echo === %vcArgs% >&2
call %vcArgs%
exit /b %errorlevel%
:shell
echo === "%comspec%" /k "%vcVarsAll%" %vcArch% >&2
"%comspec%" /k "%vcVarsAll%" %vcArch%
exit /b %errorlevel%
:poparg
if /i not "%~5"=="%~4" if /i not "%~5"=="--%~4" exit /b 1
set %~2=%~3
::: echo ... %~2: %~3 [%~5] >&2
if not "%~1"=="" call :eval set %~1=%%%~1:*%4=%%
if not "%~1"=="" call :eval if "%%%~1:~0,1%%"==" " set %~1=%%%~1:* =%%
exit /b 0
:eval
%*
exit /b %errorlevel%
:test
if "%~2"=="" set %~1=&& exit /b
if defined %~1 exit /b 2
if not exist "%~2\vcvarsall.bat" exit /b 1
::: echo ... %~1: %~2 >&2
set %~1=%~2\vcvarsall.bat
exit /b %errorlevel%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment