Running NSIS Natively On Linux
The NSIS source files are shipped with every official NSIS distribution as well with the development snapshots. The binary files distributed with the NSIS releases are compiled with the Microsoft Visual C++ 6.0 compiler. The source has also been tested to be compatible with the Microsoft Visual C++ .NET 2002/2003 compiler. The NSIS distribution includes Microsoft Visual C++ 6.0 project files, Microsoft Visual C++ .NET 2002/2003 automatically convert these files to a new format.
As of NSIS 2.01, the compiler, makensis, also compiles on POSIX platforms. POSIX platforms include Linux, *BSD, Mac OS X and others. You must first compile the exeheads to be able to compile makensis. This can be done on Windows using the methods explained above, or using a cross compiler ().
To build the cross compiler create a cross-compiler-src ( ie: /opt/cross-compiler-src ) directory and place ths following script in it:
build-cross.sh
#!/bin/sh
# This is my script for building a complete cross-compiler toolchain.
# It is based partly on Ray Kelm's script, which in turn was built on
# Mo Dejong's script for doing the same, but with some added fixes.
# The intent with this script is to build a cross-compiled version
# of the current MinGW environment.
#
# Updated by Sam Lantinga
# what flavor are we building?
TARGET=i686-mingw32msvc
# where does it go?
PREFIX=/opt/cross-tools
# you probably don't need to change anything from here down
TOPDIR=`pwd`
SRCDIR="$TOPDIR/source"
# These are the files from the MinGW 3.2.0 RC3 release
MINGW_URL=http://heanet.dl.sourceforge.net/sourceforge/mingw
GCC_VERSION=3.4.2-20040916-1
GCC=gcc-$GCC_VERSION
GCC_ARCHIVES="gcc-core-$GCC_VERSION-src.tar.gz gcc-g++-$GCC_VERSION-src.tar.gz"
GCC_PATCH=""
BINUTILS=binutils-2.15.91-20040904-1
BINUTILS_ARCHIVE=$BINUTILS-src.tar.gz
MINGW=mingw-runtime-3.7
MINGW_ARCHIVE=$MINGW.tar.gz
W32API=w32api-3.2
W32API_ARCHIVE=$W32API.tar.gz
# These are the files from the SDL website
SDL_URL=http://www.libsdl.org/extras/win32/common
OPENGL_ARCHIVE=opengl-devel.tar.gz
DIRECTX_ARCHIVE=directx-devel.tar.gz
# need install directory first on the path so gcc can find binutils
PATH="$PREFIX/bin:$PATH"
#
# download a file from a given url, only if it is not present
#
download_file()
{
cd "$SRCDIR"
if test ! -f $1 ; then
echo "Downloading $1"
wget "$2/$1"
if test ! -f $1 ; then
echo "Could not download $1"
exit 1
fi
else
echo "Found $1 in the srcdir $SRCDIR"
fi
cd "$TOPDIR"
}
download_files()
{
mkdir -p "$SRCDIR"
# Make sure wget is installed
if test "x`which wget`" = "x" ; then
echo "You need to install wget."
exit 1
fi
for file in $GCC_ARCHIVES; do
download_file "$file" "$MINGW_URL"
done
download_file "$BINUTILS_ARCHIVE" "$MINGW_URL"
download_file "$MINGW_ARCHIVE" "$MINGW_URL"
download_file "$W32API_ARCHIVE" "$MINGW_URL"
download_file "$OPENGL_ARCHIVE" "$SDL_URL"
download_file "$DIRECTX_ARCHIVE" "$SDL_URL"
}
install_libs()
{
echo "Installing cross libs and includes"
mkdir -p "$PREFIX/$TARGET"
cd "$PREFIX/$TARGET"
gzip dc "$SRCDIR/$MINGW_ARCHIVE" | tar xf
gzip dc "$SRCDIR/$W32API_ARCHIVE" | tar xf
gzip dc "$SRCDIR/$OPENGL_ARCHIVE" | tar xf
gzip dc "$SRCDIR/$DIRECTX_ARCHIVE" | tar xf
cd "$TOPDIR"
}
extract_binutils()
{
cd "$SRCDIR"
rm -rf "$BINUTILS"
echo "Extracting binutils"
gzip dc "$SRCDIR/$BINUTILS_ARCHIVE" | tar xf
cd "$TOPDIR"
}
configure_binutils()
{
cd "$TOPDIR"
rm rf "binutils$TARGET"
mkdir "binutils-$TARGET"
cd "binutils-$TARGET"
echo "Configuring binutils"
"$SRCDIR/$BINUTILS/configure" -prefix="$PREFIX" -target=$TARGET &> configure.log
cd "$TOPDIR"
}
build_binutils()
{
cd "$TOPDIR/binutils-$TARGET"
echo "Building binutils"
make &> make.log
if test $? -ne 0; then
echo "make failed log available: binutils$TARGET/make.log"
exit 1
fi
cd "$TOPDIR"
}
install_binutils()
{
cd "$TOPDIR/binutils-$TARGET"
echo "Installing binutils"
make install &> make-install.log
if test $? -ne 0; then
echo "install failed log available: binutils$TARGET/make-install.log"
exit 1
fi
cd "$TOPDIR"
}
extract_gcc()
{
cd "$SRCDIR"
rm -rf "$GCC"
echo "Extracting gcc"
for file in $GCC_ARCHIVES; do
gzip dc "$SRCDIR/$file" | tar xf
done
cd "$TOPDIR"
}
patch_gcc()
{
if [ "$GCC_PATCH" != "" ]; then
echo "Patching gcc"
cd "$SRCDIR/$GCC"
patch -p1 < "$SRCDIR/$GCC_PATCH"
cd "$TOPDIR"
fi
}
configure_gcc()
{
cd "$TOPDIR"
rm rf "gcc$TARGET"
mkdir "gcc-$TARGET"
cd "gcc-$TARGET"
echo "Configuring gcc"
"$SRCDIR/$GCC/configure" -v
-prefix="$PREFIX" -target=$TARGET
-withheaders="$PREFIX/$TARGET/include"
-withgnu-as -withgnu-ld
-withoutnewlib -disablemultilib &> configure.log
cd "$TOPDIR"
}
build_gcc()
{
cd "$TOPDIR/gcc-$TARGET"
echo "Building gcc"
make &> make.log
if test $? -ne 0; then
echo "make failed log available: gcc$TARGET/make.log"
exit 1
fi
cd "$TOPDIR"
}
install_gcc()
{
cd "$TOPDIR/gcc-$TARGET"
echo "Installing gcc"
make LANGUAGES="c c++" install &> make-install.log
if test $? -ne 0; then
echo "install failed log available: gcc$TARGET/make-install.log"
exit 1
fi
cd "$TOPDIR"
}
final_tweaks()
{
echo "Finalizing installation"
# remove gcc build headers
rm rf "$PREFIX/$TARGET/sysinclude"
# Add extra binary links
if [ ! -f "$PREFIX/$TARGET/bin/objdump" ]; then
ln "$PREFIX/bin/$TARGET-objdump" "$PREFIX/$TARGET/bin/objdump"
fi
# make cc and c++ symlinks to gcc and g++
if [ ! -f "$PREFIX/$TARGET/bin/g++" ]; then
ln "$PREFIX/bin/$TARGET-g++" "$PREFIX/$TARGET/bin/g++"
fi
if [ ! -f "$PREFIX/$TARGET/bin/cc" ]; then
ln -s "gcc" "$PREFIX/$TARGET/bin/cc"
fi
if [ ! -f "$PREFIX/$TARGET/bin/c++" ]; then
ln -s "g++" "$PREFIX/$TARGET/bin/c++"
fi
# strip all the binaries
ls "$PREFIX"/bin/* "$PREFIX/$TARGET"/bin/* | egrep -v '.dll$' |
while read file; do
strip "$file"
done
echo "Installation complete!"
}
download_files
install_libs
extract_binutils
configure_binutils
build_binutils
install_binutils
extract_gcc
patch_gcc
configure_gcc
build_gcc
install_gcc
final_tweaks
Execute this script and the cross compiler will be downloaded and installed to /opt/cross-tools.
Steps to compile NSIS using POSIX
How to do it:
1. Download the NSIS source (I used nsis206 in this example) from here.
2. Make a backup of the original source (ie: cp NSIS NSIS.orig)
3. cd NSIS/Source/exehead
4. Next go to NSIS/Source/exehead and create cross-make.sh script in that will be used with the cross compilation tools.
cross-make.sh
#!/bin/sh PREFIX=/opt/cross-tools TARGET=i686-mingw32msvc PATH="$PREFIX/bin:$PREFIX/$TARGET/bin:$PATH" export PATH exec make $*
5. chmod a+x /opt/nsis-src/NSIS/Source/exehead/cross-make.sh
6. execute /opt/nsis-src/NSIS/Source/exehead/cross-make.sh
7. cd ..
8. make makensis
9. cd ..
10. cp -a . /opt/nsis/lib
11. rm -Rf /opt/nsis/lib/Source
12. create a shell script named /opt/nsis/makensis to run your native version.
makensis
#!/bin/sh /opt/nsis/lib/makensis $*
13. chmod a+x /opt/nsis/lib/makensisThere were some issues with the cross-compiler header files. In linux the winnt.h header was not found as the code is looking for WinNT.h. I simply had to rename the file to have the appropriate title case.