diff --git a/macosx/Makefile b/macosx/Makefile index 650370e90..a9e732708 100644 --- a/macosx/Makefile +++ b/macosx/Makefile @@ -2,9 +2,8 @@ # Zenmap, Ncat, and Ndiff. export NMAP_VERSION := $(shell echo NMAP_VERSION | $(CPP) -imacros ../nmap.h - | sed -n '$$s/[" ]//g;$$p') -#OSX_VERSION=$(shell sw_vers -productVersion | cut -d'.' -f1,2 | tr -d ' ') -OSX_VERSION=10.11 -OSX_MIN_VERSION = 10.9 +OSX_VERSION=$(shell sw_vers -productVersion | cut -d'.' -f1,2 | tr -d ' ') +OSX_MIN_VERSION = 10.15 NAME_VERSION = nmap-$(NMAP_VERSION)$(if $(APPENDAGE),-$(APPENDAGE)) @@ -42,34 +41,11 @@ EXTRA_DIST = README.md ../LICENSE ../docs/3rd-party-licenses.txt ../docs/license CONFIGURE_ARGS = --prefix="$(PREFIX)" --with-libdnet=included --with-libpcap=included --with-libpcre=included --with-liblua=included CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" PYTHON="$(PYTHON)" -# Flags for building universal binaries. See -# http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/compiling/chapter_4_section_3.html. -UNIVERSAL_CONFIGURE_ARGS = --disable-dependency-tracking -UNIVERSAL_CC = gcc -UNIVERSAL_CXX = g++ -# Setting ARCHFLAGS separately is required. distutils.util.get_platform -# sniffs it to determine whether to return a universal architecture -# ("fat" or "universal") or a single one ("i386" or "ppc"). py2app in -# turn uses the arch value to decide which of its bootstrappers to -# install. -UNIVERSAL_ARCHFLAGS = -arch x86_64 -UNIVERSAL_CPPFLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(OSX_VERSION).sdk -UNIVERSAL_CFLAGS = $(UNIVERSAL_CPPFLAGS) -mmacosx-version-min=$(OSX_MIN_VERSION) $(UNIVERSAL_ARCHFLAGS) -UNIVERSAL_CXXFLAGS = $(UNIVERSAL_CFLAGS) -# https://stackoverflow.com/questions/19637164/c-linking-error-after-upgrading-to-mac-os-x-10-9-xcode-5-0-1/19637199#19637199 -UNIVERSAL_LDFLAGS = -stdlib=libstdc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(OSX_VERSION).sdk -mmacosx-version-min=$(OSX_MIN_VERSION) $(UNIVERSAL_ARCHFLAGS) - -CC = $(UNIVERSAL_CC) -CXX = $(UNIVERSAL_CXX) -ARCHFLAGS += $(UNIVERSAL_ARCHFLAGS) -CONFIGURE_ARGS += $(UNIVERSAL_CONFIGURE_ARGS) -CPPFLAGS += $(UNIVERSAL_CPPFLAGS) -CFLAGS += $(UNIVERSAL_CFLAGS) -CXXFLAGS += $(UNIVERSAL_CXXFLAGS) -LDFLAGS += $(UNIVERSAL_LDFLAGS) +CFLAGS = -mmacosx-version-min=$(OSX_MIN_VERSION) +CXXFLAGS = -mmacosx-version-min=$(OSX_MIN_VERSION) # Jhbuild static libraries -PYTHON = $(JHBUILD_PREFIX)/bin/python2.7 +PYTHON = $(JHBUILD_PREFIX)/bin/python3 OPENSSL_STATIC = $(JHBUILD_PREFIX)/lib/libssl.a $(JHBUILD_PREFIX)/lib/libcrypto.a LIBZ_STATIC = $(JHBUILD_PREFIX)/lib/libz.a @@ -135,7 +111,7 @@ $(IMAGE_STAGING_DIR)/$(PKG_NAME): check-nmap check-ncat check-ndiff check-zenmap mv $(NAME_VERSION).mpkg $(NAME_VERSION)/$(NAME_VERSION).mpkg check-%: stage-% - if (find $*-root -perm -a+x -type f | xargs otool -L | grep -F "$(JHBUILD_PREFIX)"); then false; else echo "Libs are clean"; fi + (find $*-root -perm -a+x -type f | xargs otool -L | awk '/:$$/{e=$$0}index($$0,"$(JHBUILD_PREFIX)"){x=1;print e; print}END{exit x}') && echo "Libs are clean" export-%: rm -rf $* diff --git a/macosx/openssl.modules b/macosx/openssl.modules index 2e7a55a1f..e558703d1 100644 --- a/macosx/openssl.modules +++ b/macosx/openssl.modules @@ -1,6 +1,7 @@ + + ]> @@ -17,14 +18,14 @@ - - + "$SCRIPT_DIR/tmp.bundle" + +echo "Building bundle" +gtk-mac-bundler "$SCRIPT_DIR/tmp.bundle" + +echo "Removing unneeded items" +# GIR files not needed, only typelib +rm -rf $BASE/Resources/share/gir-1.0/ + +echo "Creating caches" +pushd "$BASE/Resources" +export GDK_PIXBUF_MODULEDIR=$(ls - lib/gdk-pixbuf-2.0/2.*/loaders) +gdk-pixbuf-query-loaders > "$GDK_PIXBUF_MODULEDIR".cache +gtk-update-icon-cache share/icons/hicolor +popd + +# echo "Compiling Python to bytecode" +PYTHONLIB=$(ls -d $BASE/Resources/lib/python3.*) +# Remove compiled bytecode, recompile in legacy locations, allowing for removal of source. +# See PEP-3147 +find "$PYTHONLIB" -depth \( -name 'zenmap*' -o -name 'radialnet' \) -prune -o -name __pycache__ -exec rm -rf '{}' \; +python -m compileall -b -x 'zenmapGUI|zenmapCore|radialnet' "$PYTHONLIB" + +# Remove source if compiled is available, except for Zenmap itself: +find "$PYTHONLIB" \( -name 'zenmap*' -o -name 'radialnet' \) -prune -o \( -name '*.pyc' -print \) | while read pyc; do +rm -f "${pyc%.pyc}.py" +done + +# Now compile Zenmap using default (not legacy) location. +# If we had used legacy location, python.exe tries to write out the PEP-3147 +# location anyway when source is available. +python -m compileall "$PYTHONLIB"/site-packages #|| true 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 "Building using distutils" -python setup.py build --executable "/usr/bin/env python" -python setup.py install vanilla --prefix "$BASE/Resources" +$PYTHON setup.py build --executable "/usr/bin/env python3" +$PYTHON setup.py install vanilla --prefix "$BASE/Resources" echo "Renaming main Zenmap executable." mv $BASE/MacOS/$APP_NAME $BASE/MacOS/zenmap.bin # This is a dummy script, so we'll clean it up: -rm $BASE/MacOS/$APP_NAME-bin +#rm $BASE/MacOS/$APP_NAME-bin echo "Compiling and installing authorization wrapper." -echo $CC $CPPFLAGS $CFLAGS $LDFLAGS -v "$SCRIPT_DIR/zenmap_auth.m" -lobjc -framework Foundation -o "$BASE/MacOS/$APP_NAME" -$CC $CPPFLAGS $CFLAGS $LDFLAGS -v "$SCRIPT_DIR/zenmap_auth.m" -lobjc -framework Foundation -o "$BASE/MacOS/$APP_NAME" +echo $CC $CPPFLAGS $OBJCFLAGS $LDFLAGS -v "$SCRIPT_DIR/zenmap_auth.m" -lobjc -framework Foundation -o "$BASE/MacOS/$APP_NAME" +$CC $CPPFLAGS $OBJCFLAGS $LDFLAGS -v "$SCRIPT_DIR/zenmap_auth.m" -lobjc -framework Foundation -o "$BASE/MacOS/$APP_NAME" echo "Filling out Info.plist" -python - "$SCRIPT_DIR/Info.plist" >"$BASE/Info.plist" <<'EOF' +$PYTHON - "$SCRIPT_DIR/Info.plist" >"$BASE/Info.plist" <<'EOF' import sys from string import Template from zenmapCore.Version import * diff --git a/zenmap/install_scripts/macosx/zenmap.bundle b/zenmap/install_scripts/macosx/zenmap.bundle index 3d8fd96cc..dff4c318b 100644 --- a/zenmap/install_scripts/macosx/zenmap.bundle +++ b/zenmap/install_scripts/macosx/zenmap.bundle @@ -1,4 +1,8 @@ + + +]> @@ -23,14 +27,14 @@ - ${project}/launcher.sh + --> - + gtk+-3.0 ${project}/Info.plist - + + + - ${prefix}/bin/pygtk-demo + ${prefix}/bin/zenmap-launcher - ${prefix}/bin/python + ${prefix}/bin/python3 - - - - ${prefix}/lib/libpyglib-2.0-python2.0.dylib - - - - ${prefix}/lib/libgtk-quartz-${gtkversion}.0.dylib - - - - - ${prefix}/lib/${gtkdir}/modules/*.so - - - + binaries link to are also copied in automatically. + --> + - ${prefix}/lib/${gtkdir}/${pkg:${gtk}:gtk_binary_version}/engines/*.so + ${prefix}/lib/gdk-pixbuf-2.0/${pkg:gdk-pixbuf-2.0:gdk_pixbuf_binary_version}/loaders/libpixbufloader-gif.so + + + + ${prefix}/lib/${gtkdir}/${pkg:${gtk}:gtk_binary_version}/immodules/im-quartz.so + + + ${prefix}/lib/${gtkdir}/${pkg:${gtk}:gtk_binary_version}/printbackends/*.so - + - ${prefix}/lib/gdk-pixbuf-2.0/${pkg:gdk-pixbuf-2.0:gdk_pixbuf_binary_version}/loaders/*.so + ${prefix}/lib/python&PYVER;/site-packages/gi/*.so + + + ${prefix}/lib/python&PYVER;/site-packages/cairo/*.so - - - ${prefix}/share/locale - +&pyreqs; + + ${prefix}/lib/libgtkmacintegration-gtk3.dylib + - - ${prefix}/lib/python2.7/lib-dynload/*.so - ${prefix}/lib/python2.7/site-packages/*.so - ${prefix}/lib/python2.7/site-packages/cairo/*.so - ${prefix}/lib/python2.7/site-packages/glib/*.so - ${prefix}/lib/python2.7/site-packages/gobject/*.so - ${prefix}/lib/python2.7/site-packages/gtk-2.0/*.so - ${prefix}/lib/python2.7/site-packages/gtk-2.0/gio/*.so - ${prefix}/lib/python2.7/site-packages/gtk-2.0/gtk/*.so - ${prefix}/lib/python2.7/site-packages/gtkosx_application/*.so - - - ${prefix}/lib/python2.7/ + ${prefix}/share/gir-1.0/Atk-1.0.gir + ${prefix}/share/gir-1.0/GLib-2.0.gir + ${prefix}/share/gir-1.0/GModule-2.0.gir + ${prefix}/share/gir-1.0/GObject-2.0.gir + ${prefix}/share/gir-1.0/Gdk-3.0.gir + ${prefix}/share/gir-1.0/GdkPixbuf-2.0.gir + ${prefix}/share/gir-1.0/Gio-2.0.gir + ${prefix}/share/gir-1.0/Gtk-3.0.gir + ${prefix}/share/gir-1.0/HarfBuzz-0.0.gir + ${prefix}/share/gir-1.0/Pango-1.0.gir + ${prefix}/share/gir-1.0/PangoCairo-1.0.gir + ${prefix}/share/gir-1.0/PangoOT-1.0.gir + ${prefix}/share/gir-1.0/cairo-1.0.gir + ${prefix}/share/gir-1.0/freetype2-2.0.gir + + + + ${project}/zenmap_launcher.py - - ${prefix}/share/themes + ${prefix}/share/glib-2.0/schemas + - - - ${project}/gtkrc - - diff --git a/zenmap/install_scripts/macosx/zenmap_launcher.py b/zenmap/install_scripts/macosx/zenmap_launcher.py new file mode 100644 index 000000000..98aca78b3 --- /dev/null +++ b/zenmap/install_scripts/macosx/zenmap_launcher.py @@ -0,0 +1,43 @@ +from os.path import join, dirname, abspath, normpath +import sys, os +import platform + + +bundlepath = sys.argv[0] + +bundle_contents = join(bundlepath, 'Contents') +bundle_res = join(bundle_contents, 'Resources') + +bundle_lib = join(bundle_res, 'lib') +bundle_bin = join(bundle_res, 'bin') +bundle_data = join(bundle_res, 'share') +bundle_etc = join(bundle_res, 'etc') + +os.environ['XDG_DATA_DIRS'] = bundle_data +os.environ['DYLD_LIBRARY_PATH'] = bundle_lib +os.environ['LD_LIBRARY_PATH'] = bundle_lib +os.environ['GTK_DATA_PREFIX'] = bundle_res +os.environ['GTK_EXE_PREFIX'] = bundle_res +os.environ['GTK_PATH'] = bundle_res + +os.environ['PANGO_RC_FILE'] = join(bundle_etc, 'pango', 'pangorc') +os.environ['PANGO_SYSCONFDIR'] = bundle_etc +os.environ['PANGO_LIBDIR'] = bundle_lib +os.environ['GDK_PIXBUF_MODULE_FILE'] = join(bundle_lib, 'gdk-pixbuf-2.0', + '2.10.0', 'loaders.cache') +if int(platform.release().split('.')[0]) > 10: + os.environ['GTK_IM_MODULE_FILE'] = join(bundle_etc, 'gtk-3.0', + 'gtk.immodules') + +os.environ['GI_TYPELIB_PATH'] = join(bundle_lib, 'girepository-1.0') + +#Set $PYTHON to point inside the bundle +PYVER = 'python3.10' +sys.path.append(bundle_res) + +os.environ['USERPROFILE'] = os.environ['HOME'] +os.environ['APPDATA'] = join(os.environ['HOME'], 'Library', 'Application Support') +# Replace my_app with the file or module with your main() function. +from zenmapGUI import App +App.run() + diff --git a/zenmap/install_scripts/utils/get_deps.py b/zenmap/install_scripts/utils/get_deps.py index 1c4a8e64b..af00507a9 100755 --- a/zenmap/install_scripts/utils/get_deps.py +++ b/zenmap/install_scripts/utils/get_deps.py @@ -7,16 +7,16 @@ import os.path import site import encodings -site_package_deps = ("zenmapCore", "zenmapGUI", "radialnet", "gi", "cairo") +site_package_deps = ("gi", "cairo") # These items are unneeded, large, and on macOS _ssl causes dependency problems. -pyd_remove = ("_decimal", "_ssl", "_testcapi") +pyd_remove = ("_decimal", "_ssl", "_testcapi", "_hashlib") def module_paths(mods): for m in mods: if m.__name__ in pyd_remove: continue - elif getattr(m, "__file__", None) and ('..' not in m.__file__): + elif getattr(m, "__file__", None) and not m.__file__.endswith("zenmap"): yield m.__file__ def get_deps(): @@ -31,12 +31,12 @@ def get_deps(): # Now use modulefinder to get the rest mfind = modulefinder.ModuleFinder() - mfind.run_script('../../zenmap') + mfind.run_script(os.path.normpath(__file__ + '/../../../zenmap')) for path in module_paths(mfind.modules.values()): parent = os.path.dirname(path) found_parent = False # If a parent dir is already included, don't bother listing the file. - while parent not in sys.path: + while parent not in sys.path and len(parent) > 2: if parent in files: found_parent = True break @@ -59,6 +59,14 @@ def update_cfg(cfg, files): oldvalue = cfg.get('bundle', 'nodelete') cfg.set('bundle', 'nodelete', oldvalue + "\nmingw*" + filestr) +def write_xml(filename, files): + with open(filename, "w") as f: + for file in files: + fname = r"${prefix}" + file.removeprefix(sys.prefix) + fmt = "{}" + if file.endswith(".so"): + fmt = "{}" + print(fmt.format(fname), file=f) if __name__ == "__main__": files = get_deps() @@ -66,6 +74,7 @@ if __name__ == "__main__": cfg = read_cfg(sys.argv[2]) update_cfg(cfg, files) write_cfg(cfg, sys.argv[1]) - #elif sys.platform == "darwin": + elif sys.platform == "darwin": + write_xml(sys.argv[1], files) else: raise NotImplementedError diff --git a/zenmap/install_scripts/windows/styrene.cfg b/zenmap/install_scripts/windows/styrene.cfg index 6376420bf..b5cfd2c3e 100755 --- a/zenmap/install_scripts/windows/styrene.cfg +++ b/zenmap/install_scripts/windows/styrene.cfg @@ -145,15 +145,15 @@ nodelete = # Zenmap's files (mostly in site-packages above) mingw*/share/zenmap # mingw*/bin/zenmap + mingw*/lib/python3.*/site-packages/zenmapCore + mingw*/lib/python3.*/site-packages/zenmapGUI + mingw*/lib/python3.*/site-packages/radialnet # The python modules here will be added by script: # mingw*/lib/python3.* # mingw*/lib/python3.*/encodings # mingw*/lib/python3.*/site.py # mingw*/lib/python3.*/_sitebuiltins.py - # mingw*/lib/python3.*/site-packages/zenmapCore - # mingw*/lib/python3.*/site-packages/zenmapGUI - # mingw*/lib/python3.*/site-packages/radialnet # mingw*/lib/python3.*/site-packages/gi # mingw*/lib/python3.*/site-packages/cairo