Difference between revisions of "Vim/makevim"
From RonWareWiki
< Vim
Line 3: | Line 3: | ||
<code bash> | <code bash> | ||
#!/bin/sh | #!/bin/sh | ||
+ | # vim: ft=sh : | ||
+ | |||
+ | verbose='no' | ||
die() | die() | ||
Line 9: | Line 12: | ||
exit $1 | exit $1 | ||
} | } | ||
− | + | required() | |
+ | { | ||
+ | x=`which $1 2>&1` | ||
+ | if [ ! -x "$x" ] | ||
+ | then | ||
+ | die 100 "'$1' not found. Make sure it is installed and in your PATH" | ||
+ | fi | ||
+ | } | ||
+ | verbose() | ||
+ | { | ||
+ | if [ "$verbose" == "yes" ]; then echo $1; fi | ||
+ | } | ||
+ | |||
# findvim: | # findvim: | ||
vimdir="" | vimdir="" | ||
− | for v in ~/proj/vim | + | for v in ~/proj/vim /c/vim ~/src/vim |
do | do | ||
if [ -d $v ] | if [ -d $v ] | ||
Line 20: | Line 35: | ||
vimdir=$v | vimdir=$v | ||
break | break | ||
+ | fi | ||
+ | else | ||
+ | v=${v}7 | ||
+ | if [ -d $v ] | ||
+ | then | ||
+ | if [ -d $v/src ] | ||
+ | then | ||
+ | vimdir=$v | ||
+ | break | ||
+ | fi | ||
fi | fi | ||
fi | fi | ||
− | done | + | done |
if [ "$vimdir" == "" ] | if [ "$vimdir" == "" ] | ||
Line 28: | Line 53: | ||
die 1 "Cannot determine the VIM directory. Please update script" | die 1 "Cannot determine the VIM directory. Please update script" | ||
fi | fi | ||
− | + | ||
− | |||
# are we doing a cross-compile for Windows? | # are we doing a cross-compile for Windows? | ||
cross='no' | cross='no' | ||
Line 37: | Line 61: | ||
if [ "$rawos" == "Linux" ]; then os="Lin" ; fi | if [ "$rawos" == "Linux" ]; then os="Lin" ; fi | ||
if [ "$rawos" == "MINGW32_NT-5.1" ]; then os="Win" ; fi | if [ "$rawos" == "MINGW32_NT-5.1" ]; then os="Win" ; fi | ||
− | + | ||
if [ "$os" == "?" ] | if [ "$os" == "?" ] | ||
then | then | ||
Line 47: | Line 71: | ||
nowhere="NUL" | nowhere="NUL" | ||
fi | fi | ||
− | + | ||
# check for required programs: | # check for required programs: | ||
− | for p in diff ncftpls ncftpget patch gawk sed sort grep tail | + | for p in diff ncftpls ncftpget patch gawk sed sort grep tail ; do required $p ; done |
− | do | + | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | done | ||
− | |||
clean() | clean() | ||
{ | { | ||
− | + | verbose "Cleaning previous VIM build" | |
cd $vimdir | cd $vimdir | ||
make distclean 2>&1 > $nowhere | make distclean 2>&1 > $nowhere | ||
cd - | cd - | ||
} | } | ||
− | + | ||
patches() | patches() | ||
{ | { | ||
+ | verbose "Looking for patches" | ||
cd $vimdir | cd $vimdir | ||
if [ ! -d "diff" ]; then mkdir diff ; fi | if [ ! -d "diff" ]; then mkdir diff ; fi | ||
Line 74: | Line 92: | ||
vernumraw=`grep "define.*VIM_VERSION_SHORT" src/version.h` | vernumraw=`grep "define.*VIM_VERSION_SHORT" src/version.h` | ||
vernum=`echo $vernumraw | sed -e 's/[^.0-9]//g'` | vernum=`echo $vernumraw | sed -e 's/[^.0-9]//g'` | ||
− | unstable=`echo $vernumraw | sed -e 's/^[^"] | + | #unstable=`echo "#define VER \"1.2a\" b" | sed -e 's/[^"]*//'` |
+ | unstable=`echo $vernumraw | sed -e 's/[^"]*//'` | ||
+ | unstable=`echo $unstable | sed -e 's/"[^"]*$//'` | ||
unstable=`echo $unstable | sed -e 's/"//'` | unstable=`echo $unstable | sed -e 's/"//'` | ||
− | |||
unstable=`echo $unstable | sed -e 's/[0-9.]//g'` | unstable=`echo $unstable | sed -e 's/[0-9.]//g'` | ||
− | + | ||
patchnum=`gawk 'BEGIN{RS=";"} /included_patches\[]/{print $0;quit}' src/version.c \ | patchnum=`gawk 'BEGIN{RS=";"} /included_patches\[]/{print $0;quit}' src/version.c \ | ||
| sed -e 's/[^0-9]//g' | sort -n| tail -n 1` | | sed -e 's/[^0-9]//g' | sort -n| tail -n 1` | ||
patchnum=$(($patchnum + 1)) | patchnum=$(($patchnum + 1)) | ||
− | + | ||
cmd="ncftpls -u anonymous -p ron@ronware.org ftp://ftp.vim.org/pub/vim/${unstable}patches/$vernum/" | cmd="ncftpls -u anonymous -p ron@ronware.org ftp://ftp.vim.org/pub/vim/${unstable}patches/$vernum/" | ||
− | + | ||
echo "/$patchnum/,/END/" > diff/awk | echo "/$patchnum/,/END/" > diff/awk | ||
toget=`$cmd | grep $vernum | gawk -f diff/awk` | toget=`$cmd | grep $vernum | gawk -f diff/awk` | ||
− | + | ||
+ | lastpatch=$patchnum | ||
if [ "$toget" == "" ] | if [ "$toget" == "" ] | ||
then | then | ||
− | + | verbose "No new patches" | |
return 1 | return 1 | ||
else | else | ||
− | + | verbose "Getting and applying patches..." | |
for p in $toget | for p in $toget | ||
do | do | ||
Line 100: | Line 120: | ||
|| die 10 "Unable to get patch file" | || die 10 "Unable to get patch file" | ||
patch -s -F 3 -p0 -idiff/$p || die 11 "Unable to apply patch $p" | patch -s -F 3 -p0 -idiff/$p || die 11 "Unable to apply patch $p" | ||
+ | lastpatch=$patchnum | ||
done | done | ||
fi | fi | ||
+ | patchnum=`echo $patchnum | sed -e 's/.*\.//'` | ||
+ | echo "!define VER_PATCH $patchnum" > ../lastpatch | ||
cd - | cd - | ||
return 0 | return 0 | ||
} | } | ||
− | + | ||
config() | config() | ||
{ | { | ||
+ | verbose "Configuring VIM" | ||
cf="-O3 -s -fomit-frame-pointer -freg-struct-return -fmerge-all-constants" | cf="-O3 -s -fomit-frame-pointer -freg-struct-return -fmerge-all-constants" | ||
− | |||
cd $vimdir | cd $vimdir | ||
./configure --with-features=big --with-compiledby="ron@ronware.org" CFLAGS="$cf"\ | ./configure --with-features=big --with-compiledby="ron@ronware.org" CFLAGS="$cf"\ | ||
Line 116: | Line 139: | ||
cd - | cd - | ||
} | } | ||
− | + | ||
build() | build() | ||
{ | { | ||
− | + | verbose "Building VIM" | |
cd $vimdir/src | cd $vimdir/src | ||
make EXTRA_LIBS="-lsqlite3" \ | make EXTRA_LIBS="-lsqlite3" \ | ||
Line 126: | Line 149: | ||
cd - | cd - | ||
} | } | ||
− | + | ||
install() | install() | ||
{ | { | ||
if [ "$os" == "Win" ] ; then return ; fi | if [ "$os" == "Win" ] ; then return ; fi | ||
+ | verbose "Installing VIM" | ||
cd $vimdir/src | cd $vimdir/src | ||
sudo make install | sudo make install | ||
Line 135: | Line 159: | ||
} | } | ||
− | # | + | win() |
+ | { | ||
+ | verbose "Doing cross-compile for Windows" | ||
+ | # do mingw cross-compile for windows | ||
+ | oldcwd=`pwd` | ||
+ | oldpath=$PATH | ||
+ | |||
+ | # prerequisites: | ||
+ | for x in upx makensis ; do required $x; done | ||
− | + | export PATH=~/mingw/bin:$PATH | |
− | + | cd $vimdir/src | |
− | + | make -f Make_ming.mak gvim.exe CROSS=yes | |
− | + | upx --best gvim.exe | |
− | + | cp gvim.exe ../bin/gvim.exe | |
+ | cd .. | ||
+ | export PATH=$oldpath | ||
+ | vim readme.ron | ||
+ | echo "Building installer executable..." | ||
+ | makensis -Onsis.log gvim.nsi || echo "NSIS failed - see 'nsis.log'" | ||
− | + | cd $oldcwd | |
− | + | exit 0 | |
− | + | } | |
− | + | ||
− | + | do_default() | |
− | build | + | { |
− | install | + | # default is to update vim, and then build if that was ok |
+ | patches && build && install | ||
exit 0 | exit 0 | ||
− | + | } | |
+ | |||
+ | syntax() | ||
+ | { | ||
+ | cat <<EOF | ||
+ | Syntax: makevim [options] | ||
+ | 'options' may be one of: | ||
+ | 'help' - show this screen | ||
+ | '-f' - force clean rebuild | ||
+ | 'clean' - clean last build | ||
+ | 'cross' - do a cross-compile for Windows | ||
+ | '-v' - be verbose | ||
+ | |||
+ | If no options are given, makevim will check for new patches for the VIM | ||
+ | source installation on the system, download and install them, and build | ||
+ | VIM again. | ||
+ | |||
+ | By default, nothing is reported unless there is an error. If you use the "-v" | ||
+ | flag, you will be informed of each step being performed. | ||
+ | EOF | ||
+ | exit 0 | ||
+ | } | ||
+ | |||
+ | banner() | ||
+ | { | ||
+ | echo "makevim version 20090427" | ||
+ | echo "updating ${vimdir}" | ||
+ | } | ||
+ | |||
+ | while [ "$1" != "" ] | ||
+ | do | ||
+ | case "$1" in | ||
+ | help) syntax ;; | ||
+ | cross) cross='yes' ;; | ||
+ | -f) clean; patches; config; build; install; exit 0; ;; | ||
+ | clean) clean ;; | ||
+ | -v) verbose='yes' ; banner ;; | ||
+ | esac | ||
+ | |||
+ | shift | ||
+ | done | ||
− | if [ "$ | + | if [ "$cross" == "yes" ] |
− | then | + | then |
− | + | win | |
− | + | else | |
+ | do_default | ||
fi | fi | ||
− | |||
− | |||
− | |||
</code> | </code> |
Latest revision as of 21:27, 27 April 2009
The script I use to build vim:
- !/bin/sh
- vim: ft=sh :
verbose='no'
die()
{
echo $2
exit $1
}
required()
{
x=`which $1 2>&1`
if [ ! -x "$x" ]
then
die 100 "'$1' not found. Make sure it is installed and in your PATH"
fi
}
verbose()
{
if [ "$verbose" == "yes" ]; then echo $1; fi
}
- findvim:
vimdir=""
for v in ~/proj/vim /c/vim ~/src/vim
do
if [ -d $v ]
then
if [ -d $v/src ]
then
vimdir=$v
break
fi
else
v=${v}7
if [ -d $v ]
then
if [ -d $v/src ]
then
vimdir=$v
break
fi
fi
fi
done
if [ "$vimdir" == "" ]
then
die 1 "Cannot determine the VIM directory. Please update script"
fi
- are we doing a cross-compile for Windows?
cross='no'
rawos=`uname`
os="?"
if [ "$rawos" == "Darwin" ]; then os="Mac" ; fi
if [ "$rawos" == "Linux" ]; then os="Lin" ; fi
if [ "$rawos" == "MINGW32_NT-5.1" ]; then os="Win" ; fi
if [ "$os" == "?" ]
then
die 1 "I don't know what the OS ${rawos} is. Please update script"
fi
nowhere="/dev/null"
if [ "$os" == "Win" ]
then
nowhere="NUL"
fi
- check for required programs:
for p in diff ncftpls ncftpget patch gawk sed sort grep tail ; do required $p ; done
clean()
{
verbose "Cleaning previous VIM build"
cd $vimdir
make distclean 2>&1 > $nowhere
cd -
}
patches()
{
verbose "Looking for patches"
cd $vimdir
if [ ! -d "diff" ]; then mkdir diff ; fi
rm -f diff/*
# get vim's "short" version number:
vernumraw=`grep "define.*VIM_VERSION_SHORT" src/version.h`
vernum=`echo $vernumraw | sed -e 's/[^.0-9]//g'`
#unstable=`echo "#define VER \"1.2a\" b" | sed -e 's/[^"]*//'`
unstable=`echo $vernumraw | sed -e 's/[^"]*//'`
unstable=`echo $unstable | sed -e 's/"[^"]*$//'`
unstable=`echo $unstable | sed -e 's/"//'`
unstable=`echo $unstable | sed -e 's/[0-9.]//g'`
patchnum=`gawk 'BEGIN{RS=";"} /included_patches\[]/{print $0;quit}' src/version.c \
| sed -e 's/[^0-9]//g' | sort -n| tail -n 1`
patchnum=$(($patchnum + 1))
cmd="ncftpls -u anonymous -p ron@ronware.org ftp://ftp.vim.org/pub/vim/${unstable}patches/$vernum/"
echo "/$patchnum/,/END/" > diff/awk
toget=`$cmd | grep $vernum | gawk -f diff/awk`
lastpatch=$patchnum
if [ "$toget" == "" ]
then
verbose "No new patches"
return 1
else
verbose "Getting and applying patches..."
for p in $toget
do
ncftpget -u anonymous -p ron@ronware.org \
-C ftp://ftp.vim.org/pub/vim/${unstable}patches/$vernum/$p diff/$p \
|| die 10 "Unable to get patch file"
patch -s -F 3 -p0 -idiff/$p || die 11 "Unable to apply patch $p"
lastpatch=$patchnum
done
fi
patchnum=`echo $patchnum | sed -e 's/.*\.//'`
echo "!define VER_PATCH $patchnum" > ../lastpatch
cd -
return 0
}
config()
{
verbose "Configuring VIM"
cf="-O3 -s -fomit-frame-pointer -freg-struct-return -fmerge-all-constants"
cd $vimdir
./configure --with-features=big --with-compiledby="ron@ronware.org" CFLAGS="$cf"\
2>&1 > config.log \
|| die 2 "Failed to configure. See config.log"
cd -
}
build()
{
verbose "Building VIM"
cd $vimdir/src
make EXTRA_LIBS="-lsqlite3" \
2>&1 > ../make.log \
|| die 3 "Make failed. See make.log"
cd -
}
install()
{
if [ "$os" == "Win" ] ; then return ; fi
verbose "Installing VIM"
cd $vimdir/src
sudo make install
cd -
}
win()
{
verbose "Doing cross-compile for Windows"
# do mingw cross-compile for windows
oldcwd=`pwd`
oldpath=$PATH
# prerequisites:
for x in upx makensis ; do required $x; done
export PATH=~/mingw/bin:$PATH
cd $vimdir/src
make -f Make_ming.mak gvim.exe CROSS=yes
upx --best gvim.exe
cp gvim.exe ../bin/gvim.exe
cd ..
export PATH=$oldpath
vim readme.ron
echo "Building installer executable..."
makensis -Onsis.log gvim.nsi || echo "NSIS failed - see 'nsis.log'"
cd $oldcwd
exit 0
}
do_default()
{
# default is to update vim, and then build if that was ok
patches && build && install
exit 0
}
syntax()
{
cat <<EOF
Syntax: makevim [options]
'options' may be one of:
'help' - show this screen
'-f' - force clean rebuild
'clean' - clean last build
'cross' - do a cross-compile for Windows
'-v' - be verbose
If no options are given, makevim will check for new patches for the VIM
source installation on the system, download and install them, and build
VIM again.
By default, nothing is reported unless there is an error. If you use the "-v"
flag, you will be informed of each step being performed.
EOF
exit 0
}
banner()
{
echo "makevim version 20090427"
echo "updating ${vimdir}"
}
while [ "$1" != "" ]
do
case "$1" in
help) syntax ;;
cross) cross='yes' ;;
-f) clean; patches; config; build; install; exit 0; ;;
clean) clean ;;
-v) verbose='yes' ; banner ;;
esac
shift
done
if [ "$cross" == "yes" ]
then
win
else
do_default
fi