/ Published in: DOS Batch
Script to run various compilers - tailored to make it easy to launch a compiler from an editor.
Expand |
Embed | Plain Text
@echo off goto end_comments rem -------------------------------------------------------- This script helps integrate compilers into UltraEdit The second parameter is the file to compile. Some notes: c:\util\runcl.cmd vc80 "%f" already there but from a different compiler. I don't know why it doesn't just go ahead and overwrite it, but it doesn't. rem -------------------------------------------------------- :end_comments echo Usage: echo %0 ^<vc ^| vc60 ^| vc71 ^| vc80 ^| vc90 ^| vc10 ^| vc11 ^| como ^| dm ^| gcc ^| test^> ^<filename^> goto :eof :set_params rem - The ProgramFiles(x86) environment variable usually contains parens rem - when the variable is expanded, the ')' paren gets parsed as the rem - paren that ends a cmd.exe 'nesting' set of parens. rem - rem - This means YOU CANNOT USE the "ProgramFiles(x86)" environment rem - variable inside a block of cmd.exe command's enclosed in parens. rem - rem - Jeez - another straw in the pile of cmd scripting goofs... rem rem **NOTE** Johannes Roessel describes another way to use rem statements: http://stackoverflow.com/questions/2771285/2771431#2771431 rem rem rem rem Note, my workaround of not using those env vars inside a paren- rem delimted block was also described by him. ) @echo off goto %1 :delpdb rem subroutine to delete the PDB file goto :eof :get_filetype rem subroutine to set the type of file on the commandline goto :eof :msvc :vc :cl rem - a generic VC target - this will try to figure out the most recent version of rem visual studio on the machine and use that... rem goto :eof :vs98 :vc98 :vc60 :vc6 call :delpdb call :get_filetype ) (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%) call :exec %CC% goto :eof :vs2003 :vc2003 :vc71 call :delpdb call :get_filetype ) rem rem /Wall generates too many warnings from system includes, that I've decided rem (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%) call :exec %CC% goto :eof :vs2005 :vc2005 :vc80 :vc8 call :delpdb call :get_filetype ) (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%) call :exec %CC% goto :eof :vs2008 :vc2008 :vc90 :vc9 call :delpdb call :get_filetype ) (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%) call :exec %CC% goto :eof :vs2010 :vc2010 :vc10 call :delpdb call :get_filetype ) (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%) call :exec %CC% goto :eof :vs2012 :vc2012 :vc11 call :delpdb call :get_filetype ) (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%) call :exec %CC% goto :eof :como call :get_filetype ) rem - COMO_MS_INCLUDE is a special environemnt variable that como uses internally to rem rem any command line) set COMO_PLATFORM_SDK=c:\Program Files\Microsoft SDKs\Windows\v6.0A rem - Comeau does not use the file extension to figure out whether to rem compile as C++ or straight C, so we need to do it rem rem - Also, there's some weirdness with the inline keyword and the rem Windows SDK (at least v6.0a, which comes with VC9) rem for C compiles, define "inline" to "__inline" rem rem That seems to help, but I'm not sure exactly what's going on... rem rem Oh, and use the "-D" option, not the "--define_macro" option - rem "--define_macro" causes a weird error about the "--c" rem command line option... rem set COMPILE_TYPE_OPT=--c++ set COMO_INLINE= set COMPILE_TYPE_OPT=--c set COMO_INLINE=-D inline=__inline ) rem (set CC=como --plv %COMO_INLINE% -o "%SOURCE_BASE_FILENAME%.exe" %COMPILE_TYPE_OPT% "%SOURCE_FILE%") rem rem como needs to have the libraries it links to specified without spaces (even if the path is quoted) rem only has short, 8.3 path components (no spaces). This uses the 'percent' ~s modifier available rem stinkin' cmd.exe parser actually throws some sort of syntax error even though it's in a comment - rem jeez, batch files really, really drive me crazy). rem @echo. @echo compile... call :exec %CC% @echo link... call :exec %LINK% goto :eof :dm call :get_filetype ) echo Digital Mars C/C++ Compile... rem - the following dumps Digital Mars compiler version info (I think scppn.exe is the actual compiler) ) echo. 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% (set CC="C:\dm\bin\dmc" -Ae -v1 -r -g -mn %DMC_INCLUDE% %DMC_CPP_INCLUDE% -D_WIN32_WINNT=%WIN32_WINNT% "%SOURCE_FILE%" %LIBRARIES%) call :exec %CC% goto :eof :mingw64 :gcc64 set GCC_TARGET=-m64 :mingw :mingw32 :gcc :gcc32 call :get_filetype ) rem some GCC options: rem rem -g compile in debugging information rem -Werror treat warnings as errors rem -Wextra enable extra warnings (unsigned compare with 0, comma expression with no side effects, etc) rem rem -E preprocess only (no compile/assembly/link) rem -E -dM causes GCC to dump pre-defined macros rem rem -M will cause included files to be listed (similar to /showIncludes) rem rem -S produce assembly output file filename.s (but won't link) rem -masm=intel use Intel syntax for assembly language rem rem -verbose-asm add some information to assembly output rem -instrument-functions add calls to user-supplied profiling functions rem rem -Wcast-align warn if a pointer is cast to something with a stricter alignment rem rem -fmudflap add runtime buffer boundary checks rem rem -save-temps retain preprocessor and/or assembly outputs rem rem -std=c89 rem -std=c90 rem -std=c99 rem -std=gnu99 rem rem -std=c++98 rem -std=c++0x rem -std=gnu++0x rem rem -O0 disable optimizations (default) rem -O or -O1 rem -O2 rem -O3 rem rem -x c compile files as C rem -x c++ compile files as C++ rem -x none compile files according to extension rem rem other options for `-x` include c-header, cpp-output, c++-header, rem c++-cpp-output, java, objective-c, and many more. rem --help=class[,qualifier] rem Print on the standard output a description of the command line options rem understood by the compiler that fit into a specific class. The class can be rem one of `optimizers', `warnings', `target', `params', or language: rem rem `optimizers' rem This will display all of the optimization options supported by the compiler. rem `warnings' rem This will display all of the options controlling warning messages produced by the compiler. rem `target' rem This will display target-specific options. Unlike the --target-help option however, rem target-specific options of the linker and assembler will not be displayed. rem `params' rem This will display the values recognized by the --param option. rem language rem This will display the options supported for language, where language is the rem name of one of the languages supported in this version of GCC. rem `common' rem This will display the options that are common to all languages. rem rem It is possible to further refine the output of the --help= option by adding a comma rem separated list of qualifiers after the class. These can be any from the following list: rem rem `undocumented' rem Display only those options which are undocumented. rem `joined' rem Display options which take an argument that appears after an equal sign in rem the same continuous piece of text, such as: `--help=target'. rem `separate' rem Display options which take an argument that appears as a separate rem word following the original option, such as: `-o output-file'. rem rem use -Q with the above to display the actual setting instead of help for options: rem rem -Q --help=target # display options affected by target architecture setting rem -Q --help=warning # display warnings enabled/disbled rem rem These warning options are turned on by `-Wall` and/or `-Wextra`. rem rem They create too much noise for little test runs, and seem to provide little benefit, rem so I turn them off explicitly: rem rem -Wunused-parameter rem -Wunused-variable rem -Wunused-function rem rem These warnings cause common structure initializations (such as `= {0}` or not using full bracing) rem to cause warnings. So I turn them off explicitly as well: rem rem -Wmissing-field-initializers rem -Wmissing-braces rem rem c:\MinGW64\bin, c:\MinGW32\bin, or c:\MinGW\bin that we find (set GCC_WARNING_CONFIG=-Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-missing-field-initializers -Wno-missing-braces) ) ) rem - default options that apply only to C builds ) rem - no default C++ only options yet ) echo GCC/MinGW C/C++ Compile... rem - collect the GCC version rem C++ specific items ) rem C specific items ) rem NOTE rem MinGW versions before 4.2.2 need to be in the path on Vista or later because rem -D__USE_MINGW_ACCESS hack). One of these days, I'll make the script rem smart enoough to detect this situation, but for now I'll just add the rem rem Versions 4.2.2 or later of MinGW (or earler versions running on XP) will find rem subprocesses just fine without being on the path because of the -B option. rem (-B is supported on GCC 2.96 or later - I've never used anything prior to 3.4.5) rem (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") call :exec %CC% goto :eof :gcc_appendlib goto :eof :exec if {%ECHO_ENVIRONMENT%} == {1} ( set ) if {%ECHO_COMMANDLINE%} == {1} ( echo %* ) %* goto :eof :not_compilable goto :eof :test echo %%~p2: %~p2 echo %%~x2: %~x2 echo %%3: %3 goto :eof
You need to login to post a comment.
