" " Functions to compile and link a single c/cpp file. " "if exists("g:loaded_vahagn_compiler") | finish | endif let g:loaded_vahagn_compiler = 1 " " Make sure let-modeline.vim is loaded. " if !exists('*FirstModeLine') runtime plugin/let-modeline.vim endif " " Windows " let g:argv="" let g:cppflags="" let g:wcppflags="/O2 /EHsc /DWIN32" function! s:CompileMSVC() let exename=expand("%:p:r:s,$,.exe,") let srcname=expand("%") " compile it let ccline="cl ".$CXXFLAGS." ".g:cppflags." ".g:wcppflags." ".srcname." /Fe".exename." /link ".$LDFLAGS echo ccline let cout = system( ccline ) if v:shell_error echo cout return endif echo cout " run it let cmd = exename . " " . g:argv echo cmd let eout = system( cmd ) echo eout endfunction function! s:CompileJava() " compile it let cmd = "javac " . g:javaflags . " " . expand("%") echo cmd let cout = system( cmd ) echo cout if v:shell_error return endif " run it "let classpath=expand("%:p:r") let exename=expand("%:r") let cmd = "java " . exename . " " . g:argv echo cmd let eout = system( cmd ) echo eout endfunction function! s:CompileWindows() let ext=expand("%:e") if ext=="java" call s:CompileJava() endif if ext=="cpp" call s:CompileMSVC() endif endfunction " " Linux " let g:lcppflags="-O2" function! s:CompileGCC() let exename=expand("%:p:r:s,$,.exe,") let srcname=expand("%") " compile it let ccline="g++ ".g:cppflags." ".g:lcppflags." ".srcname." -o".exename echo ccline let cout = system( ccline ) if v:shell_error echo cout return endif echo cout " run it let cmdline="LD_LIBRARY_PATH=".g:ldlibrarypath.":".$LD_LIBRARY_PATH." ".exename echo cmdline let eout = system( cmdline ) echo eout endfunction function! s:CompileLinux() call s:CompileGCC() endfunction " " Load compile instructions and call window or linux compiler. " function! CF5Compile() " " Source compile-opt.vim if exists. " let copt=expand("%:p:h")."/compile-opt.vim" if filereadable(copt) source copt endif " " Set source specific compiler options. " call FirstModeLine() "if exists("g:cf5script") " execute g:cf5script "endif " " Compile. " if has("win32") || has("win64") call s:CompileWindows() else call s:CompileLinux() endif endfunction