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..e566d0d8f
--- /dev/null
+++ b/macbuild/Resources/KLayoutEditor.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+#-------------------------------------------------------------------------------------
+# File: KLayoutEditor.sh
+#
+# Descriptions:
+# This is to invoke "klayout" 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=cleanlooks"
+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..3eb1fdbe0
--- /dev/null
+++ b/macbuild/Resources/KLayoutViewer.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+#-------------------------------------------------------------------------------------
+# File: KLayoutViewer.sh
+#
+# Descriptions:
+# This is to invoke "klayout" 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=motif"
+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
index 83397e420..bf8a2ad4a 100755
--- a/macbuild/build4mac.py
+++ b/macbuild/build4mac.py
@@ -40,6 +40,7 @@ def SetGlobals():
global DebugMode # True if debug mode build
global CheckComOnly # True if only for checking the command line parameters to "build.sh"
global Deployment # True if deploying the binaries for a package
+ global Version # KLayout's version
# auxiliary variables on platform
global System # 6-tuple from platform.uname()
global Node # - do -
@@ -130,6 +131,7 @@ def SetGlobals():
DebugMode = False
CheckComOnly = False
Deployment = False
+ Version = GetKLayoutVersionFrom( "./version.sh" )
#------------------------------------------------------------------------------
## To get command line parameters
@@ -451,9 +453,10 @@ def DeployBinariesForBundle():
global AbsMacBinDir
global AbsMacBuildDir
global AbsMacBuildLog
+ global Version
print("")
- print( "##### Start deploying libraries and executables #####" )
+ print( "##### Started deploying libraries and executables for #####" )
print( " [1] Checking the status of working directory ..." )
#-------------------------------------------------------------
# [1] Check the status of working directory
@@ -594,21 +597,24 @@ def DeployBinariesForBundle():
os.chdir(ProjectDir)
sourceDir0 = "%s/klayout.app/Contents" % MacBinDir
sourceDir1 = sourceDir0 + "/MacOS"
- sourceDir2 = "%s/etc" % ProjectDir
- sourceDir3 = "%s/src/klayout_main" % ProjectDir
- sourceDir4 = "%s" % MacBinDir
+ sourceDir2 = "%s/macbuild/Resources" % ProjectDir
+ sourceDir3 = "%s" % MacBinDir
- shutil.copy2( sourceDir0 + "/Info.plist", targetDir0 )
- shutil.copy2( sourceDir1 + "/klayout", targetDirM )
- shutil.copy2( sourceDir2 + "/logo.png", targetDirR )
- shutil.copy2( sourceDir3 + "/logo.ico", targetDirR )
+ tmpfileM = ProjectDir + "/macbuild/Resources/Info.plist.template"
+ keydicM = { 'exe': 'klayout', 'icon': 'klayout.icns', 'bname': 'klayout.main', 'ver': Version }
+ plistM = GenerateInfoPlist( keydicM, tmpfileM )
+ file = open( targetDir0 + "/Info.plist", "w" )
+ file.write(plistM)
+ file.close()
- os.chmod( targetDir0 + "/Info.plist", 0644 )
- os.chmod( targetDirM + "/klayout", 0755 )
- os.chmod( targetDirR + "/logo.png", 0644 )
- os.chmod( targetDirR + "/logo.ico", 0644 )
+ shutil.copy2( sourceDir1 + "/klayout", targetDirM )
+ shutil.copy2( sourceDir2 + "/klayout.icns", targetDirR )
- buddies = glob.glob( sourceDir4 + "/strm*" )
+ os.chmod( targetDir0 + "/Info.plist", 0644 )
+ os.chmod( targetDirM + "/klayout", 0755 )
+ os.chmod( targetDirR + "/klayout.icns", 0644 )
+
+ buddies = glob.glob( sourceDir3 + "/strm*" )
for item in buddies:
shutil.copy2( item, targetDirB )
buddy = os.path.basename(item)
@@ -665,12 +671,115 @@ def DeployBinariesForBundle():
os.chdir(ProjectDir)
return(1)
else:
- msg = "### Deployed applications on OS X ###"
- print( msg, file=sys.stderr )
+ print( "##### Finished deploying libraries and executables for #####" )
print("")
os.chdir(ProjectDir)
return(0)
+#------------------------------------------------------------------------------
+## To deploy script bundles that invoke the main bundle (klayout.app) in
+# editor mode or viewer mode
+#
+# @return 0 on success; non-zero on failure
+#------------------------------------------------------------------------------
+def DeployScriptBundles():
+ global ProjectDir
+ global MacPkgDir
+ global AbsMacPkgDir
+
+ print("")
+ print( "##### Started deploying files for and #####" )
+ print( " [1] Checking the status of working directory ..." )
+ #-------------------------------------------------------------
+ # [1] Check the status of working directory
+ #-------------------------------------------------------------
+ os.chdir(ProjectDir)
+ if not os.path.isdir(MacPkgDir):
+ print( "!!! Package directory <%s> does not present !!!" % MacPkgDir, file=sys.stderr )
+ return(1)
+
+
+ print( " [2] Creating a new empty directory <%s> for deployment ..." % (MacPkgDir + "/klayout.scripts") )
+ #-------------------------------------------------------------
+ # [2] Create a new empty directory for deploying binaries
+ #-------------------------------------------------------------
+ os.chdir(MacPkgDir)
+ scriptDir = "klayout.scripts"
+ if os.path.isfile(scriptDir):
+ os.remove(scriptDir)
+ if os.path.isdir(scriptDir):
+ shutil.rmtree(scriptDir)
+ os.mkdir(scriptDir)
+
+
+ print( " [3] Creating the standard directory structure for the script bundles ..." )
+ #-------------------------------------------------------------
+ # [3] Create the directory skeleton for the two script bundles.
+ #
+ # klayout.scripts/+
+ # +-- KLayoutEditor.app/+
+ # | +-- Contents/+
+ # | +-- Info.plist
+ # | +-- Resources/
+ # | +-- MacOS/+
+ # | +-- 'KLayoutEditor.sh'
+ # +-- KLayoutViewer.app/+
+ # +-- Contents/+
+ # +-- Info.plist
+ # +-- Resources/
+ # +-- MacOS/+
+ # +-- 'KLayoutViewer.sh'
+ #-------------------------------------------------------------
+ os.chdir(ProjectDir)
+ targetDir0E = "%s/%s/KLayoutEditor.app/Contents" % ( AbsMacPkgDir, scriptDir )
+ targetDir0V = "%s/%s/KLayoutViewer.app/Contents" % ( AbsMacPkgDir, scriptDir )
+
+ targetDirME = targetDir0E + "/MacOS"
+ targetDirMV = targetDir0V + "/MacOS"
+ targetDirRE = targetDir0E + "/Resources"
+ targetDirRV = targetDir0V + "/Resources"
+
+ os.makedirs(targetDirME)
+ os.makedirs(targetDirMV)
+ os.makedirs(targetDirRE)
+ os.makedirs(targetDirRV)
+
+
+ print( " [4] Copying script files and icon files ..." )
+ #-------------------------------------------------------------------------------
+ # [4] Copy different script files icon files
+ #-------------------------------------------------------------------------------
+ os.chdir(ProjectDir)
+ resourceDir = "macbuild/Resources"
+
+ shutil.copy2( resourceDir + "/KLayoutEditor.sh", targetDirME )
+ shutil.copy2( resourceDir + "/KLayoutViewer.sh", targetDirMV )
+ shutil.copy2( resourceDir + "/klayout-red.icns", targetDirRE )
+ shutil.copy2( resourceDir + "/klayout-blue.icns", targetDirRV )
+
+ os.chmod( targetDirME + "/KLayoutEditor.sh", 0755 )
+ os.chmod( targetDirMV + "/KLayoutViewer.sh", 0755 )
+ os.chmod( targetDirRE + "/klayout-red.icns", 0644 )
+ os.chmod( targetDirRV + "/klayout-blue.icns", 0644 )
+
+ tmpfileE = ProjectDir + "/macbuild/Resources/Info.plist.template"
+ keydicE = { 'exe': 'KLayoutEditor.sh', 'icon': 'klayout-red.icns', 'bname': 'klayout.editor', 'ver': Version }
+ plistE = GenerateInfoPlist( keydicE, tmpfileE )
+ fileE = open( targetDir0E + "/Info.plist", "w" )
+ fileE.write(plistE)
+ fileE.close()
+
+ tmpfileV = ProjectDir + "/macbuild/Resources/Info.plist.template"
+ keydicV = { 'exe': 'KLayoutViewer.sh', 'icon': 'klayout-blue.icns', 'bname': 'klayout.viewer', 'ver': Version }
+ plistV = GenerateInfoPlist( keydicV, tmpfileV )
+ fileV = open( targetDir0V + "/Info.plist", "w" )
+ fileV.write(plistV)
+ fileV.close()
+ print( "##### Finished deploying files for and #####" )
+ print("")
+ os.chdir(ProjectDir)
+ return(0)
+
#------------------------------------------------------------------------------
## The main function
#------------------------------------------------------------------------------
@@ -684,8 +793,12 @@ def main():
else:
sys.exit(1)
else:
- ret = DeployBinariesForBundle()
- sys.exit(ret)
+ ret1 = DeployBinariesForBundle()
+ ret2 = DeployScriptBundles()
+ if not (ret1 == 0 and ret2 == 0):
+ sys.exit(1)
+ else:
+ sys.exit(0)
#===================================================================================
if __name__ == "__main__":
diff --git a/macbuild/build4mac_util.py b/macbuild/build4mac_util.py
index f67bf692b..b9e770a7b 100755
--- a/macbuild/build4mac_util.py
+++ b/macbuild/build4mac_util.py
@@ -13,6 +13,8 @@
from __future__ import print_function # to use print() of Python 3 in Python >= 2.7
import sys
import os
+import re
+import string
import subprocess
#-------------------------------------------------------------------------------
@@ -165,6 +167,62 @@ def SetChangeLibIdentificationName( executable, relativedir ):
# for-lib
return(0)
+#------------------------------------------------------------------------------
+## To get KLayout's version from a file like 'version.sh'
+#
+# @param[in] verfile version file from which version is retrieved
+#
+# @return version string
+#------------------------------------------------------------------------------
+def GetKLayoutVersionFrom( verfile='version.h' ):
+ version = "?.?.?"
+ try:
+ fd = open( verfile, "r" )
+ contents = fd.readlines()
+ fd.close()
+ except Exception as e:
+ return version
+
+ verReg = re.compile( u'(KLAYOUT_VERSION=\")([0-9A-Z_a-z\.]+)(\")' )
+ for line in contents:
+ m = verReg.match(line)
+ if m:
+ # print(m.group(0)) # KLAYOUT_VERSION="0.25"
+ # print(m.group(1)) # KLAYOUT_VERSION="
+ # print(m.group(2)) # 0.25
+ # print(m.group(3)) # "
+ version = m.group(2)
+ return version
+ return version
+
+#------------------------------------------------------------------------------
+## To generate the contents of "Info.plist" file from a template
+#
+# @param[in] keydic dictionary of four key words ['exe', 'icon', 'bname', 'ver']
+# @param[in] templfile template file
+#
+# @return generated strings
+#------------------------------------------------------------------------------
+def GenerateInfoPlist( keydic, templfile ):
+ val_exe = keydic['exe']
+ val_icon = keydic['icon']
+ val_bname = keydic['bname']
+ val_ver = keydic['ver']
+
+ try:
+ fd = open( templfile, "r" )
+ template = fd.read()
+ fd.close()
+ except Exception as e:
+ return "???"
+
+ t = string.Template(template)
+ s = t.substitute( EXECUTABLE = val_exe,
+ ICONFILE = val_icon,
+ BUNDLENAME = val_bname,
+ VERSION = val_ver)
+ return s
+
#----------------
# End of File
#----------------