[Libreoffice] .vimrc to compile source from within Vim
Eike Rathke
ooo at erack.de
Tue Aug 9 09:23:37 PDT 2011
Hi,
I took the wiki's Vim tip to build a module from within Vim and enhanced
it to compile the current source file (and only that) in both, dmake and
gbuild modules. If the current file is a Makefile, the entire module is
built using make. If the current file is build.lst, the entire module is
built using build. Should work (can't test at the moment due to a dying
graphics adapter) also with a detached gvim where sourcing the
environment is needed first. Attached.
Enjoy
Eike
--
PGP/OpenPGP/GnuPG encrypted mail preferred in all private communication.
Key ID: 0x293C05FD - 997A 4C60 CE41 0149 0DB3 9E96 2F1A D073 293C 05FD
-------------- next part --------------
" Call appropriate makeprg with Ctrl+K
map <C-K> :call Make()<CR>
if $SOLARENV == ""
" Normal makeprg, not in LibreOffice/OpenOffice.org environment
function Make()
make
endfun
else
" The root of the directory where we stop going further up, excluding.
" For example, if /libo/core is the tree's root, the root of that is /libo
let s:dir_root = fnamemodify( $SRC_ROOT, ":h" )
function DirLimit( dir )
return a:dir == s:dir_root
endfunction
function GetDotPath()
let l:dir = "."
while !DirLimit( l:dir ) && !filereadable( l:dir . "/Makefile" ) && !filereadable( l:dir . "/prj/build.lst" )
let l:dir .= "/.."
endwhile
if DirLimit( l:dir )
let l:dir = "."
else
" get rid of first ./
" The loop above could be changed to make this unnecessary, but
" as is it is identical to the one in GetModuleRoot()
let l:dir = substitute( dir, "\./", "", "" )
endif
return l:dir
endfunction
function GetModuleRoot()
let l:mods = ":p:h"
let l:dir = expand( "%" . l:mods )
while !DirLimit( l:dir ) && !filereadable( l:dir . "/Makefile" ) && !filereadable( l:dir . "/prj/build.lst" )
let l:mods .= ":h"
let l:dir = expand( "%" . l:mods )
endwhile
if DirLimit( l:dir )
let l:dir = expand( "%:p:h" )
endif
return l:dir
endfunction
function Make()
" cd into current file's directory before obtaining module's root
let l:my_local_path = expand("%:h")
if (l:my_local_path == "")
let l:my_local_path = "."
endif
exec 'lcd ' . l:my_local_path
if has("gui_running")
" Source environment for detached gvim. Use ENV.$INPATH instead of
" Env.Host.sh when building for more than one platform and
" ln -s Env.Host.sh ENV.$INPATH
" or something similar.
let l:mymake = "source $SRC_ROOT/Env.Host.sh && "
else
let l:mymake = ""
endif
let l:jobs = "1" " define how many jobs you want with make
let l:module = GetModuleRoot()
" Define the make tool, order is significant as a Makefile exists in
" the project's root returned as module if none exists in the module.
if expand( "%:t" ) == "Makefile"
" If the current file is a Makefile, gbuild the entire module.
exec 'lcd ' . l:module
let l:mymake .= "make -sr -j" . l:jobs . " wall=true debug=true"
elseif expand( "%:t" ) == "build.lst"
" If the current file is a build.lst, dmake the entire module.
let l:mymake .= "build.pl wall=true debug=true -P2 -- -P3"
elseif filereadable( "makefile.mk" )
let l:mymake .= "dmake wall=true debug=true " . GetDotPath() . "/$INPATH/slo/%:t:r.obj"
elseif filereadable( l:module . "/Makefile" )
exec 'lcd ' . l:module
" Pass target as full path constructed of now relative part.
let l:mymake .= "make -sr -j" . l:jobs . " wall=true debug=true $WORKDIR/CxxObject/" . fnamemodify( l:module, ":t" ) . "/%:.:h/%:t:r.o"
else
let l:mymake .= "build.pl wall=true debug=true -P2 -- -P3"
endif
let &makeprg = l:mymake
make
endfunction
endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20110809/7e6c48c2/attachment-0001.pgp>
More information about the LibreOffice
mailing list