diff --git a/build.sh b/build.sh index 00d4c9fbb..8dec34928 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -# +# # KLayout Layout Viewer # Copyright (C) 2006-2018 Matthias Koefferlein # @@ -17,10 +17,11 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# +# CURR_DIR=`pwd` RUN_MAKE=1 +IS_MAC="no" HAVE_QTBINDINGS=1 HAVE_64BIT_COORD=0 @@ -46,6 +47,16 @@ MAKE_OPT="" CONFIG="release" BUILD_EXPERT=0 +# Check if building on Mac OSX Darwin family +case `uname` in + Darwin*) + IS_MAC="yes" + ;; + *) + IS_MAC="no" + ;; +esac + # Check, whether build.sh is run from the top level folder if ! [ -e src ] || ! [ -e src/klayout.pro ]; then echo "*** ERROR: run build.sh from the top level folder" @@ -200,7 +211,7 @@ done echo "Scanning installation .." echo "" -# Import version info +# Import version info . ./version.sh echo "Version Info:" @@ -212,8 +223,8 @@ echo "" # if not given, try to detect the qmake binary if [ "$QMAKE" = "" ]; then for qmake in "qmake5" "qmake-qt5" "qmake4" "qmake-qt4" "qmake"; do - if [ "$QMAKE" = "" ] && [ "`$qmake -v 2>/dev/null`" != "" ]; then - QMAKE="$qmake" + if [ "$QMAKE" = "" ] && [ "`$qmake -v 2>/dev/null`" != "" ]; then + QMAKE="$qmake" fi done fi @@ -246,8 +257,8 @@ echo "" # if not given, locate ruby interpreter (prefer 1.9, then default, finally 1.8 as fallback) if [ "$RUBY" = "" ]; then for ruby in "ruby2.4" "ruby2.3" "ruby2.2" "ruby2.1" "ruby2" "ruby1.9" "ruby" "ruby1.8"; do - if [ "$RUBY" = "" ] && [ "`$ruby -e 'puts 1' 2>/dev/null`" = "1" ]; then - RUBY="$ruby" + if [ "$RUBY" = "" ] && [ "`$ruby -e 'puts 1' 2>/dev/null`" = "1" ]; then + RUBY="$ruby" fi done fi @@ -314,7 +325,7 @@ if [ "$RUBY" != "" ] && [ "$RUBY" != "-" ]; then RUBYINCLUDE2=`$RUBY -rrbconfig -e "puts (RbConfig::CONFIG['rubyarchhdrdir'] || '')"` fi if [ "$RUBYINCLUDE2" = "" ]; then - RUBYINCLUDE2="$RUBYHDRDIR"/`$RUBY -rrbconfig -e "puts (RbConfig::CONFIG['arch'] || '')"` + RUBYINCLUDE2="$RUBYHDRDIR"/`$RUBY -rrbconfig -e "puts (RbConfig::CONFIG['arch'] || '')"` fi echo " Ruby headers found: $RUBYINCLUDE and $RUBYINCLUDE2" fi @@ -329,11 +340,11 @@ if [ "$RUBY" != "" ] && [ "$RUBY" != "-" ]; then fi -# if not given, locate Python interpreter +# if not given, locate Python interpreter if [ "$PYTHON" = "" ]; then for python in "python3.5" "python3.4" "python3.3" "python3.2" "python3.1" "python3" "python2.8" "python2.7" "python2" "python"; do - if [ "$PYTHON" = "" ] && [ "`$python -c 'print(1)' 2>/dev/null`" = "1" ]; then - PYTHON="$python" + if [ "$PYTHON" = "" ] && [ "`$python -c 'print(1)' 2>/dev/null`" = "1" ]; then + PYTHON="$python" fi done fi @@ -468,11 +479,21 @@ mkdir -p $BUILD . $(dirname $(which $0))/version.sh # qmake needs absolute paths, so we get them now: -BUILD=`readlink -f $BUILD` -BIN=`readlink -f $BIN` +# OSX does not have `readlink -f` command. Use equivalent Perl script. +if [ "$IS_MAC" = "no" ]; then + BUILD=`readlink -f $BUILD` + BIN=`readlink -f $BIN` +else + BUILD=`perl -MCwd -le 'print Cwd::abs_path(shift)' $BUILD` + BIN=`perl -MCwd -le 'print Cwd::abs_path(shift)' $BIN` +fi -if ( gmake -v >/dev/null 2>/dev/null ); then - MAKE_PRG=gmake +if [ "$IS_MAC" = "no" ]; then + if ( gmake -v >/dev/null 2>/dev/null ); then + MAKE_PRG=gmake + else + MAKE_PRG=make + fi else MAKE_PRG=make fi diff --git a/macbuild/ReadMe.md b/macbuild/ReadMe.md new file mode 100644 index 000000000..0e39fdb87 --- /dev/null +++ b/macbuild/ReadMe.md @@ -0,0 +1,72 @@ +<< Draft Version 0.003>> Relevant KLayout version: 0.25.1 + +# 1. Introduction +This directory "macbuild" contains different files required for building KLayout (http://www.klayout.de/) version 0.25 or later for different Mac OSXs including: +* Yosemite (10.10) +* El Capitan (10.11) +* Sierra (10.12) +* High Sierra (10.13) + +By default, Qt framework is "Qt5" from Mac Ports (https://www.macports.org/) which is usually located under: +``` +/opt/local/libexec/qt5/ +``` + +### IMPORTANT +``` +* Please DO NOT USE "Qt 5.10.0" which is problematic in showing your design in the main canvas. +* Please USE "Qt 5.9.x" instead. +* Building with Qt4 will lead to some compile errors. +``` +Also by default, supported script languages, i.e, Ruby and Python, are those standard ones bundled with the OS. + +# 2. Non-OS-standard script language support +You may want to use a non-OS-standard script language such as Python 3.6 from Anaconda2 (https://www.anaconda.com/download/#macos) in combination with KLayout. + +Since Anaconda2 is a popular Python development environment, this is worth trying. +Unfortunately, however, some dynamic linkage problems are observed as of today. +On the other hand, Python 3.6 provided by Mac Ports is usable. +Please try this (refer to 3B below) if you feel it's useful. + +# 3. Use-cases +### 3A. Debug build using the OS-standard script languages +1. Make a symbolic link from the parent directory (where 'build.sh' exists) to + 'build4mac.py', that is, +``` + build4mac.py -> macbuild/build4mac.py +``` +2. Invoke 'build4mac.py' with appropriate options ("-d" for debug build): +``` +$ cd /where/'build.sh'/exists +$ ./build4mac.py -d +``` +3. Confirm successful build. +4. Run 'build4mac.py' again with the same options used in 2. PLUS "-y" to deploy executables and libraries (including Qt's frameworks) under "klayout.app" bundle. +``` +$ ./build4mac.py -d -y +``` +5. Copy/move generated bundles ("klayout.app" and "klayout.scripts/") to your "/Applications" directory for installation. + +### 3B. Release build using the non-OS-standard Ruby 2.4 and Python 3.6 both from MacPorts +1. Make a symbolic link from the parent directory (where 'build.sh' exists) to 'build4mac.py', that is, +``` +build4mac.py -> macbuild/build4mac.py +``` +2. Invoke 'build4mac.py' with appropriate options: +``` +$ cd /where/'build.sh'/exists +$ ./build4mac.py -r mp24 -p mp36 +``` +3. Confirm successful build. +4. Run 'build4mac.py' again with the same options used in 2. PLUS "-Y" to deploy executables and libraries under "klayout.app" bundle. +``` +$ ./build4mac.py -r mp24 -p mp36 -Y +``` +* [-Y|--DEPOLY] option deploys KLayout's dylibs and executables only. +That is, paths to other modules (Ruby, Python, and Qt5 Frameworks) remain unchanged (absolute paths in your development environment). + +5. Copy/move generated bundles ("klayout.app" and "klayout.scripts/") to your "/Applications" directory for installation. + +By: Kazzz (January 08, 2018) + +[End of File] diff --git a/macbuild/ReadMe.txt b/macbuild/ReadMe.txt new file mode 100644 index 000000000..ffa630d17 --- /dev/null +++ b/macbuild/ReadMe.txt @@ -0,0 +1,69 @@ +<< Draft Version 0.003>> +Relevant KLayout version: 0.25.1 + +1. Introduction: + This directory "macbuild" contains different files required for building KLayout (http://www.klayout.de/) + version 0.25 or later for different Mac OSXs including: + * Yosemite (10.10) + * El Capitan (10.11) + * Sierra (10.12) + * High Sierra (10.13) + + By default, Qt framework is "Qt5" from Mac Ports (https://www.macports.org/) which is + usually located under: + /opt/local/libexec/qt5/ + + : + * Please DO NOT USE "5.10.0" which is problematic in showing your design in the main canvas. + * Please USE "5.9.x" instead. + * Building with Qt4 will lead to some compile errors. + + Also by default, supported script languages, i.e, Ruby and Python, are those + standard ones bundled with the OS. + + +2. Non-OS-standard script language support: + You may want to use a non-OS-standard script language such as Python 3.6 from + Anaconda2 (https://www.anaconda.com/download/#macos) in combination with KLayout. + Since Anaconda2 is a popular Python development environment, this is worth trying. + Unfortunately, however, some dynamic linkage problems are observed as of today. + + On the other hand, Python 3.6 provided by Mac Ports is usable. + Please try this (refer to 3B below) if you feel it's useful. + +3. Use-cases: +3A. Debug build using the OS-standard script languages: + (1) Make a symbolic link from the parent directory (where 'build.sh' exists) to + 'build4mac.py', that is, + build4mac.py -> macbuild/build4mac.py + (2) Invoke 'build4mac.py' with appropriate options ("-d" for debug build): + $ cd /where/'build.sh'/exists + $ ./build4mac.py -d + (3) Confirm successful build. + (4) Run 'build4mac.py' again with the same options used in (2) PLUS "-y" + to deploy executables and libraries (including Qt's frameworks) under "klayout.app" bundle. + $ ./build4mac.py -d -y + (5) Copy/move generated bundles ("klayout.app" and "klayout.scripts/") to your + "/Applications" directory for installation. + + +3B. Release build using the non-OS-standard Ruby 2.4 and Python 3.6 both from MacPorts: + (1) Make a symbolic link from the parent directory (where 'build.sh' exists) to + 'build4mac.py', that is, + build4mac.py -> macbuild/build4mac.py + (2) Invoke 'build4mac.py' with appropriate options: + $ cd /where/'build.sh'/exists + $ ./build4mac.py -r mp24 -p mp36 + (3) Confirm successful build. + (4) Run 'build4mac.py' again with the same options used in (2) PLUS "-Y" + to deploy executables and libraries under "klayout.app" bundle. + $ ./build4mac.py -r mp24 -p mp36 -Y + * [-Y|--DEPOLY] option deploys KLayout's dylibs and executables only. + That is, paths to other modules (Ruby, Python, and Qt5 Frameworks) + remain unchanged (absolute paths in your development environment). + (5) Copy/move generated bundles ("klayout.app" and "klayout.scripts/") to your + "/Applications" directory for installation. + +By: Kazzz (January 08, 2018) + +[End of File] diff --git a/macbuild/Resources/Info.plist.template b/macbuild/Resources/Info.plist.template new file mode 100644 index 000000000..74090cbb3 --- /dev/null +++ b/macbuild/Resources/Info.plist.template @@ -0,0 +1,28 @@ + + + + + NOTE + This file was originally generated by Qt/QMake. + CFBundleGetInfoString + Created by Qt/QMake + CFBundleExecutable + ${EXECUTABLE} + CFBundleIconFile + ${ICONFILE} + CFBundleIdentifier + de.klayout + CFBundleName + ${BUNDLENAME} + CFBundlePackageType + APPL + CFBundleVersion + ${VERSION} + CFBundleSignature + ???? + NSPrincipalClass + NSApplication + NSSupportsAutomaticGraphicsSwitching + + + diff --git a/macbuild/Resources/KLayoutEditor.sh b/macbuild/Resources/KLayoutEditor.sh new file mode 100755 index 000000000..96f2c4c2d --- /dev/null +++ b/macbuild/Resources/KLayoutEditor.sh @@ -0,0 +1,36 @@ +#!/bin/bash +#------------------------------------------------------------------------------------- +# File: KLayoutEditor.sh +# +# Descriptions: +# This is to invoke "klayout" with Qt5 distributed as a binary package for Mac +# in "editor" mode. +# +# You may specify style and other options as you like by setting +# "opt_style" and "opt_others" variable in this script. +#------------------------------------------------------------------------------------- + +#--------------------------------------------------------- +# With "-n" option, multiple instances can be invoked +#--------------------------------------------------------- +myKLayout="open -n -a /Applications/klayout.app --args " + +#=================================================== +# Pass command line parameters to klayout +# vvvvvvvvvv You may edit the block below vvvvvvvvvv +opt_mode="-e" +opt_style="-style=fusion" +opt_others="" +# ^^^^^^^^^^ You may edit the block above ^^^^^^^^^^ +#=================================================== +options="$opt_mode $opt_style $opt_others" +targetfiles=$@ + +echo "### Starting KLayout in Editor mode..." +$myKLayout $options $targetfiles & + +exit 0 + +#------------------- +# End of file +#------------------- diff --git a/macbuild/Resources/KLayoutHDD.icns b/macbuild/Resources/KLayoutHDD.icns new file mode 100644 index 000000000..c0a933218 Binary files /dev/null and b/macbuild/Resources/KLayoutHDD.icns differ diff --git a/macbuild/Resources/KLayoutViewer.sh b/macbuild/Resources/KLayoutViewer.sh new file mode 100755 index 000000000..d0fa2c038 --- /dev/null +++ b/macbuild/Resources/KLayoutViewer.sh @@ -0,0 +1,36 @@ +#!/bin/bash +#------------------------------------------------------------------------------------- +# File: KLayoutViewer.sh +# +# Descriptions: +# This is to invoke "klayout" with Qt5 distributed as a binary package for Mac +# in "viewer" mode. +# +# You may specify style and other options as you like by setting +# "opt_style" and "opt_others" variable in this script. +#------------------------------------------------------------------------------------- + +#--------------------------------------------------------- +# With "-n" option, multiple instances can be invoked +#--------------------------------------------------------- +myKLayout="open -n -a /Applications/klayout.app --args " + +#=================================================== +# Pass command line parameters to klayout +# vvvvvvvvvv You may edit the block below vvvvvvvvvv +opt_mode="-ne" +opt_style="-style=windows" +opt_others="" +# ^^^^^^^^^^ You may edit the block above ^^^^^^^^^^ +#=================================================== +options="$opt_mode $opt_style $opt_others" +targetfiles=$@ + +echo "### Starting KLayout in Viewer mode..." +$myKLayout $options $targetfiles & + +exit 0 + +#------------------- +# End of file +#------------------- diff --git a/macbuild/Resources/klayout-blue.icns b/macbuild/Resources/klayout-blue.icns new file mode 100644 index 000000000..511940b8b Binary files /dev/null and b/macbuild/Resources/klayout-blue.icns differ diff --git a/macbuild/Resources/klayout-green.icns b/macbuild/Resources/klayout-green.icns new file mode 100644 index 000000000..00b48ee66 Binary files /dev/null and b/macbuild/Resources/klayout-green.icns differ diff --git a/macbuild/Resources/klayout-red.icns b/macbuild/Resources/klayout-red.icns new file mode 100644 index 000000000..381fc8906 Binary files /dev/null and b/macbuild/Resources/klayout-red.icns differ diff --git a/macbuild/Resources/klayout-yellow.icns b/macbuild/Resources/klayout-yellow.icns new file mode 100644 index 000000000..424217b6c Binary files /dev/null and b/macbuild/Resources/klayout-yellow.icns differ diff --git a/macbuild/Resources/klayout.icns b/macbuild/Resources/klayout.icns new file mode 100644 index 000000000..424217b6c Binary files /dev/null and b/macbuild/Resources/klayout.icns differ diff --git a/macbuild/build4mac.py b/macbuild/build4mac.py new file mode 100755 index 000000000..9eaeaca8b --- /dev/null +++ b/macbuild/build4mac.py @@ -0,0 +1,901 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +#=============================================================================== +# File: "macbuild/build4mac.py" +# +# The top Python script for building KLayout (http://www.klayout.de/index.php) +# version 0.25 or later on different Apple Mac OSX platforms. +#=============================================================================== +from __future__ import print_function # to use print() of Python 3 in Python >= 2.7 +import sys +import os +import shutil +import glob +import platform +import optparse +import subprocess + +#------------------------------------------------------------------------------- +## To import global dictionaries of different modules and utility functions +#------------------------------------------------------------------------------- +mydir = os.path.dirname(os.path.abspath(__file__)) +sys.path.append( mydir + "/macbuild" ) +from build4mac_env import * +from build4mac_util import * + +#------------------------------------------------------------------------------- +## To set global variables including present directory and platform info. +#------------------------------------------------------------------------------- +def SetGlobals(): + global ProjectDir # project directory where "build.sh" exists + global Usage # string on usage + global BuildBash # the main build Bash script + global Platform # platform + global ModuleQt # Qt module to be used + global ModuleRuby # Ruby module to be used + global ModulePython # Python module to be used + global NonOSStdLang # True if non-OS-standard language is chosen + global NoQtBindings # True if not creating Qt bindings for Ruby scripts + global MakeOptions # options passed to `make` + global DebugMode # True if debug mode build + global CheckComOnly # True if only for checking the command line parameters to "build.sh" + global DeploymentF # True if fully (including Qt's Frameworks) deploy the binaries for bundles + global DeploymentP # True if partially deploy the binaries excluding Qt's Frameworks + global DeployVerbose # -verbose=<0-3> level passed to 'macdeployqt' tool + global Version # KLayout's version + # auxiliary variables on platform + global System # 6-tuple from platform.uname() + global Node # - do - + global Release # - do - + global Version # - do - + global Machine # - do - + global Processor # - do - + global Bit # machine bit-size + + Usage = "\n" + Usage += "--------------------------------------------------------------------------------------------------------\n" + Usage += "<< Usage of 'build4mac.py' >>\n" + Usage += " for building KLayout 0.25 or later on different Apple Mac OSX platforms.\n" + Usage += "\n" + Usage += "$ [python] ./build4mac.py \n" + Usage += " option & argument : descriptions | default value\n" + Usage += " ----------------------------------------------------------------------------------+---------------\n" + Usage += " : * key type names below are case insensitive * | \n" + Usage += " : 'nil' = not to support the script language | \n" + Usage += " : 'Sys' = using the OS standard script language | \n" + Usage += " : Refer to 'macbuild/build4mac_env.py' for details | \n" + Usage += " [-q|--qt ] : type=['Qt4MacPorts', 'Qt5MacPorts'] | qt5macports \n" + Usage += " [-r|--ruby ] : type=['nil', 'Sys', 'Src24', 'MP24'] | sys \n" + Usage += " [-p|--python ] : type=['nil', 'Sys', 'Ana27', 'Ana36', 'MP36'] | sys \n" + Usage += " [-n|--noqtbinding] : don't create Qt bindings for ruby scripts | disabled \n" + Usage += " [-m|--make