2026-07-18 18:48:23 +02:00
|
|
|
# Klammertext com/ Makefile
|
|
|
|
|
# Improved version with automatic header dependency tracking
|
|
|
|
|
|
|
|
|
|
K := $(KLAMMERTEXT_HOME)
|
|
|
|
|
KS := $(K)/sks
|
|
|
|
|
KM := $(K)/mac
|
|
|
|
|
|
2026-07-22 18:17:43 +02:00
|
|
|
include $(K)/env/makefile.env
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
# 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.
|
2026-09-25 18:43:22 +02:00
|
|
|
# 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.
|
2026-07-18 18:48:23 +02:00
|
|
|
BINDIR := ../bin
|
2026-09-25 18:43:22 +02:00
|
|
|
BINCOMMANDS := $(addprefix $(BINDIR)/,$(addsuffix $(EXE),$(COMMANDS)))
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
# 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
|
2026-09-25 18:43:22 +02:00
|
|
|
LIBRARY := $(LIBDIR)/$(KLAMMERTEXT_LIBFILE)
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
# Linker flags for commands
|
|
|
|
|
COM_LDFLAGS := $(EXPORT_DYNAMIC) -Wl,-rpath,'$(ORIGIN)/../lib' -L$(LIBDIR)
|
|
|
|
|
|
2026-09-25 00:32:55 +02:00
|
|
|
# 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.
|
2026-09-25 18:43:22 +02:00
|
|
|
RUNTIME_DLLS := $(addprefix $(BINDIR)/,$(KLAMMERTEXT_LIBFILE) $(GCC_RUNTIME_DLLS))
|
2026-09-25 00:32:55 +02:00
|
|
|
else
|
|
|
|
|
MANIFEST_OBJ :=
|
|
|
|
|
RUNTIME_DLLS :=
|
|
|
|
|
endif
|
|
|
|
|
|
2026-07-18 18:48:23 +02:00
|
|
|
# Dependency files for command sources
|
|
|
|
|
DEPFILES := $(addsuffix .d,$(COMMANDS))
|
|
|
|
|
|
|
|
|
|
# Compiler flags for dependency generation ($(@F) keeps the .d files in com/,
|
2026-09-25 18:43:22 +02:00
|
|
|
# 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
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
.PHONY: all clean redo clang mac sks install
|
|
|
|
|
|
2026-07-29 19:22:46 +02:00
|
|
|
# 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.
|
2026-07-18 18:48:23 +02:00
|
|
|
all : | mac sks
|
2026-07-29 19:22:46 +02:00
|
|
|
$(MAKE) -j commands
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
# Separate target to build commands (called after dependencies are ready)
|
|
|
|
|
.PHONY: commands
|
2026-09-25 00:32:55 +02:00
|
|
|
commands : $(BINCOMMANDS) $(RUNTIME_DLLS)
|
|
|
|
|
|
|
|
|
|
ifneq (,$(filter MINGW% MSYS%,$(UNAME_S)))
|
|
|
|
|
manifest.o : klammertext.rc klammertext.manifest
|
|
|
|
|
windres $< $@
|
2026-09-25 18:43:22 +02:00
|
|
|
$(BINDIR)/$(KLAMMERTEXT_LIBFILE) : $(LIBRARY) | $(BINDIR)
|
2026-09-25 00:32:55 +02:00
|
|
|
cp $< $@
|
|
|
|
|
$(BINDIR)/%.dll : $(GCC_BIN)%.dll | $(BINDIR)
|
|
|
|
|
cp $< $@
|
|
|
|
|
endif
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
# Ensure the output directory exists before linking into it.
|
|
|
|
|
$(BINDIR) :
|
|
|
|
|
mkdir -p $@
|
|
|
|
|
|
|
|
|
|
# Build mac/ objects
|
|
|
|
|
mac :
|
|
|
|
|
$(MAKE) -C $(KM) -j
|
|
|
|
|
|
|
|
|
|
# Build sks/ components (depends on mac)
|
|
|
|
|
sks : | mac
|
|
|
|
|
$(MAKE) -C $(KS)/kutil -j
|
|
|
|
|
$(MAKE) -C $(KS)/target -j
|
|
|
|
|
$(MAKE) -C $(KS)/document
|
|
|
|
|
|
|
|
|
|
# Explicit rules for each command - link against shared library, output to bin/
|
2026-09-25 18:43:22 +02:00
|
|
|
$(BINDIR)/kdiag$(EXE) : kdiag.cpp $(LIBRARY) $(MANIFEST_OBJ) | $(BINDIR)
|
2026-09-25 00:32:55 +02:00
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEPFLAGS) $(COM_LDFLAGS) $(LDFLAGS) $< $(MANIFEST_OBJ) -o $@ $(KLAMMERTEXT_LIB) $(LDLIBS)
|
2026-07-18 18:48:23 +02:00
|
|
|
|
2026-09-25 18:43:22 +02:00
|
|
|
$(BINDIR)/kdesc$(EXE) : kdesc.cpp $(LIBRARY) $(MANIFEST_OBJ) | $(BINDIR)
|
2026-09-25 00:32:55 +02:00
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEPFLAGS) $(COM_LDFLAGS) $(LDFLAGS) $< $(MANIFEST_OBJ) -o $@ $(KLAMMERTEXT_LIB) $(LDLIBS)
|
2026-07-18 18:48:23 +02:00
|
|
|
|
2026-09-25 18:43:22 +02:00
|
|
|
$(BINDIR)/ktext$(EXE) : ktext.cpp $(LIBRARY) $(MANIFEST_OBJ) | $(BINDIR)
|
2026-09-25 00:32:55 +02:00
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEPFLAGS) $(COM_LDFLAGS) $(LDFLAGS) $< $(MANIFEST_OBJ) -o $@ $(KLAMMERTEXT_LIB) $(LDLIBS)
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
# Out-of-tree system install (copies; the build tree stays intact). The
|
|
|
|
|
# installed commands still need KLAMMERTEXT_HOME pointing at a Klammertext tree
|
2026-09-25 18:43:22 +02:00
|
|
|
# for sks/ and the Python modules; their rpath finds the library in
|
2026-07-18 18:48:23 +02:00
|
|
|
# $(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
|
2026-09-25 18:43:22 +02:00
|
|
|
# ref/reflect$(DSO) links against the library and is dlopened, so
|
2026-09-07 22:37:05 +02:00
|
|
|
# it shares the class layouts: a stale one after a header change is
|
2026-09-25 18:43:22 +02:00
|
|
|
# the same memory-corruption hazard as a stale sks/document$(DSO).
|
2026-09-07 22:37:05 +02:00
|
|
|
$(MAKE) -C $(K)/ref clean
|
2026-09-08 16:54:21 +02:00
|
|
|
$(MAKE) -C $(K)/kpy clean
|
2026-07-18 18:48:23 +02:00
|
|
|
$(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)
|