1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Switch to gtk-mac-bundler and jhbuild for building OS X app bundle

This commit is contained in:
dmiller
2015-12-09 04:16:50 +00:00
parent 53d41055c7
commit 94d48e7913
13 changed files with 371 additions and 312 deletions

View File

@@ -1,35 +1,15 @@
#!/bin/sh -e
set -x
# make-bundle.sh
# David Fifield
#
# This script works the magic needed to build Zenmap into a .app bundle for Mac
# OS X. It's complicated because py2app doesn't really support Pango or PyGTK.
#
# It is based on the osx-app.sh script used by Wireshark, which contains the
# following notice:
#
# AUTHORS
# Kees Cook <kees@outflux.net>
# Michael Wybrow <mjwybrow@users.sourceforge.net>
# Jean-Olivier Irisson <jo.irisson@gmail.com>
#
# Copyright (C) 2005 Kees Cook
# Copyright (C) 2005-2007 Michael Wybrow
# Copyright (C) 2007 Jean-Olivier Irisson
#
# Released under GNU GPL, read the file 'COPYING' for more information
# This script relies on having an installation of MacPorts in $(LIBPREFIX),
# configured as you wish. See README for instructions on how to make a build
# environment. You need to have installed the packages py26-gtk and
# py26-py2app.
LIBPREFIX=$HOME/macports-10.8
PYTHON=$LIBPREFIX/bin/python2.7
PKG_CONFIG=$LIBPREFIX/bin/pkg-config
APP_NAME=Zenmap
BASE=dist/$APP_NAME.app/Contents
ZENMAP_DIST_DIR=$PWD/dist
ZENMAP_BUILD_DIR=$PWD/build
export ZENMAP_DIST_DIR
export ZENMAP_BUILD_DIR
BASE=$ZENMAP_DIST_DIR/$APP_NAME.app/Contents
SCRIPT_DIR=`dirname "$0"`
CC=${CC:-gcc}
@@ -38,48 +18,63 @@ CFLAGS=${CFLAGS:--Wall -arch i386}
echo "Running $0."
echo "Removing old build."
rm -rf build dist
rm -rf "$ZENMAP_DIST_DIR" "$ZENMAP_BUILD_DIR"
echo "Compiling using py2app."
$PYTHON setup.py py2app --arch=i386 --no-strip
echo "Building bundle"
# jhbuild bootstrap
# jhbuild build meta-gtk-osx-bootstrap
# jhbuild build meta-gtk-osx-core
# jhbuild build meta-gtk-osx-python
gtk-mac-bundler "$SCRIPT_DIR/zenmap.bundle"
# Delete a library that causes compatibility problems with OS X 10.9.
# http://seclists.org/nmap-dev/2013/q4/85
rm -f $BASE/Frameworks/libxml2.2.dylib
mkdir -p $BASE/Resources/etc
mkdir -p $BASE/Resources/lib
gtk_version=`$PKG_CONFIG --variable=gtk_binary_version gtk+-2.0`
echo "Copying GTK+ $gtk_version files."
mkdir -p $BASE/Resources/lib/gtk-2.0/$gtk_version
cp -R $LIBPREFIX/lib/gtk-2.0/$gtk_version/* $BASE/Resources/lib/gtk-2.0/$gtk_version/
mkdir -p $BASE/Resources/etc/gtk-2.0
cp $SCRIPT_DIR/gtkrc $BASE/Resources/etc/gtk-2.0/
echo "Updating paths in GTK+ .so files"
ESCAPED_LIBPREFIX=$(echo $LIBPREFIX | sed 's/\([\/\\.]\)/\\\1/g')
find $BASE/Resources/lib/gtk-2.0/$gtk_version/ -type f -name '*.so' | while read so; do
otool -L "$so" | awk "/$ESCAPED_LIBPREFIX/{print \$1}" | while read dep; do
install_name_tool -change $dep $(echo $dep | sed "s/$ESCAPED_LIBPREFIX\/lib/@executable_path\/..\/Frameworks/") "$so"
done
echo "Stripping unoptimized Python libraries"
#Remove some stuff that is unneeded. This cuts 40M off the installed size.
rm -rf $BASE/Resources/lib/python2.7/test/
rm -rf $BASE/Resources/lib/python2.7/config/
rm -rf $BASE/Resources/lib/python2.7/idlelib/
rm -rf $BASE/Resources/lib/python2.7/lib-tk/
rm -rf $BASE/Resources/lib/python2.7/lib2to3/
rm -f $BASE/Resources/lib/python2.7/site-packages/*.a
find "$BASE/Resources/lib/python2.7" -type f -name '*.py' | while read py; do
# If the .pyc exists, delete the .py
test -f "${py}c" && rm -v "$py"
done
find "$BASE/Resources/lib/python2.7" -type f -name '*.pyo' | while read py; do
# If the .pyc exists, delete the .pyo
test -f "${py/%o/c}" && rm -v "$py"
done
echo "Copying Fontconfig files."
cp -R $LIBPREFIX/etc/fonts $BASE/Resources/etc/
# Remove the dir and cachedir under $LIBPREFIX. The cachedir ~/.fontconfig remains.
sed -i "" 's/ *<dir>'$(echo "$LIBPREFIX" | sed -e 's/\([^a-zA-Z0-9]\)/\\\1/g')'\/share\/fonts<\/dir>//g' $BASE/Resources/etc/fonts/fonts.conf
sed -i "" '/<cachedir>'$(echo "$LIBPREFIX" | sed -e 's/\([^a-zA-Z0-9]\)/\\\1/g')'\/var\/cache\/fontconfig<\/cachedir>/d' $BASE/Resources/etc/fonts/fonts.conf
# Disable hinting to better match the Mac GUI.
cp $LIBPREFIX/share/fontconfig/conf.avail/10-unhinted.conf $BASE/Resources/etc/fonts/conf.d
echo "Building using distutils"
python setup.py build --executable "/usr/bin/env python"
python setup.py install vanilla --prefix "$BASE/Resources"
# This isn't truly necessary, but it allows us to do a simpler check for problems later.
echo "Rewriting linker paths to pass checks"
ESCAPED_LIBBASE=$(echo "$BASE/Resources/" | sed 's/\([\/\\.]\)/\\\1/g')
find $BASE/Resources/lib -type f -name '*.dylib' | while read so; do
dep=$(echo "$so" | sed "s/$ESCAPED_LIBBASE//")
install_name_tool -id "@executable_path/../Resources/$dep" "$so"
done
echo "Renaming main Zenmap executable."
mv $BASE/MacOS/$APP_NAME $BASE/MacOS/zenmap.bin
echo "Installing wrapper script."
cp $SCRIPT_DIR/zenmap_wrapper.py $BASE/MacOS/
# This is a dummy script, so we'll clean it up:
rm $BASE/MacOS/$APP_NAME-bin
echo "Compiling and installing authorization wrapper."
echo $CC $CPPFLAGS $CFLAGS $LDFLAGS -framework Security -o $BASE/MacOS/$APP_NAME $SCRIPT_DIR/zenmap_auth.c
$CC $CPPFLAGS $CFLAGS $LDFLAGS -framework Security -o $BASE/MacOS/$APP_NAME $SCRIPT_DIR/zenmap_auth.c
echo $CC $CPPFLAGS $CFLAGS $LDFLAGS -framework Security -o "$BASE/MacOS/$APP_NAME" "$SCRIPT_DIR/zenmap_auth.c"
$CC $CPPFLAGS $CFLAGS $LDFLAGS -framework Security -o "$BASE/MacOS/$APP_NAME" "$SCRIPT_DIR/zenmap_auth.c"
echo "Filling out Info.plist"
python - "$SCRIPT_DIR/Info.plist" >"$BASE/Info.plist" <<'EOF'
import sys
from string import Template
from zenmapCore.Version import *
from zenmapCore.Name import *
with open(sys.argv[1],"r") as f:
sys.stdout.write(Template(f.read()).substitute(
VERSION=VERSION,
APP_WEB_SITE=APP_WEB_SITE,
APP_COPYRIGHT=APP_COPYRIGHT
))
EOF