Files
klammertext/com/Makefile
T
ackandClaude Fable 5.1 ed7bedf5a7 Images in plain text and the terminal; bounded build parallelism (from dev 16f82cc887af)
- @image under txt and ansi is a picture in characters, in five styles
  (Image_txt_style: halfblock the default, shade, ascii, quadrant,
  braille), sized to the terminal's width less a margin when ktext runs
  in one, every cell in its own colours under ansi; a figure's caption
  is centred under it and no txt caption is ruled off any more.
- The build compiles as many files at once as the machine has cores
  (JOBS; make -C com JOBS=1 for a small machine): the sub-makes' bare -j
  meant unlimited parallelism and exhausted 8 GB machines. The three
  install pages say "make -C com".

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-30 16:13:23 +02:00

136 lines
4.8 KiB
Makefile

# Klammertext com/ Makefile
# Improved version with automatic header dependency tracking
K := $(KLAMMERTEXT_HOME)
KS := $(K)/sks
KM := $(K)/mac
include $(K)/env/makefile.env
# Commands to build
COMMANDS := kdiag kdesc ktext
# Build output directory: commands are linked directly into ../bin, so there is
# exactly one copy of each (no redundant executables in com/) and make still
# tracks them by path for incremental builds.
# The targets carry the system's executable suffix (makefile.env's EXE) so
# that on Windows the file gcc writes, ktext.exe, is the target itself.
BINDIR := ../bin
BINCOMMANDS := $(addprefix $(BINDIR)/,$(addsuffix $(EXE),$(COMMANDS)))
# System install location (out-of-tree). Override on the command line, e.g.
# make install PREFIX=/opt DESTDIR=/tmp/stage
PREFIX ?= /usr/local
DESTDIR ?=
# Shared library location
LIBDIR := ../lib
LIBRARY := $(LIBDIR)/$(KLAMMERTEXT_LIBFILE)
# Linker flags for commands
COM_LDFLAGS := $(EXPORT_DYNAMIC) -Wl,-rpath,'$(ORIGIN)/../lib' -L$(LIBDIR)
# Windows: the application manifest (UTF-8 process code page) is linked into
# each command as a resource object; elsewhere there is nothing to add.
# (Only variables here: a rule before "all" would become the default goal.
# The Windows rules themselves follow the commands target below.)
ifneq (,$(filter MINGW% MSYS%,$(UNAME_S)))
MANIFEST_OBJ := manifest.o
# The DLLs beside the commands (makefile.env explains); with them, bin/ on
# PATH is all a Windows user needs besides Python.
RUNTIME_DLLS := $(addprefix $(BINDIR)/,$(KLAMMERTEXT_LIBFILE) $(GCC_RUNTIME_DLLS))
else
MANIFEST_OBJ :=
RUNTIME_DLLS :=
endif
# Dependency files for command sources
DEPFILES := $(addsuffix .d,$(COMMANDS))
# Compiler flags for dependency generation ($(@F) keeps the .d files in com/,
# not in the ../bin output directory; $(basename) drops the .exe so the file
# is ktext.d on every system, the name DEPFILES includes and clean removes).
DEPFLAGS = -MMD -MP -MF $(basename $(@F)).d
.PHONY: all clean redo clang mac sks install
# Default target: build dependencies first, then commands. The commands are
# three independent links against the finished library, so they run in
# parallel (as mac/ and the sks/ components already do) rather than one after
# another -- the serial links were about a quarter of a clean rebuild.
all : | mac sks
$(MAKE) -j$(JOBS) commands
# Separate target to build commands (called after dependencies are ready)
.PHONY: commands
commands : $(BINCOMMANDS) $(RUNTIME_DLLS)
ifneq (,$(filter MINGW% MSYS%,$(UNAME_S)))
manifest.o : klammertext.rc klammertext.manifest
windres $< $@
$(BINDIR)/$(KLAMMERTEXT_LIBFILE) : $(LIBRARY) | $(BINDIR)
cp $< $@
$(BINDIR)/%.dll : $(GCC_BIN)%.dll | $(BINDIR)
cp $< $@
endif
# Ensure the output directory exists before linking into it.
$(BINDIR) :
mkdir -p $@
# Build mac/ objects
mac :
$(MAKE) -C $(KM) -j$(JOBS)
# Build sks/ components (depends on mac)
sks : | mac
$(MAKE) -C $(KS)/kutil -j$(JOBS)
$(MAKE) -C $(KS)/target -j$(JOBS)
$(MAKE) -C $(KS)/document
# Explicit rules for each command - link against shared library, output to bin/
$(BINDIR)/kdiag$(EXE) : kdiag.cpp $(LIBRARY) $(MANIFEST_OBJ) | $(BINDIR)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEPFLAGS) $(COM_LDFLAGS) $(LDFLAGS) $< $(MANIFEST_OBJ) -o $@ $(KLAMMERTEXT_LIB) $(LDLIBS)
$(BINDIR)/kdesc$(EXE) : kdesc.cpp $(LIBRARY) $(MANIFEST_OBJ) | $(BINDIR)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEPFLAGS) $(COM_LDFLAGS) $(LDFLAGS) $< $(MANIFEST_OBJ) -o $@ $(KLAMMERTEXT_LIB) $(LDLIBS)
$(BINDIR)/ktext$(EXE) : ktext.cpp $(LIBRARY) $(MANIFEST_OBJ) | $(BINDIR)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEPFLAGS) $(COM_LDFLAGS) $(LDFLAGS) $< $(MANIFEST_OBJ) -o $@ $(KLAMMERTEXT_LIB) $(LDLIBS)
# Out-of-tree system install (copies; the build tree stays intact). The
# installed commands still need KLAMMERTEXT_HOME pointing at a Klammertext tree
# for sks/ and the Python modules; their rpath finds the library in
# $(PREFIX)/lib.
install : all
install -d $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/lib
install -m755 $(BINCOMMANDS) $(DESTDIR)$(PREFIX)/bin
install -m755 $(LIBRARY) $(DESTDIR)$(PREFIX)/lib
clean :
rm -f $(BINCOMMANDS) $(DEPFILES) *~
redo :
ifneq ($(filter clang,$(MAKECMDGOALS)),)
@:
else
$(MAKE) -C $(KM) clean
$(MAKE) -C $(KS)/kutil clean
$(MAKE) -C $(KS)/target clean
$(MAKE) -C $(KS)/document clean
# ref/reflect$(DSO) links against the library and is dlopened, so
# it shares the class layouts: a stale one after a header change is
# the same memory-corruption hazard as a stale sks/document$(DSO).
$(MAKE) -C $(K)/ref clean
$(MAKE) -C $(K)/kpy clean
$(MAKE) clean
$(MAKE) all
endif
# "make clang" = incremental build; "make clang redo" = full clean rebuild
clang :
$(MAKE) $(or $(filter-out clang,$(MAKECMDGOALS)),all) COMPILER=clang
# Include generated dependency files (if they exist)
-include $(DEPFILES)