Actions

Difference between revisions of "Vim/makevim"

From RonWareWiki

< Vim
(New page: The script I use to build vim: <code sh> #!/bin/sh # setup: die() { echo $2 exit $1 } vimdir=~/proj/vim if [ ! -d $vimdir ]; then vimdir=/c/vim7 ; fi if [ ! -d $vimdir ]; then vimdi...)
 
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
The script I use to build vim:
 
The script I use to build vim:
  
<code sh>
+
<code bash>
 
#!/bin/sh  
 
#!/bin/sh  
 +
# vim: ft=sh :
 +
 +
verbose='no'
  
# setup:
 
 
die()
 
die()
 
{
 
{
Line 10: 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:
 +
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
  
vimdir=~/proj/vim
+
if [ "$vimdir" == "" ]
 
 
if [ ! -d $vimdir ]; then vimdir=/c/vim7 ; fi
 
if [ ! -d $vimdir ]; then vimdir=~/src/vim ; fi
 
 
 
if [ ! -d $vimdir ]
 
 
then
 
then
 
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?
 +
cross='no'
 
rawos=`uname`
 
rawos=`uname`
 
os="?"
 
os="?"
 
if [ "$rawos" == "Darwin" ]; then os="Mac" ; fi
 
if [ "$rawos" == "Darwin" ]; then os="Mac" ; fi
 
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 [ "$os" == "?" ]
 
if [ "$os" == "?" ]
 
then
 
then
 
die 1 "I don't know what the OS ${rawos} is.  Please update script"
 
die 1 "I don't know what the OS ${rawos} is.  Please update script"
 
fi
 
fi
 
+
nowhere="/dev/null"
patches()
+
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()
 
{
 
{
patchvim
+
verbose "Cleaning previous VIM build"
 +
cd $vimdir
 +
make distclean 2>&1 > $nowhere
 +
cd -
 
}
 
}
 
+
clean()
+
patches()
 
{
 
{
echo "Cleaning previous VIM build"
+
verbose "Looking for patches"
pushd $vimdir
+
cd $vimdir
make distclean
+
if [ ! -d "diff" ]; then mkdir diff ; fi
popd
+
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()
 
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"
echo "Configuring VIM"
+
cd $vimdir
pushd $vimdir
 
 
./configure --with-features=big --with-compiledby="ron@ronware.org" CFLAGS="$cf"\
 
./configure --with-features=big --with-compiledby="ron@ronware.org" CFLAGS="$cf"\
 
2>&1 > config.log \
 
2>&1 > config.log \
 
|| die 2 "Failed to configure.  See config.log"
 
|| die 2 "Failed to configure.  See config.log"
popd
+
cd -
 
}
 
}
 +
 
build()
 
build()
 
{
 
{
echo "Building VIM"
+
verbose "Building VIM"
pushd $vimdir/src
+
cd $vimdir/src
 
make EXTRA_LIBS="-lsqlite3" \
 
make EXTRA_LIBS="-lsqlite3" \
 
2>&1 > ../make.log \
 
2>&1 > ../make.log \
 
|| die 3 "Make failed.  See make.log"
 
|| die 3 "Make failed.  See make.log"
popd
+
cd -
 
}
 
}
 +
 
install()
 
install()
 
{
 
{
 +
if [ "$os" == "Win" ] ; then return ; fi
 +
verbose "Installing VIM"
 +
cd $vimdir/src
 
sudo make install
 
sudo make install
 +
cd -
 
}
 
}
  
if [ "$1" == "-f" ]
+
win()
then
+
{
clean
+
verbose "Doing cross-compile for Windows"
patches
+
# do mingw cross-compile for windows
config
+
oldcwd=`pwd`
build  
+
oldpath=$PATH
install
+
 
 +
# 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
 
exit 0
fi
+
}
 +
 
 +
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}"
 +
}
  
if [ "$1" == "clean" ]
+
while [ "$1" != "" ]
then
+
do
clean
+
case "$1" in
exit 0
+
help) syntax ;;
fi
+
cross) cross='yes' ;;
 +
-f) clean; patches; config; build; install; exit 0; ;;
 +
clean) clean ;;
 +
-v) verbose='yes' ; banner ;;
 +
esac
  
patches
+
shift
build
+
done
install
 
  
 +
if [ "$cross" == "yes" ]
 +
then
 +
win
 +
else
 +
do_default
 +
fi
 
</code>
 
</code>

Latest revision as of 21:27, 27 April 2009

The script I use to build vim:

  1. !/bin/sh
  2. 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 }

  1. 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

  1. 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

  1. 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