Posted By

mwb1100 on 02/09/10


Tagged

run various compilers


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Tyster
thastyle


RunCL


 / Published in: DOS Batch
 

Script to run various compilers - tailored to make it easy to launch a compiler from an editor.

  1. @echo off
  2. goto end_comments
  3. rem --------------------------------------------------------
  4.  
  5. This script helps integrate compilers into UltraEdit
  6.  
  7. The first parameter is an ID for the compiler to use (vc60, vc71, vc80, etc.)
  8.  
  9. The second parameter is the file to compile.
  10.  
  11. Some notes:
  12.  
  13. 1) An example command line (for VC 2005)that would go into UltraEdit is:
  14.  
  15. c:\util\runcl.cmd vc80 "%f"
  16.  
  17. 1) the .pdb file is deleted if it exists. VC complains when there's a .pdb file
  18. already there but from a different compiler. I don't know why it doesn't just go ahead and
  19. overwrite it, but it doesn't.
  20.  
  21. rem --------------------------------------------------------
  22. :end_comments
  23.  
  24. if /i {%1}=={vc} goto set_params
  25. if /i {%1}=={msvc} goto set_params
  26. if /i {%1}=={cl} goto set_params
  27.  
  28. if /i {%1}=={vc60} goto set_params
  29. if /i {%1}=={vc6} goto set_params
  30. if /i {%1}=={vs98} goto set_params
  31. if /i {%1}=={vc98} goto set_params
  32.  
  33. if /i {%1}=={vc71} goto set_params
  34. if /i {%1}=={vs2003} goto set_params
  35. if /i {%1}=={vc2003} goto set_params
  36.  
  37. if /i {%1}=={vc80} goto set_params
  38. if /i {%1}=={vc8} goto set_params
  39. if /i {%1}=={vs2005} goto set_params
  40. if /i {%1}=={vc2005} goto set_params
  41.  
  42. if /i {%1}=={vc90} goto set_params
  43. if /i {%1}=={vc9} goto set_params
  44. if /i {%1}=={vs2008} goto set_params
  45. if /i {%1}=={vc2008} goto set_params
  46.  
  47. if /i {%1}=={vc10} goto set_params
  48. if /i {%1}=={vs2010} goto set_params
  49. if /i {%1}=={vc2010} goto set_params
  50.  
  51. if /i {%1}=={vc11} goto set_params
  52. if /i {%1}=={vs2012} goto set_params
  53. if /i {%1}=={vc2012} goto set_params
  54.  
  55. if /i {%1}=={gcc} goto set_params
  56. if /i {%1}=={gcc32} goto set_params
  57. if /i {%1}=={gcc64} goto set_params
  58. if /i {%1}=={mingw} goto set_params
  59. if /i {%1}=={mingw32} goto set_params
  60. if /i {%1}=={mingw64} goto set_params
  61.  
  62. if /i {%1}=={como} goto set_params
  63. if /i {%1}=={dm} goto set_params
  64. if /i {%1}=={test} goto set_params
  65.  
  66.  
  67. echo Unsupported Compiler: %1
  68. echo Usage:
  69. echo %0 ^<vc ^| vc60 ^| vc71 ^| vc80 ^| vc90 ^| vc10 ^| vc11 ^| como ^| dm ^| gcc ^| test^> ^<filename^>
  70. goto :eof
  71.  
  72. :set_params
  73. (set ECHO_COMMANDLINE=1)
  74. if {%CC_OPT%} == {} (set CC_OPT=/Wall)
  75. if {%CC_OPT_VC6%} == {} (set CC_OPT_VC6=) & rem VC6 doesn't support "/Wall"
  76. if {%WARNING_LEVEL%} == {} (set WARNING_LEVEL=3)
  77. rem if {%INTERSLICE_INCLUDE%} == {} (set INTERSLICE_INCLUDE=C:\DevTrees\includes;C:\DevTrees\Boost\boost_1_34_1)
  78. if {%INTERSLICE_INCLUDE%} == {} (set INTERSLICE_INCLUDE=C:\DevTrees\includes;C:\boost\boost_1_49_0)
  79. if {%WIN32_WINNT%} == {} (set WIN32_WINNT=0x0500)
  80. (set SOURCE_BASE_FILENAME=%~n2) & rem - base filename (without extension)
  81. (set SOURCE_FILE=%~f2) & rem - full path and filename
  82. (set SOURCE_FILEEXT=%~x2) & rem - just the extension
  83. (set PDB_FILE=%~dpn2.pdb) & rem - drive+path+basename followed by .pdb
  84. (set LIBRARIES=kernel32.lib user32.lib gdi32.lib advapi32.lib shlwapi.lib oleaut32.lib ws2_32.lib)
  85. (set x64=0)
  86. (set PROG_FILES=c:\Program Files)
  87.  
  88. rem - The ProgramFiles(x86) environment variable usually contains parens
  89. rem - when the variable is expanded, the ')' paren gets parsed as the
  90. rem - paren that ends a cmd.exe 'nesting' set of parens.
  91. rem -
  92. rem - This means YOU CANNOT USE the "ProgramFiles(x86)" environment
  93. rem - variable inside a block of cmd.exe command's enclosed in parens.
  94. rem -
  95. rem - Jeez - another straw in the pile of cmd scripting goofs...
  96. rem
  97. rem **NOTE** Johannes Roessel describes another way to use
  98. rem environment variables that contain parens in `set`
  99. rem statements: http://stackoverflow.com/questions/2771285/2771431#2771431
  100. rem
  101. rem essentially, put the stuff **after** the `set` command in quotes:
  102. rem
  103. rem set "PROG_FILES=%ProgramFilesx86%"
  104. rem
  105. rem Note, my workaround of not using those env vars inside a paren-
  106. rem delimted block was also described by him.
  107.  
  108. set ProgramFilesx86=%ProgramFiles(x86)%
  109. if not {"%ProgramFiles%"} == {""} set PROG_FILES=%ProgramFiles%
  110. if not {"%ProgramFilesx86%"} == {""} set PROG_FILES=%ProgramFilesx86%
  111. if not {"%ProgramFilesx86%"} == {""} (
  112. (set x64=1)
  113. )
  114. @rem echo PROG_FILES: "%PROG_FILES%"
  115. @echo off
  116.  
  117. goto %1
  118.  
  119.  
  120.  
  121. :delpdb
  122. rem subroutine to delete the PDB file
  123. if exist %PDB_FILE% del %PDB_FILE%
  124. goto :eof
  125.  
  126. :get_filetype
  127. rem subroutine to set the type of file on the commandline
  128. (set FILETYPE="")
  129. if /i "%SOURCE_FILEEXT%" == ".c" (set FILETYPE="C")
  130. if /i "%SOURCE_FILEEXT%" == ".cpp" (set FILETYPE="CPP")
  131. if /i "%SOURCE_FILEEXT%" == ".cxx" (set FILETYPE="CPP")
  132. if /i "%SOURCE_FILEEXT%" == ".cc" (set FILETYPE="CPP")
  133. goto :eof
  134.  
  135.  
  136. :msvc
  137. :vc
  138. :cl
  139. rem - a generic VC target - this will try to figure out the most recent version of
  140. rem visual studio on the machine and use that...
  141. rem
  142.  
  143. if exist "%PROG_FILES%\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat" goto vs2012
  144. if exist "%PROG_FILES%\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat" goto vs2010
  145. if exist "%PROG_FILES%\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat" goto vs2008
  146. if exist "%PROG_FILES%\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat" goto vs2005
  147. if exist "%PROG_FILES%\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat" goto vs2003
  148. if exist "%PROG_FILES%\Microsoft Visual Studio\VC98\Bin\vcvars32.bat" goto vc6
  149.  
  150. echo. Error: Could not find an appropriate MSVC compiler...
  151. goto :eof
  152.  
  153.  
  154.  
  155.  
  156. :vs98
  157. :vc98
  158. :vc60
  159. :vc6
  160. call :delpdb
  161. call :get_filetype
  162. if NOT %FILETYPE% == "C" (
  163. if NOT %FILETYPE% == "CPP" goto :not_compilable
  164. )
  165. call "%PROG_FILES%\Microsoft Visual Studio\VC98\Bin\vcvars32.bat"
  166. echo Visual C/C++ 6 (VC98) Compile...
  167. set INCLUDE=%INCLUDE%;%INTERSLICE_INCLUDE%
  168. set CC_OPT=%CC_OPT_VC6% -W%WARNING_LEVEL%
  169. (set CC="%PROG_FILES%\Microsoft Visual Studio\VC98\Bin\cl" %CC_OPT% /GX /Zi -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" /link /INCREMENTAL:NO %LIBRARIES%)
  170. call :exec %CC%
  171. goto :eof
  172.  
  173.  
  174. :vs2003
  175. :vc2003
  176. :vc71
  177. call :delpdb
  178. call :get_filetype
  179. if NOT %FILETYPE% == "C" (
  180. if NOT %FILETYPE% == "CPP" goto :not_compilable
  181. )
  182. call "%PROG_FILES%\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat"
  183. echo Visual C/C++ 2003 (VC 7.1) Compile...
  184. set INCLUDE=%INCLUDE%;%INTERSLICE_INCLUDE%
  185.  
  186. rem
  187. rem /Wall generates too many warnings from system includes, that I've decided
  188. rem just to not bother with it for VS2003 (so I use the VC6 options)
  189. rem
  190. set CC_OPT=%CC_OPT_VC6% -W%WARNING_LEVEL%
  191.  
  192. (set CC="%PROG_FILES%\Microsoft Visual Studio .NET 2003\Vc7\bin\cl" %CC_OPT% /Gi- /Zi /EHsc -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" /link /incremental:no %LIBRARIES%)
  193. call :exec %CC%
  194. goto :eof
  195.  
  196. :vs2005
  197. :vc2005
  198. :vc80
  199. :vc8
  200. call :delpdb
  201. call :get_filetype
  202. if NOT %FILETYPE% == "C" (
  203. if NOT %FILETYPE% == "CPP" goto :not_compilable
  204. )
  205. call "%PROG_FILES%\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
  206. echo Visual C/C++ 2005 (VC 8.0) Compile...
  207. set INCLUDE=%INCLUDE%;%INTERSLICE_INCLUDE%
  208. set CC_OPT=%CC_OPT% -W%WARNING_LEVEL%
  209. (set CC="%PROG_FILES%\Microsoft Visual Studio 8\VC\bin\cl.exe" %CC_OPT% /Zi /EHsc -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" /link /incremental:no %LIBRARIES%)
  210. call :exec %CC%
  211. goto :eof
  212.  
  213. :vs2008
  214. :vc2008
  215. :vc90
  216. :vc9
  217. call :delpdb
  218. call :get_filetype
  219. if NOT %FILETYPE% == "C" (
  220. if NOT %FILETYPE% == "CPP" goto :not_compilable
  221. )
  222. call "%PROG_FILES%\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
  223. echo Visual C/C++ 2008 (VC 9.0) Compile...
  224. set INCLUDE=%INCLUDE%;%INTERSLICE_INCLUDE%
  225. set CC_OPT=%CC_OPT% -W%WARNING_LEVEL%
  226. (set CC="%PROG_FILES%\Microsoft Visual Studio 9.0\VC\bin\cl.exe" %CC_OPT% /Zi /EHsc -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" /link /incremental:no %LIBRARIES%)
  227. call :exec %CC%
  228. goto :eof
  229.  
  230.  
  231. :vs2010
  232. :vc2010
  233. :vc10
  234. call :delpdb
  235. call :get_filetype
  236. if NOT %FILETYPE% == "C" (
  237. if NOT %FILETYPE% == "CPP" goto :not_compilable
  238. )
  239. call "%PROG_FILES%\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"
  240. echo Visual C/C++ 2010 (VC 10.0) Compile...
  241. set INCLUDE=%INCLUDE%;%INTERSLICE_INCLUDE%
  242. set CC_OPT=%CC_OPT% -W%WARNING_LEVEL%
  243. (set CC="%PROG_FILES%\Microsoft Visual Studio 10.0\VC\bin\cl.exe" %CC_OPT% /Zi /EHsc -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" /link /incremental:no %LIBRARIES%)
  244. call :exec %CC%
  245. goto :eof
  246.  
  247. :vs2012
  248. :vc2012
  249. :vc11
  250. call :delpdb
  251. call :get_filetype
  252. if NOT %FILETYPE% == "C" (
  253. if NOT %FILETYPE% == "CPP" goto :not_compilable
  254. )
  255. call "%PROG_FILES%\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat"
  256. echo Visual C/C++ 2012 (VC 11.0) Compile...
  257. set INCLUDE=%INCLUDE%;%INTERSLICE_INCLUDE%
  258. set CC_OPT=%CC_OPT% -W%WARNING_LEVEL%
  259. (set CC="%PROG_FILES%\Microsoft Visual Studio 11.0\VC\bin\cl.exe" %CC_OPT% /Zi /EHsc -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" /link /incremental:no %LIBRARIES%)
  260. call :exec %CC%
  261. goto :eof
  262.  
  263.  
  264. :como
  265. call :get_filetype
  266. if NOT %FILETYPE% == "C" (
  267. if NOT %FILETYPE% == "CPP" goto :not_compilable
  268. )
  269. rem - set up environment for Comeau C/C++ compiler
  270.  
  271. call "%PROG_FILES%\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
  272. set path=c:\como\xp4310beta2\bin;%path%
  273.  
  274. rem - COMO_MS_INCLUDE is a special environemnt variable that como uses internally to
  275. rem find headers for MSVC. It's not passed on the command line.
  276. set COMO_MS_INCLUDE=%PROG_FILES%\Microsoft Visual Studio 9.0\VC\include
  277.  
  278. rem - VS2008 installs the Platform SDK in the following directory instead of in the VS directory
  279. rem
  280. rem - Note that VS 2008 puts the SDK libraries in "C:\Program Files" even if the machine has a 64-bit OS.
  281.  
  282. rem - COMO_PLATFORM_SDK is a special env var that como uses internally (so it's not passed on
  283. rem any command line)
  284. set COMO_PLATFORM_SDK=c:\Program Files\Microsoft SDKs\Windows\v6.0A
  285.  
  286. rem - Comeau does not use the file extension to figure out whether to
  287. rem compile as C++ or straight C, so we need to do it
  288. rem
  289. rem - Also, there's some weirdness with the inline keyword and the
  290. rem Windows SDK (at least v6.0a, which comes with VC9)
  291. rem for C compiles, define "inline" to "__inline"
  292. rem
  293. rem That seems to help, but I'm not sure exactly what's going on...
  294. rem
  295. rem Oh, and use the "-D" option, not the "--define_macro" option -
  296. rem "--define_macro" causes a weird error about the "--c"
  297. rem command line option...
  298. rem
  299. set COMPILE_TYPE_OPT=--c++
  300. set COMO_INLINE=
  301. if %FILETYPE% == "C" (
  302. set COMPILE_TYPE_OPT=--c
  303. set COMO_INLINE=-D inline=__inline
  304. )
  305.  
  306.  
  307. set SOURCE_BASE_FILENAME=%SOURCE_BASE_FILENAME:"=%
  308.  
  309. rem - set up a compiler switch for INTERSLICE_INCLUDE if there's something there
  310. (set COMO_INCLUDE=)
  311. if NOT "%INTERSLICE_INCLUDE%" == "" (set COMO_INCLUDE=-I%INTERSLICE_INCLUDE:;= -I%)
  312.  
  313.  
  314. rem (set CC=como --plv %COMO_INLINE% -o "%SOURCE_BASE_FILENAME%.exe" %COMPILE_TYPE_OPT% "%SOURCE_FILE%")
  315. (set CC=como %COMO_INLINE% -c %COMPILE_TYPE_OPT% %COMO_INCLUDE% "%SOURCE_FILE%")
  316.  
  317. rem
  318. rem como needs to have the libraries it links to specified without spaces (even if the path is quoted)
  319. rem the following `for` command converts the long-filename-path for advapi32.lib to a path that
  320. rem only has short, 8.3 path components (no spaces). This uses the 'percent' ~s modifier available
  321. rem to the `for` command. (note that I couldn't use the actual percent sign in the comment, because the
  322. rem stinkin' cmd.exe parser actually throws some sort of syntax error even though it's in a comment -
  323. rem jeez, batch files really, really drive me crazy).
  324. rem
  325. for %%a in ("%COMO_PLATFORM_SDK%\Lib\AdvAPI32.Lib") do set advapi32lib=%%~sa
  326. (set LINK=como -o "%SOURCE_BASE_FILENAME%.exe" "%SOURCE_BASE_FILENAME%.obj" "%advapi32lib%")
  327.  
  328. @echo compile...
  329. call :exec %CC%
  330. @echo link...
  331. call :exec %LINK%
  332.  
  333. goto :eof
  334.  
  335. :dm
  336. call :get_filetype
  337. if NOT %FILETYPE% == "C" (
  338. if NOT %FILETYPE% == "CPP" goto :not_compilable
  339. )
  340. echo Digital Mars C/C++ Compile...
  341. rem - the following dumps Digital Mars compiler version info (I think scppn.exe is the actual compiler)
  342. for /F "usebackq tokens=1*" %%i in (`c:\dm\bin\scppn.exe`) do (
  343. if /i "%%i" == "Digital" echo %%i %%j
  344. )
  345.  
  346. rem - do not let any residual VC include path from the system environment get to DMC
  347. rem - the default DMC include path is set in the c:\dm\bin\sc.ini file
  348. (set INCLUDE=)
  349. rem - set up a compiler switch for INTERSLICE_INCLUDE if there's something there
  350. (set DMC_INCLUDE=)
  351. if NOT "%INTERSLICE_INCLUDE%" == "" (set DMC_INCLUDE=-I%INTERSLICE_INCLUDE%)
  352. rem - C++ compiles get an additional include directory that's set in the DMC_CPP_INCLUDE var
  353. (set DMC_CPP_INCLUDE=)
  354. if {%FILETYPE%} == {"CPP"} (set DMC_CPP_INCLUDE=-Ic:\dm\stlport\stlport)
  355. rem "C:\dm\bin\dmc" -Ae -v1 -r -g -mn %DMC_INCLUDE% %DMC_CPP_INCLUDE% -IC:/DevTrees/Boost/boost_1_34_1 -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" %LIBRARIES%
  356. (set CC="C:\dm\bin\dmc" -Ae -v1 -r -g -mn %DMC_INCLUDE% %DMC_CPP_INCLUDE% -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" %LIBRARIES%)
  357. call :exec %CC%
  358. goto :eof
  359.  
  360.  
  361. :mingw64
  362. :gcc64
  363. set GCC_TARGET=-m64
  364.  
  365. :mingw
  366. :mingw32
  367. :gcc
  368. :gcc32
  369. if "%GCC_TARGET%" == "" (set GCC_TARGET=-m32)
  370.  
  371. call :get_filetype
  372. if NOT %FILETYPE% == "C" (
  373. if NOT %FILETYPE% == "CPP" goto :not_compilable
  374. )
  375.  
  376.  
  377. rem some GCC options:
  378. rem
  379. rem -g compile in debugging information
  380. rem -Werror treat warnings as errors
  381. rem -Wextra enable extra warnings (unsigned compare with 0, comma expression with no side effects, etc)
  382. rem
  383. rem -E preprocess only (no compile/assembly/link)
  384. rem -E -dM causes GCC to dump pre-defined macros
  385. rem
  386. rem -M will cause included files to be listed (similar to /showIncludes)
  387. rem
  388. rem -S produce assembly output file filename.s (but won't link)
  389. rem -masm=intel use Intel syntax for assembly language
  390. rem
  391. rem -verbose-asm add some information to assembly output
  392. rem -instrument-functions add calls to user-supplied profiling functions
  393. rem
  394. rem -Wshadow warn if a variable for built-in function is hidden
  395. rem -Wcast-align warn if a pointer is cast to something with a stricter alignment
  396. rem
  397. rem -fmudflap add runtime buffer boundary checks
  398. rem
  399. rem -save-temps retain preprocessor and/or assembly outputs
  400. rem
  401. rem -std=c89
  402. rem -std=c90
  403. rem -std=c99
  404. rem -std=gnu90 (default for C compiles)
  405. rem -std=gnu99
  406. rem
  407. rem -std=c++98
  408. rem -std=c++0x
  409. rem -std=gnu++98 (default for C++ compiles)
  410. rem -std=gnu++0x
  411. rem
  412. rem -O0 disable optimizations (default)
  413. rem -O or -O1
  414. rem -O2
  415. rem -O3
  416. rem
  417. rem -x c compile files as C
  418. rem -x c++ compile files as C++
  419. rem -x none compile files according to extension
  420. rem
  421. rem other options for `-x` include c-header, cpp-output, c++-header,
  422. rem c++-cpp-output, java, objective-c, and many more.
  423.  
  424. rem --help=class[,qualifier]
  425. rem Print on the standard output a description of the command line options
  426. rem understood by the compiler that fit into a specific class. The class can be
  427. rem one of `optimizers', `warnings', `target', `params', or language:
  428. rem
  429. rem `optimizers'
  430. rem This will display all of the optimization options supported by the compiler.
  431. rem `warnings'
  432. rem This will display all of the options controlling warning messages produced by the compiler.
  433. rem `target'
  434. rem This will display target-specific options. Unlike the --target-help option however,
  435. rem target-specific options of the linker and assembler will not be displayed.
  436. rem This is because those tools do not currently support the extended --help= syntax.
  437. rem `params'
  438. rem This will display the values recognized by the --param option.
  439. rem language
  440. rem This will display the options supported for language, where language is the
  441. rem name of one of the languages supported in this version of GCC.
  442. rem `common'
  443. rem This will display the options that are common to all languages.
  444. rem
  445. rem It is possible to further refine the output of the --help= option by adding a comma
  446. rem separated list of qualifiers after the class. These can be any from the following list:
  447. rem
  448. rem `undocumented'
  449. rem Display only those options which are undocumented.
  450. rem `joined'
  451. rem Display options which take an argument that appears after an equal sign in
  452. rem the same continuous piece of text, such as: `--help=target'.
  453. rem `separate'
  454. rem Display options which take an argument that appears as a separate
  455. rem word following the original option, such as: `-o output-file'.
  456. rem
  457. rem use -Q with the above to display the actual setting instead of help for options:
  458. rem
  459. rem -Q --help=target # display options affected by target architecture setting
  460. rem -Q --help=warning # display warnings enabled/disbled
  461. rem
  462. rem These warning options are turned on by `-Wall` and/or `-Wextra`.
  463. rem
  464. rem They create too much noise for little test runs, and seem to provide little benefit,
  465. rem so I turn them off explicitly:
  466. rem
  467. rem -Wunused-parameter
  468. rem -Wunused-variable
  469. rem -Wunused-function
  470. rem
  471. rem These warnings cause common structure initializations (such as `= {0}` or not using full bracing)
  472. rem to cause warnings. So I turn them off explicitly as well:
  473. rem
  474. rem -Wmissing-field-initializers
  475. rem -Wmissing-braces
  476. rem
  477. rem set GCC_OPTS=-Wall
  478.  
  479. rem if MINGW_PATH isn't explicitly set, use the first of:
  480. rem c:\MinGW64\bin, c:\MinGW32\bin, or c:\MinGW\bin that we find
  481. if {%MINGW_PATH%} == {} if exist c:\MinGW64\bin\gcc.exe (set MINGW_PATH=c:\MinGW64\bin)
  482. if {%MINGW_PATH%} == {} if exist c:\MinGW32\bin\gcc.exe (set MINGW_PATH=c:\MinGW32\bin)
  483. if {%MINGW_PATH%} == {} if exist c:\MinGW\bin\gcc.exe (set MINGW_PATH=c:\MinGW\bin)
  484.  
  485. if "%GCC_WARNING_CONFIG%" == "" (
  486. (set GCC_WARNING_CONFIG=-Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-missing-field-initializers -Wno-missing-braces)
  487. )
  488.  
  489. if "%GCC_OPTS%" == "" (
  490. (set GCC_OPTS=-g -Wall -Wextra %GCC_WARNING_CONFIG%)
  491. )
  492.  
  493. if "%GCC_OPTS_C%" == "" (
  494. rem - default options that apply only to C builds
  495. (set GCC_OPTS_C=-Wstrict-prototypes)
  496. )
  497.  
  498. if "%GCC_OPTS_CPP%" == "" (
  499. rem - no default C++ only options yet
  500. (set GCC_OPTS_CPP=)
  501. )
  502.  
  503. echo GCC/MinGW C/C++ Compile...
  504. rem - collect the GCC version
  505. for /f %%a in ('%MINGW_PATH%\gcc -dumpversion') do (set GCC_VERSION=%%a)
  506. @echo GCC Version %GCC_VERSION%
  507. rem - do not let any residual VC include path from the system environement get to MinGW
  508. (set INCLUDE=%MINGW_PATH%\..\include)
  509. rem - set up a compiler switch for INTERSLICE_INCLUDE if there's something there
  510. (set GCC_INCLUDE=-I%INCLUDE%)
  511. if NOT "%INTERSLICE_INCLUDE%" == "" (set GCC_INCLUDE=%GCC_INCLUDE% -I%INTERSLICE_INCLUDE:;= -I%)
  512. rem - C++ compiles get an additional include directory that's set in the GCC_CPP_INCLUDE var
  513. (set GCC_CPP_INCLUDE=)
  514.  
  515.  
  516. rem C++ specific items
  517. if {%FILETYPE%} == {"CPP"} (
  518. (set GCC_OPTS=%GCC_OPTS% %GCC_OPTS_CPP%)
  519. (set GCC_CPP_INCLUDE=-I%INCLUDE%\c++\%GCC_VERSION%)
  520.  
  521. (set GCC_COMPILER="%MINGW_PATH%\g++")
  522. )
  523.  
  524. rem C specific items
  525. if {%FILETYPE%} == {"C"} (
  526. (set GCC_OPTS=%GCC_OPTS% %GCC_OPTS_C%)
  527.  
  528. (set GCC_COMPILER="%MINGW_PATH%\gcc")
  529. )
  530.  
  531.  
  532. rem set up the libraries for the gcc command line
  533. (set GCC_LIBRARIES=)
  534. for %%a in (%LIBRARIES%) do call :gcc_appendlib %%a
  535.  
  536. rem NOTE
  537. rem MinGW versions before 4.2.2 need to be in the path on Vista or later because
  538. rem of the _access() bug (worked around in later GCC builds with the
  539. rem -D__USE_MINGW_ACCESS hack). One of these days, I'll make the script
  540. rem smart enoough to detect this situation, but for now I'll just add the
  541. rem configured MinGW to the path (which I'd rather not do)...
  542. rem
  543. rem Versions 4.2.2 or later of MinGW (or earler versions running on XP) will find
  544. rem subprocesses just fine without being on the path because of the -B option.
  545. rem (-B is supported on GCC 2.96 or later - I've never used anything prior to 3.4.5)
  546. rem
  547. set PATH=%MINGW_PATH%;%PATH%
  548.  
  549. (set CC=%GCC_COMPILER% -B%MINGW_PATH% %GCC_TARGET% %GCC_OPTS% %GCC_CPP_INCLUDE% %GCC_INCLUDE% -D__USE_MINGW_ACCESS -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" %GCC_LIBRARIES% -o "%SOURCE_BASE_FILENAME%.exe")
  550. call :exec %CC%
  551. goto :eof
  552.  
  553. :gcc_appendlib
  554. (set GCC_LIBRARIES=%GCC_LIBRARIES% -l%~n1)
  555. goto :eof
  556.  
  557.  
  558.  
  559.  
  560. :exec
  561. if {%ECHO_ENVIRONMENT%} == {1} (
  562. set
  563. )
  564. if {%ECHO_COMMANDLINE%} == {1} (
  565. echo %*
  566. )
  567. %*
  568. goto :eof
  569.  
  570. :not_compilable
  571. echo Cannot compile a "%SOURCE_FILEEXT%" type of file
  572. goto :eof
  573.  
  574. :test
  575. echo current dir is:
  576. echo %%1: %1
  577. echo %%2: %2
  578. echo %%SOURCE_FILE%%: %SOURCE_FILE%
  579. echo %%SOURCE_FILEEXT%%: %SOURCE_FILEEXT%
  580. echo %%SOURCE_BASE_FILENAME%%: %SOURCE_BASE_FILENAME%
  581. echo %%PDB_FILE%%: %PDB_FILE%
  582. echo %%~d2: %~d2
  583. echo %%~p2: %~p2
  584. echo %%~n2: %~n2
  585. echo %%~x2: %~x2
  586. echo %%~dpn2: %~dpn2
  587. echo %%3: %3
  588. goto :eof

Report this snippet  

You need to login to post a comment.