Saturday, March 16, 2013

Compiling Python In Native MinGW

The official Python package lacks some modules and were built using MSVC. It's nice if we could have build Python in native MinGW environment and build all external modules in native MinGW without mixing them both (MSVC built Python with GCC built extensions). We need to patch the source in order to compile Python with MinGW because it's not officially supported (yet.. or will never be?). I'm using patches from mingwandroid & alexpux and make some minor adjustment to compile successfully with MinGW-w64 toolchains.

For this build, we need a new MinGW-w64 toolchains (previously we are using toolchains by NevCairiel) because nevcairiel's build lacks gfortran because it is needed afterwards to compile NumPy and SciPy for example. So, lets start with the basic part..




Preparing the toolchains.

The MSYS routine is the same as before.

Download ray_linn's toolchain here: mingw-w64-gcc-4.7.2-runtime-2.0.7-static-ada-gc-20121112.7z and extract it to 'c:\'

Optional: Remove the pthreads dll, lib and headers.


Updating the environment.

Add in 'c:/msys/etc/fstab':
c:/mingw64 /mingw


Add in 'c:/msys/etc/profile':
export CPPFLAGS="-Ic:/programs/dev/python64/include"
export LDFLAGS="-Lc:/programs/dev/python64/lib"
export PATH="$PATH:/c/programs/python27/bin:/c/programs/python64/bin"
export TERMINFO="c:/programs/python27/share/terminfo"
export lt_cv_deplibs_check_method="pass_all"


Compile extra libs for modules.

expat-2.1.0

http://sourceforge.net/projects/expat/files/expat/2.1.0/expat-2.1.0.tar.gz/download
cd expat-2.1.0
./configure --prefix=c:/programs/dev/python64 --build=x86_64-w64-mingw32 --disable-shared
make
make install

zlib-1.2.8
http://zlib.net/zlib-1.2.8.tar.bz2
patch: zlib-1.2.8_disable_shared.diff
cd zlib-1.2.8
patch -p1 <../zlib-1.2.8_disable_shared.diff

make prefix=c:/programs/dev/python64 libz.a -f win32/Makefile.gcc install

bzip2-1.0.6
http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
patch: bzip2-1.0.6_static_mingw.diff
cd bzip2-1.0.6
patch -p1 <../bzip2-1.0.6_static
_mingw.diff
make
install -m 644 bzlib.h c:/programs/dev/python64/include
install -m 644 libbz2.a c:/programs/dev/python64/lib

sqlite-3.7.15.2 
http://sqlite.org/sqlite-autoconf-3071502.tar.gz
export CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 \
-DSQLITE_ENABLE_UNLOCK_NOTIFY=1 -DSQLITE_SECURE_DELETE=1"
cd sqlite-autoconf-3071502
./configure --prefix=c:/programs/dev/python64 --build=x86_64-w64-mingw32 --disable-shared
make
make install

ncurses-5.9
http://invisible-island.net/datafiles/release/ncurses.tar.gz
cd ncurses-5.9-20131102
./configure --prefix=c:/programs/dev/python64 --build=x86_64-w64-mingw32 --with-progs --without-tests \
--without-cxx-binding --without-ada --without-debug --without-manpages --enable-overwrite --enable-widec \
--enable-term-driver --enable-assertions --enable-database --enable-sp-funcs --enable-hard-tabs \
--enable-ext-colors --enable-ext-mouse --enable-interop --disable-assumed-color --disable-termcap
make
make install

readline-5.0
http://ftp.gnu.org/gnu/readline/readline-5.0.tar.gz
patch: readline-5.0_ncursesw_mingw.diff
cd readline-5.0
patch -p1 <../readline-5.0_ncursesw
_mingw.diff
./configure --prefix=c:/programs/dev/python64 --build=x86_64-w64-mingw32 --with-curses --disable-shared
make
make install

openssl-1.0.1h
http://www.openssl.org/source/openssl-1.0.1h.tar.gz
patch: openssl-1.0.1h_static_mingw.diff
cd openssl-1.0.1h
patch -p1<../openssl-1.0.1h_static_mingw.diff
./configure --prefix=c:/programs/dev/python64 mingw64 no-zlib no-asm no-dso no-shared
make
make install

gdbm-1.10
http://ftp.gnu.org/pub/gnu/gdbm/gdbm-1.10.tar.gz
patch: gdbm-1.10_mingw.diff
cd gdbm-1.10
patch -p1 <../gdbm-1.10_mingw.diff
./configure --prefix=c:/programs/dev/python64 --build=x86_64-w64-mingw32 --disable-nls --disable-shared
make
make install

libffi-3.0.12
ftp://sourceware.org/pub/libffi/libffi-3.0.12.tar.gz
patch: libffi-3.0.12_mingw.diff
cd libffi-3.0.12
patch -p1 <../libffi-3.0.12_mingw.diff
./configure --prefix=c:/programs/dev/python64 --build=x86_64-w64-mingw32 --disable-shared
make
make install


tcl-8.6.1
http://sourceforge.net/projects/tcl/files/Tcl/8.6.1/tcl-core8.6.1-src.tar.gz/download
patch: tcl8.6.1_system_zlib_mingw.diff

cd tcl8.6.1/win
patch -p1 <../../tcl8.6.1_system_zlib_mingw.diff
./configure --prefix=c:/programs/python27 --build=x86_64-w64-mingw32 --enable-64bit
make
make install

tk-8.6.1
http://sourceforge.net/projects/tcl/files/Tcl/8.6.1/tk8.6.1-src.tar.gz/download
patch: tk8.6.1_mingw.diff
cd tk8.6.1/win
patch -p1 <../../tk8.6.1_mingw.diff
./configure --prefix=c:/programs/python27 --build=x86_64-w64-mingw32 --enable-64bit
make

make install

Compile Python.

Python-2.7.8

http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
patch: Python-2.7.8-1_mingw.diff
cd Python-2.7.8
patch -p1 <../Python-2.7.8-1_mingw.diff
mkdir _build64 && cd _build64
../configure --prefix=c:/programs/python27 --build=x86_64-w64-mingw32 --with-system-expat --with-system-ffi
make
Some modules were not built;
Python build finished, but the necessary bits to build these modules were not found:

_bsddb             bsddb185           dl
linuxaudiodev      nis                ossaudiodev
resource           sunaudiodev        termios


To test the compilation;
make test
Then install it;
make install

Downloads:

Python-2.7.8-1-mingw-x86_64.7z
Python-2.7.8-1-mingw-i686.7z

Python-3.4.1-1-mingw-x86_64.7z
Python-3.4.1-1-mingw-i686.7z

+ Now using '\\' as primary path separator instead of '/', and resulting
  in more test suites passed the test.
+ Fixed some failing test.
+ Cosmetic cleanups.


Old Versions:

Python-2.7.6-1-mingw-x86_64.7z

+ Added architecture bitness in 'COMPILER' string.
+ Added posix installation path for bdist_wininst & bdist_msi module.
+ Fixed some regrtest routines.
+ Removed some old unused codes for mingw port.

Python-2.7.3-2-mingw-x86_64.7z

+ Added 'pythonw.exe' to the build.
+ Now using shared Tcl/Tk.
+ Fixed some test routines.
+ Some minor fix.


Python-2.7.3-1-mingw-x86_64.7z 

+ Initial release.


Python running under mintty, with simple curses example:



Friday, March 1, 2013

Compiling SMPlayer

Continued from here.

After we have succeeded compiling MPlayer, it's nice if we can have a GUI for it. Although MPlayer have it's own frontend (more like a wrapper), it still shows the console window (which is sometimes annoying :) ). My favorite choice for MPlayer frontend is SMPlayer, so lets try compiling it from svn repository. We need to compile Qt first for its GUI engine.


Compile Qt

Download the source from here:
http://download.qt-project.org/archive/qt/4.8/4.8.4/qt-everywhere-opensource-src-4.8.4.zip

Extract the source to 'C:\Programs\Dev\qt-4.8.4'

We will only be using MinGW and Windows cmd.exe (run as Administrator) to build Qt and SMPlayer.

Launch cmd.exe and set some variables:

set QTDIR=C:\Programs\Dev\qt-4.8.4
set QMAKESPEC=%QTDIR%\mkspecs\win32-g++
set PATH=C:\MinGW64\bin;%QTDIR%\bin

Patch Qt source to enable static build (including QtWebkit and QtDesigner):
cd %QTDIR%
patch -p1 ../qt-4.8.4_mingw_static.diff

Configure Qt:

cd %QTDIR%
configure.exe -confirm-license -release -static -opensource -qt-style-windowsxp -qt-style-windowsvista -opengl desktop -audio-backend -webkit -no-exceptions -no-s60 -no-phonon -no-qt3support -nomake tests -nomake examples -nomake demos -nomake translations -nomake docs

Compile Qt:
mingw32-make

Avoid jobserver (-j#) when running mingw32-make to prevent race conditions.
We don't need to install Qt to other directory.



Compile SMPlayer

We need to set some variables before running qmake:
set QTDIR=C:\Programs\Dev\qt-4.8.4
set QMAKESPEC=%QTDIR%\mkspecs\win32-g++
set CPPFLAGS=%CPPFLAGS% -I%QTDIR%\include
set CXXFLAGS=%CXXFLAGS% -I%QTDIR%\include
set LFLAGS=%LFLAGS% -L%QTDIR%\lib
set PKG_CONFIG_PATH=%QTDIR%\lib\pkgconfig
set PATH=%PATH%;C:\MinGW64\bin;C:\MSYS\sbin\svn\bin;%QTDIR%\bin

Get the latest SMPlayer source from repo:

cd C:\Programs\Dev
svn co https://smplayer.svn.sourceforge.net/svnroot/smplayer/smplayer/trunk smplayer-svn

Compile SMPlayer:
cd C:\Programs\Dev\smplayer-svn
getrev.cmd
cd zlib
mingw32-make -f win32/makefile.gcc libz.a
cd ..\src
lrelease smplayer.pro
qmake DEFINES+=PORTABLE_APP
mingw32-make

The compiled smplayer.exe is located in 'C:\Programs\Dev\smplayer-svn\src\release'. Copy it to anywhere you like and launch it. This build can't register the supported filetypes because it was compiled as portable. If you want SMPlayer to be the default player for certain audio/video type, just right click the file and select 'Open with' > 'Choose default program...' , browse for your installed SMPlayer and tick 'Always use the selected program..bla..bla'.