Skip to content

Instantly share code, notes, and snippets.

@TomyLobo
Last active February 8, 2017 13:18
Show Gist options
  • Save TomyLobo/bdfc284e5d5027254edd2dd7bc805a7b to your computer and use it in GitHub Desktop.
Save TomyLobo/bdfc284e5d5027254edd2dd7bc805a7b to your computer and use it in GitHub Desktop.
Script to build tcl/tk on Cygwin without requiring an X server at runtime
#!/bin/bash
# This script downloads and builds tcl/tk and runs a small test case with it to verify that it works without an X server.
# It was tested with 8.6.6 and 8.5.18.
# At its core it's just "cd unix && ./configure --enable-threads --enable-64bit && make"
# I recommend to run this in a separate directory.
#
# Usage: ./build.sh [<version>]
#
# version - The tcl/tk version to use, defaults to 8.6.6.
#
# This was tested on 2017-02-07 with the following packages installed:
# - Cygwin x86_64 default install
# - make
# - gcc-core 5.4.0-1
# - mingw64-x86_64-gcc-core 5.4.0-3 - I guess that's needed in order to build the interface to GDI
# - libX11-devel 1.6.4-1 - I guess that's needed in order to build the interface to X11
# - gitk 2.8.3-1 - for the test case at the end
# - Plus dependencies (See end of file)
# - Plus a bunch of packages I probably had preinstalled and didn't consider related to this. Error messages are likely to hint at which libs are missing.
#--------------------------------------------------------------------------------------------------#
# Error handling, lazy style
set -e
#--------------------------------------------------------------------------------------------------#
# The version to download and build
version="${1:-8.6.6}"
# SHA1 checksums for the two tar.gz source archives (see https://sourceforge.net/projects/tcl/files/Tcl)
# Leave empty to use a simple existence check
case "$version" in
'8.6.6')
tcl_sha1sum='169dd1589cad62c9fac4257c113db245da502cd0'
tk_sha1sum='34d546496c05014349cf5edad6696c125ad4f9ea'
;;
'8.5.18')
tcl_sha1sum='7d4f35bc080d27b2e148689037d312ea41e4d16b'
tk_sha1sum='250f75581e618cb5ad0fb0c4f01c1faf21f4af54'
;;
esac
# The URL prefix for the source archives
url_prefix='http://prdownloads.sourceforge.net/tcl/'
#--------------------------------------------------------------------------------------------------#
# The version, reduced to $major.$minor
short_version="$(sed -r 's/^([^.]+\.[^.]+).*$/\1/' <<< "$version")"
# The subdirectory to place the collected executables and libraries into
tcl_bin=tcl-bin-"$short_version"
# The paths for the source archives
tcl_tar=tcl"$version"-src.tar.gz
tk_tar=tk"$version"-src.tar.gz
# The URLs for the source archives
tcl_url="$url_prefix$tcl_tar"
tk_url="$url_prefix$tk_tar"
#--------------------------------------------------------------------------------------------------#
build() {
# The path to the .tar.gz
local source="$1"
shift 1
# The arguments to ./configure
local configure_args=("$@")
# The directory containing the tar.gz
source_dir="$(dirname "$source")"
# The tar.gz
source_tar="$(basename "$source")"
# The directory in the tar.gz
source_base="$(basename "$source_tar" -src.tar.gz)"
(
cd "$source_dir"
# Extract a pristine source tree
rm -rf "$source_base"
tar xzf "$source_tar"
# Go to the unix subdirectory in that source tree
cd "$source_base"/unix
# The usual build process
./configure "${configure_args[@]}"
make
)
}
download() {
# The name of the local file
local tar="$1"
# The URL of the remote file
local url="$2"
# The SHA1 checksum of the file
local sha1sum="$3"
if [ -e "$tar" ]; then
# Check if a checksum was given
if [ -n "$sha1sum" ]; then
# Yes => verify checksum...
if sha1sum "$tar" 2> /dev/null | grep -qFe "$sha1sum"; then
echo "$tar has the correct checksum, not downloading."
return
else
echo "$tar has the wrong checksum, redownloading..."
fi
else
# No => Only check for existence...
echo "$tar exists, not downloading."
return
fi
else
echo "$tar does not exist, downloading..."
fi
# Downloadthe file
wget -O "$tar" "$url"
# Verify checksum again, if it was given...
if [ -n "$sha1sum" ]; then
if sha1sum "$tar" 2> /dev/null | grep -qFe "$sha1sum"; then
echo "$tar was downloaded with the correct checksum, download successful."
return
else
echo >&2 "$tar was downloaded with the wrong checksum, aborting"
exit 1
fi
fi
}
#--------------------------------------------------------------------------------------------------#
# Download tcl and tk
download "$tcl_tar" "$tcl_url" "$tcl_sha1sum"
download "$tk_tar" "$tk_url" "$tk_sha1sum"
# Build tcl and tk
build "$tcl_tar" --enable-threads --enable-64bit
build "$tk_tar" --enable-threads --enable-64bit --with-tcl="$(realpath tcl"$version"/unix)"
#--------------------------------------------------------------------------------------------------#
# Messily cobble everything together for a test case.
# Note that I only take DLLs parts from the unix subdirectory, not from the win subdirectory.
# If you don't care about messing up your system, you can probably just "make install".
rm -rf "$tcl_bin"
mkdir "$tcl_bin"
find {tcl,tk}"$version"/unix -name *.dll -o -name *.exe -o -name *.so | xargs cp -t "$tcl_bin"
# ../lib/tcl8.6 and ../lib/tk8.6 appear to be the paths where wish.exe expects its library
mkdir -p lib
ln -sf ../tcl"$version"/library lib/tcl"$short_version"
ln -sf ../tk"$version"/library lib/tk"$short_version"
# Create an example Git repository to show in gitk
cd "$tcl_bin"
# Initialize an empty repo
git init
# Set up user name/email specific to that repo
git config user.email "[email protected]"
git config user.name "Testuser"
# Create an empty commit
git commit --allow-empty -m 'test'
# Run gitk with the wish executable we just built
./wish /usr/bin/gitk
#--------------------------------------------------------------------------------------------------#
# If I inspect the gitk process with Process Explorer, I see threads whose names begin with "cygwin1.dll!", which tells me that this is indeed a cygwin process.
# I also tried "./wish /usr/bin/gitk --all &", which also works fine.
# I can only conclude that this change was deliberate and can easily be reversed by simply not removing all the "#ifdef CYGWIN" from the upstream sources
# List of automatically installed dependencies:
# binutils (2.25-4)
# GNU assembler, linker, and similar utilities
# Required by: gcc-core, python
# bzip2 (1.0.6-2)
# BZip file de/compressor
# Required by: tar
# ca-certificates (2.11-1)
# CA root certificates
# Required by: libopenssl100, libcurl4
# csih (0.9.9-1)
# Provides support for installing cygwin services
# Required by: openssh
# cygrunsrv (1.62-1)
# NT/W2K service initiator
# Required by: openssh
# cygwin-devel (2.6.1-1)
# Core development files
# Required by: gcc-core, python
# dejavu-fonts (2.37-1)
# DejaVu font family
# Required by: libfontconfig1
# desktop-file-utils (0.23-1)
# Utilities for manipulating desktop files
# Required by: libglib2.0_0
# gamin (0.1.10-15)
# File Alteration Monitor system (daemon)
# Required by: libfam0
# git (2.8.3-1)
# Distributed version control system
# Required by: gitk
# groff (1.22.3-1)
# GNU roff formatter
# Required by: man-db
# gsettings-desktop-schemas (3.18.1-1)
# GNOME desktop GSettings schemas
# Required by: libglib2.0_0
# kbproto (1.0.7-1)
# X.Org XKB extension headers
# Required by: libX11-devel
# less (481-1)
# A file pager program, similar to more(1)
# Required by: man-db, git
# libargp (20110921-3)
# Interface for parsing command-line arguments
# Required by: getent
# libatomic1 (5.4.0-1)
# GCC C11/C++11 locked atomics runtime library
# Required by: gcc-core
# libattr1 (2.4.46-1)
# Shared lib for managing filesystem extended attributes
# Required by: coreutils
# libblkid1 (2.25.2-2)
# Block device ID library (runtime)
# Required by: util-linux
# libbz2_1 (1.0.6-2)
# BZip file de/compressor
# Required by: bzip2, python, libfreetype6
# libcom_err2 (1.42.12-2)
# Common error description library (runtime)
# Required by: libgssapi_krb5_2, libkrb5_3
# libcrypt0 (1.4-1)
# Encryption/Decryption utility and library
# Required by: openssh, perl_base, python, libsasl2_3
# libcurl4 (7.52.1-1)
# Multi-protocol file transfer library (runtime)
# Required by: git
# libdb5.3 (5.3.28-1)
# Oracle Berkeley DB (runtime)
# Required by: python, libsasl2_3
# libedit0 (20130712-1)
# The NetBSD Editline library (runtime)
# Required by: openssh
# libexpat1 (2.2.0-0)
# Expat XML parser library (shared library)
# Required by: git, python, libfontconfig1
# libfam0 (0.1.10-15)
# File Alteration Monitor system (runtime library)
# Required by: libglib2.0_0
# libffi6 (3.2.1-2)
# Portable foreign function interface library
# Required by: python, libglib2.0_0, libp11-kit0
# libfontconfig-common (2.12.1-1)
# Font configuration library
# Required by: libfontconfig1
# libfontconfig1 (2.12.1-1)
# Font configuration library
# Required by: tcl-tk, libXft2
# libfreetype6 (2.6.5-1)
# FreeType font engine
# Required by: libXft2, libfontconfig1
# libgcc1 (5.4.0-1)
# GCC C runtime library
# Required by: gcc-core, libmpfr4, libgomp1, libquadmath0, libncursesw10, groff, libuuid1, openssh, libfontconfig1, libstdc++6, libdb5.3, libcom_err2, libunistring2
# libgdbm4 (1.12-1)
# GNU dbm implementation
# Required by: man-db, python
# libglib2.0_0 (2.46.2-4)
# GNOME core C function library (runtime)
# Required by: pkg-config, desktop-file-utils, gsettings-desktop-schemas, shared-mime-info, gamin
# libgmp10 (6.1.2-1)
# Library for arbitrary precision arithmetic (C runtime)
# Required by: coreutils, gawk, gcc-core, mingw64-x86_64-gcc-core, libmpfr4, libisl13, libmpc3
# libgomp1 (5.4.0-1)
# GCC OpenMP runtime library
# Required by: gcc-core
# libgssapi_krb5_2 (1.14.4-1)
# Kerberos reference implementation GSS-API library
# Required by: libcurl4, openssh, libsasl2_3
# libiconv (1.14-3)
# Unicode iconv() implementation
# Required by: man-db
# libiconv2 (1.14-3)
# Unicode iconv() implementation
# Required by: alternatives, bash, coreutils, diffutils, gcc-core, grep, man-db, mingw64-x86_64-gcc-core, tar, vim-minimal, libintl8, libpopt0, git, groff, libiconv, rsync, libglib2.0_0, libidn2_0, libpsl5, libunistring2, libxml2
# libidn2_0 (0.11-1)
# International Domain Name library (runtime)
# Required by: libcurl4, libpsl5
# libintl8 (0.19.8.1-2)
# GNU Internationalization runtime library
# Required by: alternatives, bash, coreutils, diffutils, findutils, gawk, gcc-core, grep, info, man-db, mingw64-x86_64-gcc-core, sed, tar, util-linux, libattr1, libpopt0, binutils, git, libgdbm4, libiconv, mingw64-x86_64-binutils, xz, libblkid1, libsmartcols1, libuuid1, python, libglib2.0_0, libgssapi_krb5_2, libkrb5_3, desktop-file-utils, libp11-kit0, libk5crypto3, libkrb5support0
# libisl13 (0.14.1-1)
# Integer Set Library (runtime)
# Required by: gcc-core, mingw64-x86_64-gcc-core
# libk5crypto3 (1.14.4-1)
# Kerberos reference implementation crypto library
# Required by: libgssapi_krb5_2, libkrb5_3
# libkrb5support0 (1.14.4-1)
# Kerberos reference implementation support library
# Required by: libgssapi_krb5_2, libkrb5_3, libk5crypto3
# libkrb5_3 (1.14.4-1)
# Kerberos reference implementation library
# Required by: openssh, libgssapi_krb5_2, libsasl2_3
# liblzma5 (5.2.2-1)
# LZMA de/compressor library (runtime)
# Required by: xz, libxml2
# libmpc3 (1.0.3-1)
# C library for multiple-precision floating-point computations with exact rounding (runtime)
# Required by: gcc-core, mingw64-x86_64-gcc-core
# libmpfr4 (3.1.5-1)
# A library for multiple-precision floating-point arithmetic with exact rounding (runtime)
# Required by: gawk, gcc-core, mingw64-x86_64-gcc-core, libmpc3
# libncursesw10 (6.0-9.20170121)
# Terminal display library
# Required by: info, libreadline7, ncurses, util-linux, vim-minimal, less, python, libedit0
# libnghttp2_14 (1.14.0-1)
# HTTP/2 C library
# Required by: libcurl4
# libopenldap2_4_2 (2.4.42-1)
# Lightweight Directory Access Protocol suite (runtime)
# Required by: libcurl4, libsasl2_3
# libp11-kit0 (0.22.1-1)
# PKCS#11 module library
# Required by: p11-kit
# libpcre1 (8.40-1)
# Perl Compatible Regular Expressions UTF-8 runtime
# Required by: grep, git, libglib2.0_0
# libpipeline1 (1.4.0-1)
# C library for manipulating pipelines of subprocesses - runtime
# Required by: man-db
# libpng16 (1.6.28-1)
# PNG library
# Required by: libfreetype6
# libpopt-common (1.16-2)
# Command-line option parser library
# Required by: libpopt0
# libpopt0 (1.16-2)
# Command-line option parser library
# Required by: cygutils
# libpsl5 (0.17.0-1)
# Public Suffix List library
# Required by: libcurl4
# libquadmath0 (5.4.0-1)
# GCC Quad-Precision Math runtime library
# Required by: gcc-core
# libsasl2_3 (2.1.26-9)
# The Cyrus SASL API implementation. (Runtime library and Daemon)
# Required by: libopenldap2_4_2
# libsigsegv2 (2.10-2)
# Library for handling page faults in user mode (runtime)
# Required by: diffutils
# libsmartcols1 (2.25.2-2)
# Tabular data formatting library (runtime)
# Required by: util-linux
# libsqlite3_0 (3.16.2-1)
# An embeddable SQL database engine (library)
# Required by: python
# libssh2_1 (1.7.0-1)
# SSH2 protocol library
# Required by: libcurl4
# libssp0 (5.4.0-1)
# GCC Stack-Smashing Protection runtime library
# Required by: gcc-core, vim-minimal, openssh, perl-TermReadKey, perl_base
# libstdc++6 (5.4.0-1)
# GCC C++ runtime library
# Required by: libncursesw10, groff, libdb5.3
# libtasn1_6 (4.9-1)
# ASN.1 library (runtime)
# Required by: p11-kit, p11-kit-trust
# libunistring2 (0.9.6-1)
# Library for manipulating Unicode strings - runtime
# Required by: libpsl5
# libuuid-devel (2.25.2-2)
# Universally Unique ID library (development)
# Required by: python
# libuuid1 (2.25.2-2)
# Universally Unique ID library (runtime)
# Required by: util-linux, libblkid1, libuuid-devel
# libvtv0 (5.4.0-1)
# GCC vtable verification library
# Required by: gcc-core
# libX11_6 (1.6.4-1)
# X.Org X11 core library (runtime)
# Required by: libX11-devel, tcl-tk, libXft2, libXss1, libXrender1, libXext6
# libXau-devel (1.0.8-1)
# X.Org Xauthority library
# Required by: libxcb-devel
# libXau6 (1.0.8-1)
# X.Org Xauthority library
# Required by: libxcb1, libXau-devel
# libxcb-devel (1.12-1)
# X Protocol C-Language Bindings (core development)
# Required by: libX11-devel
# libxcb1 (1.12-1)
# X Protocol C-Language Bindings (core runtime)
# Required by: libX11_6, libxcb-devel
# libXdmcp-devel (1.1.2-1)
# X.Org Display Manager Control Protocol library
# Required by: libxcb-devel
# libXdmcp6 (1.1.2-1)
# X.Org Display Manager Control Protocol library
# Required by: libxcb1, libXdmcp-devel
# libXext6 (1.3.3-1)
# X.Org X11 extension library
# Required by: libXss1
# libXft2 (2.3.2-1)
# X.Org X Freetype library
# Required by: tcl-tk
# libxml2 (2.9.4-1)
# GNOME XML library (runtime)
# Required by: shared-mime-info
# libXrender1 (0.9.9-1)
# X.Org Xrender library
# Required by: libXft2
# libXss1 (1.2.2-1)
# X.Org XScreenSaver library
# Required by: tcl-tk
# mingw64-x86_64-binutils (2.25.0.1.23f238d-1)
# Binutils for MinGW-w64 Win64 toolchain
# Required by: mingw64-x86_64-gcc-core
# mingw64-x86_64-headers (5.0.1-1)
# MinGW-w64 runtime headers and libraries
# Required by: mingw64-x86_64-runtime
# mingw64-x86_64-runtime (5.0.1-1)
# MinGW-w64 runtime headers and libraries
# Required by: mingw64-x86_64-gcc-core
# mingw64-x86_64-windows-default-manifest (6.4-1)
# Default Windows application manifest
# Required by: mingw64-x86_64-gcc-core
# mingw64-x86_64-winpthreads (5.0.1-1)
# MinGW-w64 POSIX threads
# Required by: mingw64-x86_64-gcc-core, mingw64-x86_64-headers
# openssh (7.4p1-1)
# The OpenSSH server and client programs
# Required by: git
# p11-kit (0.22.1-1)
# PKCS#11 module tool
# Required by: ca-certificates
# p11-kit-trust (0.22.1-1)
# PKCS#11 module library
# Required by: ca-certificates
# perl-Carp (1.38-1)
# Perl distribution Carp
# Required by: git
# perl-Error (0.17024-1)
# Perl distribution Error
# Required by: git
# perl-TermReadKey (2.37-1)
# Perl distribution TermReadKey
# Required by: git
# perl_base (5.22.3-1)
# Perl programming language interpreter
# Required by: git, perl-Carp, perl-Error, perl-TermReadKey
# pkg-config (0.29.1-1)
# Package compiling configuration utility
# Required by: libX11-devel, kbproto, libxcb-devel, xproto
# publicsuffix-list-dafsa (20170116-1)
# Public Suffix List
# Required by: libpsl5
# python (2.7.12-1)
# Python language interpreter
# Required by: git
# rsync (3.1.2-1)
# Fast remote file transfer program (can use existing data to minimize transfer)
# Required by: git
# shared-mime-info (1.7-1)
# Shared MIME info database
# Required by: libglib2.0_0
# tcl (8.5.18-1)
# Tool Command Language
# Required by: tcl-tk
# tcl-tk (8.5.18-1)
# Tcl X11 toolkit
# Required by: gitk
# tzcode (2016j-1)
# Time Zone Database utilities
# Required by: coreutils
# w32api-headers (4.0.4-1)
# MinGW-w64 Windows API headers for Cygwin
# Required by: gcc-core, w32api-runtime
# w32api-runtime (4.0.4-1)
# MinGW-w64 Windows API import libraries for Cygwin
# Required by: gcc-core
# windows-default-manifest (6.4-1)
# Default Windows application manifest
# Required by: gcc-core
# xorg-x11-fonts-dpi75 (7.5-3)
# X11 core fonts
# Required by: gitk
# xproto (7.0.31-1)
# X.Org X11 core headers
# Required by: libX11-devel, kbproto, libXau-devel, libXdmcp-devel
# xz (5.2.2-1)
# LZMA de/compressor
# Required by: tar
# zlib0 (1.2.8-3)
# gzip de/compression library (runtime)
# Required by: file, gcc-core, libopenssl100, man-db, mingw64-x86_64-gcc-core, util-linux, binutils, git, mingw64-x86_64-binutils, libcurl4, openssh, python, libglib2.0_0, libssh2_1, libfreetype6, libpng16, libxml2
# libguile17 (1.8.8-1)
# GNU Scheme interpreter library
# Required by: make
# libltdl7 (2.4.6-4)
# Libtool dynamic library loader library (runtime)
# Required by: libguile17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment