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..24aafd699 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 @@ -413,7 +415,7 @@ def RunMainBuildBash(): # [3] Invoke the main Bash script #----------------------------------------------------- if Deployment: - return(0) + return 0 else: myscript = "build4mac.py" if subprocess.call( command, shell=True ) != 0: @@ -422,14 +424,14 @@ def RunMainBuildBash(): print( "!!! <%s>: failed to build KLayout" % myscript, file=sys.stderr ) print( "-------------------------------------------------------------" ) print("") - return(1) + return 1 else: print("") print( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" ) print( "### <%s>: successfully built KLayout" % myscript, file=sys.stderr ) print( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" ) print("") - return(0) + return 0 #------------------------------------------------------------------------------ ## To deploy built binaries and libraries on which those binaries depend @@ -451,25 +453,26 @@ 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 #------------------------------------------------------------- os.chdir(ProjectDir) if not Deployment: - return(1) + return 1 if not os.path.isfile(MacBuildLog): print( "!!! Build log file <%s> does not present !!!" % MacBuildLog, file=sys.stderr ) - return(1) + return 1 if not os.path.isdir(MacBuildDir): print( "!!! Build directory <%s> does not present !!!" % MacBuildDir, file=sys.stderr ) - return(1) + return 1 if not os.path.isdir(MacBinDir): print( "!!! Binary directory <%s> does not present !!!" % MacBinDir, file=sys.stderr ) - return(1) + return 1 print( " [2] Creating a new empty directory <%s> for deployment ..." % MacPkgDir ) @@ -583,7 +586,7 @@ def DeployBinariesForBundle(): if not ret == 0: msg = "!!! Failed to set and change to new identification names !!!" print(msg) - return(1) + return 1 print( " [6] Copying built executables and resource files ..." ) @@ -594,21 +597,26 @@ 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', '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( sourceDir0 + "/PkgInfo", targetDir0 ) # this file is not mandatory + shutil.copy2( sourceDir1 + "/klayout", targetDirM ) + shutil.copy2( sourceDir2 + "/klayout.icns", targetDirR ) - buddies = glob.glob( sourceDir4 + "/strm*" ) + os.chmod( targetDir0 + "/PkgInfo", 0644 ) + 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) @@ -628,7 +636,7 @@ def DeployBinariesForBundle(): os.chdir(ProjectDir) msg = "!!! Failed to set/change library identification name for <%s> !!!" print( msg % klayoutexec, file=sys.stderr ) - return(1) + return 1 buddies = glob.glob( "klayout.app/Contents/Buddy/strm*" ) macdepQtOpt = "" @@ -639,7 +647,7 @@ def DeployBinariesForBundle(): os.chdir(ProjectDir) msg = "!!! Failed to set/change library identification name for <%s> !!!" print( msg % buddy, file=sys.stderr ) - return(1) + return 1 print( " [8] Finally, deploying Qt's Frameworks ..." ) @@ -663,13 +671,116 @@ def DeployBinariesForBundle(): print( msg, file=sys.stderr ) print("") os.chdir(ProjectDir) - return(1) + 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) + 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', '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', '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 +795,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..a6fe8bbbc 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 #------------------------------------------------------------------------------- @@ -88,7 +90,7 @@ def SetChangeIdentificationNameOfDyLib( libdic ): if subprocess.call( command, shell=True ) != 0: msg = "!!! Failed to set the new identification name to <%s> !!!" print( msg % lib, file=sys.stderr ) - return(1) + return 1 #------------------------------------------------------------------------- # [2] Make the library aware of the new identifications of all supporters @@ -101,9 +103,9 @@ def SetChangeIdentificationNameOfDyLib( libdic ): if subprocess.call( command, shell=True ) != 0: msg = "!!! Failed to make the library aware of the new identification name <%s> of supporter <%s> !!!" print( msg % (nameNew, sup), file=sys.stderr ) - return(1) + return 1 # for-lib - return(0) + return 0 #------------------------------------------------------------------------------ ## To set the identification names of KLayout's libraries to an executable @@ -150,7 +152,7 @@ def SetChangeLibIdentificationName( executable, relativedir ): if subprocess.call( command, shell=True ) != 0: msg = "!!! Failed to set the new identification name to <%s> !!!" print( msg % lib, file=sys.stderr ) - return(1) + return 1 #----------------------------------------------------------- # [2] Make the application aware of the new identification @@ -161,9 +163,65 @@ def SetChangeLibIdentificationName( executable, relativedir ): if subprocess.call( command, shell=True ) != 0: msg = "!!! Failed to make the application aware of the new identification name <%s> !!!" print( msg % nameNew, file=sys.stderr ) - return(1) + return 1 # for-lib - return(0) + return 0 + +#------------------------------------------------------------------------------ +## To get KLayout's version from a file; most likely from '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 ("macbuild/Resources/Info.plist.template") +# +# @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