【问题标题】:Find precompiled or compile Tcl/Tk Frameworks for macOS查找用于 macOS 的预编译或编译 Tcl/Tk 框架
【发布时间】:2018-12-14 09:49:52
【问题描述】:

我是 Tcl/Tk 的初学者,但我已经需要部署一个包含 Tcl/Tk 框架的 .app(因为 .app 需要依赖其自己的 Tcl/Tk 版本而不是 macOS 标准和旧的 Tcl/Tk)。有人可以指出我在哪里可以找到预编译的框架或如何在 macOS 上编译它们的分步指南吗?

半天的搜索在这方面并没有什么收获。我想我的需求并不是很特别,因为我看到许多 .apps 都发布了他们自己的 Tcl/Tk 框架。 (PS:我需要从 Perl 访问这些框架,但这不应该有任何区别。)

【问题讨论】:

    标签: compilation frameworks tcl tk


    【解决方案1】:

    这是我的构建脚本。您将需要进行修改以适应 你的需求。

    • 我对 init.tcl 进行了修改,以便 Tcl 在正确的位置进行搜索 并且不会首先在 MacOS 标准位置查找。这部分 脚本将从 Tcl/Tk 8.7 开始中断。它还有一条路径是 非常具体到我的安装(“darwin 64 tcl lib”部分)。 保留它不会有任何伤害,或者您可以根据需要修改路径。
    • 我使应用程序可重定位,以便它可以从任何位置运行。 这可能是一个安全问题。建议进行额外处理 安装后完成,将库路径设置为静态位置。

    这个时候我个人推荐Tcl/Tk 8.6.8,但是必须用 较早的 XCode 版本(我在 Sierra 上使用 XCode 命令行工具 9.2)。
    MacOS Mojave 的各种错误修复仍在进行中。 其他人可能会推荐其他方式。

    变量:

    • macosxminver :将为其编译 Tcl/Tk 的最早的 MacOS 版本。
    • INSTLOC:安装位置。将其指向目标以外的其他地方 目录,然后将文件复制到目标目录。 请注意,脚本完全删除了 INSTLOC 目录。
    • sver:短 Tcl 版本。唯一使用它的地方是在 SRCDIR 定义中。 根据您的 SRCDIR 目录结构,您可能不需要它。
    • ver : Tcl 版本号。
    • mver : Tcl 主要版本号。
    • SRCDIR:Tcl/Tk 源树所在的位置。为此目的 脚本,我有一个具有以下结构的目录:

    目录结构:

    tcl868/
      tcl8.6.8/
      tk8.6.8/
    

    tclbuild.sh:

    #!/bin/bash
    
    macosxminver=10.9
    sver=868cp
    ver=8.6.8
    mver=8.6
    tclmver=$mver
    tkmver=$mver
    SRCDIR=$HOME/t/tcl${sver}
    INSTLOC=$HOME/t/localB
    
    if [[ $1 != "" ]]; then
      INSTLOC=$1
    fi
    
    if [[ -d $INSTLOC ]]; then
      rm -rf $INSTLOC
    fi
    mkdir $INSTLOC
    
    cd $SRCDIR
    
    test -d build && rm -rf build
    
    cd $SRCDIR
    cd tcl${ver}
    if [[ $? -eq 0 ]]; then
      f=library/init.tcl
      if [[ ! -f $f-orig ]]; then
        cp -pf $f $f-orig
      fi
      cp -pf $f-orig $f
    
      ed $f << _HERE_
    /issafe/
    i
        foreach Dir [list \$::tcl_library [file dirname \$::tcl_library]] {
            if { [string match *Tcl.framework* \$Dir] } {
              regsub Tcl.framework \$Dir Tk.framework Dir
              if {\$Dir ni \$::auto_path} {
                lappend ::auto_path \$Dir
              }
            }
        }
    
        # This needs to be at the end
        # The real wish executable is in an odd place.
        # Find the tcl directory in the path.
        set Dir [file dirname [info nameofexecutable]]
        if { [string match *MacOS* \$Dir] } {
          regsub {MacOS.*} \$Dir {MacOS} Dir
          set Dir [file join \$Dir darwin 64 tcl lib]
          lappend ::auto_path \$Dir
        } else {
          set Dir [file join [file dirname [file dirname \\
               [info nameofexecutable]]] lib]
        }
    
    .
    ?catch
    ?set Dir
    .,.+4 s/^/#/
    /catch
    .+1,.+5 s/^/#/
    w
    q
    _HERE_
    
      make -C macosx \
          PREFIX="" \
          CFLAGS_OPTIMIZE="-O2 -mmacosx-version-min=${macosxminver}" \
          INSTALL_ROOT=$INSTLOC install
    
      cd $SRCDIR
    
      chmod u+w $INSTLOC/bin/tclsh${tclmver}
      install_name_tool -change \
          "/Library/Frameworks/Tcl.framework/Versions/${tclmver}/Tcl" \
          @executable_path/../Library/Frameworks/Tcl.framework/Versions/${tclmver}/Tcl \
          $INSTLOC/bin/tclsh${tclmver}
    fi
    
    cd $SRCDIR
    cd tk${ver}
    if [[ $? -eq 0 ]]; then
      make -C macosx \
          PREFIX="" \
          CFLAGS_OPTIMIZE="-O2 -mmacosx-version-min=${macosxminver}" \
          INSTALL_ROOT=$INSTLOC install
      cd $SRCDIR
    
      chmod u+w $INSTLOC/Library/Frameworks/Tk.framework/Versions/${tkmver}/Resources/Wish.app/Contents/MacOS/Wish
      install_name_tool -change \
          "/Library/Frameworks/Tk.framework/Versions/${tkmver}/Tk" \
          @executable_path/../../../../Tk \
          $INSTLOC/Library/Frameworks/Tk.framework/Versions/${tkmver}/Resources/Wish.app/Contents/MacOS/Wish
      install_name_tool -change \
          "/Library/Frameworks/Tcl.framework/Versions/${tclmver}/Tcl" \
          @executable_path/../../../../../../../Tcl.framework/Versions/${tclmver}/Tcl \
          $INSTLOC/Library/Frameworks/Tk.framework/Versions/${tkmver}/Resources/Wish.app/Contents/MacOS/Wish
    fi
    
    cd $SRCDIR
    find $INSTLOC -type f -print0 | xargs -0 chmod u+w
    exit 0
    

    【讨论】:

    • 只是想知道:在 Tcl 中使用框架感知构建机制有什么问题吗:make -C /path/to/your/tcl/src/macosx install。另请参阅build instructions in macosx/README。它们对我来说很好用。
    • 没有区别。该脚本做了更多工作以确保构建可重定位并在其安装位置工作。
    • 感谢您的解释,当然值得添加到内置构建机器中?顺便说一句,适用于 8.6.9。
    • 我希望看到 init.tcl 脚本“已修复”,以便它使用基本安装目录作为定位包的起点。为了重新定位 Tcl/Tk 安装,可以编写一个实用程序脚本来重置共享库加载位置(而不是必须重新安装)。
    • 我们计划在 8.7 中修复所有这些问题(同时将所有这些文件打包到一个存档中,以便更快地打开和更健壮的安装)。
    【解决方案2】:

    编译几分钟后,建议的脚本在 Mojave 上对我来说失败,并出现以下错误:

    ERROR: version conflict for package "Tcl": have 8.5.9, need 8.6-
    If running this script from 'make html', set the NATIVE_TCLSH environment
    variable to point to an installed tclsh8.6 (or the equivalent tclsh86.exe
    on Windows).
    make[3]: *** [html-tcl] Error 1
    make[2]: *** [install-strip] Error 2
    make[1]: *** [install-tcl] Error 2
    make: *** [install-deploy] Error 2
    tclbuild.sh: line 74: cd: /Users/xl/t/tcl869cp: No such file or directory
    tclbuild.sh: line 83: cd: /Users/xl/t/tcl869cp: No such file or directory
    tclbuild.sh: line 84: cd: tk8.6.9: No such file or directory
    tclbuild.sh: line 103: cd: /Users/xl/t/tcl869cp: No such file or directory
    

    我有最新的 Tcl/Tk (8.6.9) 资源和与上述相同的文件夹结构。

    【讨论】:

    • 这不是一个正确的答案。也许您应该创建一个新问题来解决您的问题。
    猜你喜欢
    • 1970-01-01
    • 2019-06-17
    • 2016-01-14
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    • 2012-09-09
    相关资源
    最近更新 更多