mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Files

This completely removes the old system of mkfiles.pl + Recipe + .R files that I used to manage the various per-platform makefiles and other build scripts in this code base. In its place is a CMakeLists.txt setup, which is still able to compile for Linux, Windows, MacOS, NestedVM and Emscripten. The main reason for doing this is because mkfiles.pl was a horrible pile of unmaintainable cruft. It was hard to keep up to date (e.g. didn't reliably support the latest Visual Studio project files); it was so specific to me that nobody else could maintain it (or was even interested in trying, and who can blame them?), and it wasn't even easy to _use_ if you weren't me. And it didn't even produce very good makefiles. In fact I've been wanting to hurl mkfiles.pl in the bin for years, but was blocked by CMake not quite being able to support my clang-cl based system for cross-compiling for Windows on Linux. But CMake 3.20 was released this month and fixes the last bug in that area (it had to do with preprocessing of .rc files), so now I'm unblocked! CMake is not perfect, but it's better at mkfiles.pl's job than mkfiles.pl was, and it has the great advantage that lots of other people already know about it. Other advantages of the CMake system: - Easier to build with. At least for the big three platforms, it's possible to write down a list of build commands that's actually the same everywhere ("cmake ." followed by "cmake --build ."). There's endless scope for making your end-user cmake commands more fancy than that, for various advantages, but very few people _have_ to. - Less effort required to add a new puzzle. You just add a puzzle() statement to the top-level CMakeLists.txt, instead of needing to remember eight separate fiddly things to put in the .R file. (Look at the reduction in CHECKLST.txt!) - The 'unfinished' subdirectory is now _built_ unconditionally, even if the things in it don't go into the 'make install' target. So they won't bit-rot in future. - Unix build: unified the old icons makefile with the main build, so that each puzzle builds without an icon, runs to build its icon, then relinks with it. - Windows build: far easier to switch back and forth between debug and release than with the old makefiles. - MacOS build: CMake has its own .dmg generator, which is surely better thought out than my ten-line bodge. - net reduction in the number of lines of code in the code base. In fact, that's still true _even_ if you don't count the deletion of mkfiles.pl itself - that script didn't even have the virtue of allowing everything else to be done exceptionally concisely.
66 lines
2.1 KiB
Python
Executable File
66 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# Helper script used by the NestedVM cmake build script.
|
|
#
|
|
# Usage: glob-symlinks.py <srcdir> <wildcard> [<srcdir> <wildcard> ...]
|
|
#
|
|
# Each pair of command-line arguments is treated as a source
|
|
# directory, followed by either a single filename or a wildcard.
|
|
#
|
|
# The result is to create symlinks in the program's working directory
|
|
# mirroring all the files matched by the filenames/wildcards, each
|
|
# pointing at the appropriate source directory.
|
|
#
|
|
# For example, this command
|
|
# glob-symlinks.py /foo \*.txt /bar wibble.blah
|
|
# might create symlinks as follows:
|
|
# this.txt -> /foo/this.txt
|
|
# that.txt -> /foo/that.txt
|
|
# wibble.blah -> /bar/wibble.blah
|
|
#
|
|
# CMake could mostly do this itself, except that some of the files
|
|
# that need symlinking during the NestedVM build (to make a tree that
|
|
# we archive up into a .jar file) are Java class files with some
|
|
# '$suffix' in the name, and CMake doesn't escape the $ signs, so that
|
|
# the suffix vanishes during shell expansion.
|
|
|
|
import sys
|
|
import os
|
|
import glob
|
|
|
|
def get_arg_pairs():
|
|
args = iter(sys.argv)
|
|
next(args) # skip program name
|
|
while True:
|
|
try:
|
|
yield next(args), next(args)
|
|
except StopIteration:
|
|
break
|
|
|
|
def get_globbed_pairs():
|
|
for srcdir, pattern in get_arg_pairs():
|
|
if glob.escape(pattern) == pattern:
|
|
# Assume that unglobbed filenames exist
|
|
#print("non-glob:", srcdir, pattern)
|
|
yield srcdir, pattern
|
|
else:
|
|
#print("globbing:", srcdir, pattern)
|
|
prefix = srcdir + "/"
|
|
for filename in glob.iglob(prefix + pattern):
|
|
assert filename.startswith(prefix)
|
|
filename = filename[len(prefix):]
|
|
#print(" ->", srcdir, filename)
|
|
yield srcdir, filename
|
|
|
|
for srcdir, filename in get_globbed_pairs():
|
|
dirname = os.path.dirname(filename)
|
|
if len(dirname) > 0:
|
|
try:
|
|
os.makedirs(dirname)
|
|
except FileExistsError:
|
|
pass
|
|
try:
|
|
os.symlink(os.path.join(srcdir, filename), filename)
|
|
except FileExistsError:
|
|
pass
|