wscript
import os
import shutil
from waflib.TaskGen import feature, before_method
WIN32_LIBS = [
'glib-2.0',
'libxml-2.0',
'gio-2.0',
'libsoup-2.4',
'gtk+-2.0',
'webkit-1.0'
]
WIN32_DLLS = [
"libcairo-2.dll",
"libgdk-win32-2.0-0.dll",
"libgdk_pixbuf-2.0-0.dll",
"libgio-2.0-0.dll",
"libglib-2.0-0.dll",
"libgobject-2.0-0.dll",
"libgthread-2.0-0.dll",
"libgtk-win32-2.0-0.dll",
"libxml2-2.dll",
"libfontconfig-1.dll",
"libfreetype-6.dll",
"libpixman-1-0.dll",
"libpng15-15.dll",
"zlib1.dll",
"libpixman-1-0.dll",
"libpng15-15.dll",
"libintl-8.dll",
"libgmodule-2.0-0.dll",
"libffi-5.dll",
"libgobject-2.0-0.dll",
"libjasper-1.dll",
"libjpeg-8.dll",
"libtiff-5.dll",
"libgdk_pixbuf-2.0-0.dll",
"libpango-1.0-0.dll",
"libpangocairo-1.0-0.dll",
"libgdk-win32-2.0-0.dll",
"libgmodule-2.0-0.dll",
"libexpat-1.dll",
"libpangoft2-1.0-0.dll",
"libpangowin32-1.0-0.dll",
"libpangocairo-1.0-0.dll",
"libgdk-win32-2.0-0.dll",
"libpangoft2-1.0-0.dll",
"libpangowin32-1.0-0.dll",
"libpangocairo-1.0-0.dll",
"libatk-1.0-0.dll",
"libsoup-2.4-1.dll",
"libsqlite3-0.dll",
"libxslt-1.dll",
"libgcc_s_sjlj-1.dll",
"libstdc++-6.dll",
"libjavascriptcoregtk-1.0-0.dll",
"libenchant-1.dll",
"libgailutil-18.dll",
"libwebkitgtk-1.0-0.dll",
"pthreadGC2.dll"
]
@feature('have_windows_runtime')
@before_method('process_source')
def have_windows_runtime(self):
for pkg in WIN32_LIBS:
self.bld(rule='i686-w64-mingw32-pkg-config --cflags --libs '+ pkg, always=True, name=pkg)
self.source = []
def configure(conf):
print("")
print("Crosscompile for windows")
conf.find_program('i686-w64-mingw32-gcc', var='MINGW32GCC')
conf.find_program('i686-w64-mingw32-pkg-config', var='MINGW32PKG-CONFIG')
conf.find_program('windres', var='WINDRES')
conf.check_cc(features='have_windows_runtime', msg='Checking windows runtimes')
if conf.options.installer :
conf.find_program('wine', var='wine')
conf.find_program(os.getenv("HOME") + "/.wine/drive_c/Program/NSIS/makensis.exe", always=True)
def build(bld):
bld(rule="mkdir -p build/supplement")
bld(rule="windres ${SRC} -O coff -o ${TGT}", source="../win32/icon.rc", target="icon.res", always=True)
bld(rule="mv ${SRC} ${TGT}", source="../win32/icon.res", target="../build/", name="icon", always=True)
bld(
rule="""i686-w64-mingw32-gcc \
-c ./Main.c ./GtkWindow.c ./BirdfontExport.c ./libbirdfont/*.c ./ \
-D 'GETTEXT_PACKAGE="birdfont"' \
-I ./ \
-mthreads \
$(i686-w64-mingw32-pkg-config --cflags --libs glib-2.0) \
$(i686-w64-mingw32-pkg-config --cflags --libs libxml-2.0) \
$(i686-w64-mingw32-pkg-config --cflags --libs gio-2.0) \
$(i686-w64-mingw32-pkg-config --cflags --libs libsoup-2.4) \
$(i686-w64-mingw32-pkg-config --cflags --libs gtk+-2.0) \
$(i686-w64-mingw32-pkg-config --cflags --libs webkit-1.0) && \
mv *.o win32/""",
source="../build/libbirdfont/Supplement.c",
target="./Supplement.o",
name="mingw compile",
depends_on="clean_src",
always=True);
bld(rule="""mv win32/BirdfontExport.* ./ """, always=True);
bld(rule="""mv win32/Main.* ./ """, always=True);
bld(rule="""mv win32/GtkWindow.* ./ """, always=True);
bld(rule="""i686-w64-mingw32-gcc \
-shared \
./win32/*.o \
./icon.res \
-Wl,-subsystem,windows \
-mthreads \
-L/usr/i686-w64-mingw32/sys-root/mingw/lib \
-static -B static -lintl.dll -B static -l glib-2.0.dll -B static -l xml2.dll \
-B static -lgio-2.0.dll -B static -l soup-2.4.dll \
-B static -l webkitgtk-1.0.dll -B static -lgtk-win32-2.0.dll -B static -lgdk-win32-2.0.dll -B static -latk-1.0.dll -B static -lgio-2.0.dll -B static -lpangowin32-1.0.dll -B static -lpangocairo-1.0.dll -B static -lgdk_pixbuf-2.0.dll -B static -lpango-1.0.dll -B static -lcairo.dll -B static -lgobject-2.0.dll -B static -lgmodule-2.0.dll -B static -lgthread-2.0.dll -B static -lglib-2.0.dll \
-static -o libbirdfont.dll""", source="../build/libbirdfont/Supplement.c", target="../libbirdfont.dll", depends_on=['mingw compile', 'icon'], name="mingw link shared", always=True)
bld(rule="""i686-w64-mingw32-ar rcs libbirdfont.dll.a win32/*.o""", name="mingw link static", depends_on="mingw link shared")
bld(rule="""i686-w64-mingw32-gcc \
./Main.o \
./GtkWindow.o \
./icon.res \
-Wl,-subsystem,windows \
-mthreads \
-L./ \
-L/usr/i686-w64-mingw32/sys-root/mingw/lib \
-static -B -static -l birdfont.dll \
-static -B static -lintl.dll -B static -l glib-2.0.dll -B static -l xml2.dll \
-B static -l gio-2.0.dll -B static -l soup-2.4.dll \
-B static -l webkitgtk-1.0.dll -B static -l gtk-win32-2.0.dll -B static -l gdk-win32-2.0.dll -B static -l atk-1.0.dll -B static -l gio-2.0.dll -B static -l pangowin32-1.0.dll -B static -l pangocairo-1.0.dll -B static -l gdk_pixbuf-2.0.dll -B static -l pango-1.0.dll -B static -l cairo.dll -B static -l gobject-2.0.dll -B static -l gmodule-2.0.dll -B static -l gthread-2.0.dll -B static -l glib-2.0.dll \
-static -o birdfont.exe""", source="../build/libbirdfont/Supplement.c", target="../birdfont.exe", depends_on=['mingw link shared', 'icon'], name="mingw link", always=True)
bld(rule="""i686-w64-mingw32-gcc \
./Main.o \
./icon.res \
./GtkWindow.o \
-mthreads \
-L./ \
-L/usr/i686-w64-mingw32/sys-root/mingw/lib \
-static -B -static -l birdfont.dll \
-static -B static -lintl.dll -B static -l glib-2.0.dll -B static -l xml2.dll \
-B static -l gio-2.0.dll -B static -l soup-2.4.dll \
-B static -l webkitgtk-1.0.dll -B static -l gtk-win32-2.0.dll -B static -l gdk-win32-2.0.dll -B static -l atk-1.0.dll -B static -l gio-2.0.dll -B static -l pangowin32-1.0.dll -B static -l pangocairo-1.0.dll -B static -l gdk_pixbuf-2.0.dll -B static -l pango-1.0.dll -B static -l cairo.dll -B static -l gobject-2.0.dll -B static -l gmodule-2.0.dll -B static -l gthread-2.0.dll -B static -l glib-2.0.dll \
-static -o birdfont_terminal.exe""", source="../build/libbirdfont/Supplement.c", target="../birdfont.exe", depends_on=['mingw link shared', 'icon'], name="mingw link terminal", always=True)
bld(rule="""i686-w64-mingw32-gcc \
./BirdfontExport.o \
./icon.res \
-Wl,-subsystem,windows \
-mthreads \
-L./ \
-L/usr/i686-w64-mingw32/sys-root/mingw/lib \
-static -B -static -l birdfont.dll \
-static -B static -lintl.dll -B static -l glib-2.0.dll -B static -l xml2.dll \
-B static -l gio-2.0.dll -B static -l soup-2.4.dll \
-B static -l webkitgtk-1.0.dll -B static -l gtk-win32-2.0.dll -B static -l gdk-win32-2.0.dll -B static -l atk-1.0.dll -B static -l gio-2.0.dll -B static -l pangowin32-1.0.dll -B static -l pangocairo-1.0.dll -B static -l gdk_pixbuf-2.0.dll -B static -l pango-1.0.dll -B static -l cairo.dll -B static -l gobject-2.0.dll -B static -l gmodule-2.0.dll -B static -l gthread-2.0.dll -B static -l glib-2.0.dll \
-static -o birdfont-export.exe""", source="../build/libbirdfont/Supplement.c", target="../birdfont-export.exe", depends_on=['mingw link shared', 'icon'], name="mingw link", always=True)
bld(rule="mv birdfont-export.exe supplement/", depends_on='mingw link', always=True)
bld(rule="mv birdfont.exe supplement/", depends_on='mingw link', always=True)
bld(rule="mv birdfont_terminal.exe supplement/", depends_on='mingw link terminal', always=True)
bld(rule="mv libbirdfont.dll supplement/", depends_on='mingw link', always=True)
if bld.options.installer:
copy_runtime_dependencies (bld)
generate_nsi(bld)
fn = "birdfont-" + bld.env.VERSION + ".exe"
bld(rule=os.getenv("HOME") + "/.wine/drive_c/Program/NSIS/makensis.exe supplement/birdfont_installer.nsi", source='', target='supplement/' + fn, depends_on='mingw link', name="nsis installer")
bld(rule="mv ./${SRC} ${TGT}", source='supplement/' + fn, target='../', depends_on='nsis installer')
def generate_nsi(bld):
print ('generating build/supplement/birdfont_installer.nsi')
bld.exec_command('mkdir -p build/supplement')
f = open('build/supplement/birdfont_installer.nsi', 'w+')
f.write("""; windows installation script generated by by win32/wscript
Name "Birdfont"
""")
f.write("OutFile \"..\\win32\\supplement\\")
f.write("birdfont-")
f.write(bld.env.VERSION)
f.write(".exe\"")
f.write("""
InstallDir $PROGRAMFILES\Birdfont
InstallDirRegKey HKLM "Software\NSIS_Birdfont" "Install_Dir"
Icon "birdfont.ico"
; Request application privileges for Windows Vista
RequestExecutionLevel admin
;--------------------------------
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
;--------------------------------
Section "Birdfont (required)"
SectionIn RO
""");
os.chdir('./build/supplement')
write_files ('.', f)
f.write("""
SetOutPath $INSTDIR
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_Birdfont "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Birdfont" "DisplayName" "NSIS Birdfont"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Birdfont" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Birdfont" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Birdfont" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\Birdfont"
CreateShortCut "$SMPROGRAMS\Birdfont\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\Birdfont\Birdfont.lnk" "$INSTDIR\\birdfont.exe" ""
CreateShortCut "$DESKTOP\Birdfont.lnk" "$INSTDIR\\birdfont.exe" ""
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Birdfont"
DeleteRegKey HKLM SOFTWARE\NSIS_Birdfont
""")
remove_files ('.', f)
f.write("""
Delete $INSTDIR\uninstall.exe
RMDir "$INSTDIR\Birdfont"
Delete "$SMPROGRAMS\Birdfont\*.*"
RMDir "$SMPROGRAMS\Birdfont"
Delete "$DESKTOP\Birdfont.lnk"
SectionEnd
""")
os.chdir('../../')
def write_files (dir, f):
filenames = os.walk(dir)
f.write(" SetOutPath $INSTDIR\n")
for path in (os.path.join(dir, f) for f in os.listdir(dir)):
if not os.path.isdir(path):
f.write(" File \"")
f.write(path.replace ('./', '').replace ('/', '\\'))
f.write("\"\n")
for dirname, dirnames, filenames in os.walk(dir):
for subdirname in dirnames:
ndir = os.path.join(dirname, subdirname)
wdir = ndir.replace ('./', '').replace ('/', '\\')
f.write("\n")
f.write(" SetOutPath $INSTDIR\\")
f.write(wdir)
f.write("\n")
dirList = os.listdir(ndir)
for fname in dirList:
fp = os.path.join(ndir, fname)
if not os.path.isdir(fp):
f.write(" File ")
f.write(wdir)
f.write("\\")
f.write(fname)
f.write("\n")
def remove_files (dir, f):
for path in (os.path.join(dir, f) for f in os.listdir(dir)):
if os.path.isdir(path):
remove_files (path, f)
else:
f.write(" Delete \"$INSTDIR\\")
f.write(path.replace ('./', '').replace ('/', '\\'))
f.write("\"\n")
if dir == '.':
f.write(" RMDir \"$INSTDIR\"\n")
else:
f.write(" RMDir \"$INSTDIR\\")
f.write(dir.replace ('./', '').replace ('/', '\\'))
f.write("\"\n")
def copy_runtime_dependencies (bld):
MINGW = "/usr/i686-w64-mingw32/sys-root/mingw"
MINGW_BIN = MINGW + "/bin"
bld(rule="cp ../README supplement/")
bld(rule="cp ../COPYING supplement/")
bld(rule="cp ../NEWS supplement/")
bld(rule="cp -ra ../layout/ supplement/")
bld(rule="cp -ra ../icons/ supplement/")
bld(rule="cp -ra locale supplement/")
bld(rule="cp ../win32/birdfont.ico supplement/")
bld(rule="cp -r " + MINGW + "/etc supplement/")
bld(rule="cp " + MINGW_BIN + "/gspawn-win32-helper.exe supplement/")
bld(rule="cp " + MINGW_BIN + "/gspawn-win32-helper-console.exe supplement/")
# DLL-hell
for dll in WIN32_DLLS:
bld(rule="cp " + MINGW_BIN + "/" + dll + " supplement/")