From 5620a1484376e4d60d60af63b1c4ee1614173169 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 06:57:11 +0000 Subject: [PATCH] Add a top-level Makefile that builds the modules and installs the voices make builds app_speakingclock and mod_speakingclock for whichever PBX headers are installed (or PBX=...), synth/mssam and synth/macintalk, sclock-render, and fetches the Microsoft and Apple voice data from the Internet Archive into sources/. make install runs each part's install. macintalk now takes VOICEDIR from PREFIX like mssam does. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRSErpfiUMyvxPjp5Am --- Makefile | 96 +++++++++++++++++++++++++++++++++++++ README.md | 22 +++++++++ synth/macintalk/Makefile | 2 +- synth/macintalk/macintalk.c | 6 ++- 4 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..87223a4 --- /dev/null +++ b/Makefile @@ -0,0 +1,96 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Builds and installs everything: the PBX modules, our synthesisers and the +# voices. +# +# make build the modules for the PBXs found here, the +# synthesisers, sclock-render, and fetch the +# Microsoft and Apple voice data +# sudo make install install the modules, their configs, voices/, and +# the synthesisers with their voice data +# make test render 30 seconds of a voice with sclock-render +# make clean remove what make built (keeps sources/) +# make distclean also remove the downloaded voice data +# +# Settings: +# PBX="asterisk freeswitch" which modules to build (default: the PBXs +# whose headers are installed) +# FETCH=no don't download the voice data; the live +# mssam, macintalk and plaintalk voices then +# won't speak until it is fetched +# SYNTH=no skip synth/mssam and synth/macintalk +# PREFIX=/usr/local where the synthesisers go +# DESTDIR=... staging root, for packaging +# and the sub-makes' own: ASTERISK_INCLUDE, FS_INCLUDE, MODULES_DIR, +# CONF_DIR, SOUNDS_DIR (see asterisk/Makefile and freeswitch/Makefile). +# +# Microsoft's and Apple's voice files are not in this repository: they are +# downloaded from the Internet Archive into sources/ (tools/fetch-mssam.py, +# tools/fetch-macintalk.py). The PlainTalk voices need unar or unrar, and +# the Microsoft voices cabextract or 7z. + +PREFIX ?= /usr/local +FETCH ?= yes +SYNTH ?= yes + +# PBXs whose headers are installed +HAVE_ASTERISK := $(if $(ASTERISK_INCLUDE),$(wildcard $(ASTERISK_INCLUDE)/asterisk.h),$(wildcard /usr/include/asterisk.h)) +HAVE_FREESWITCH := $(or $(shell pkg-config --exists freeswitch 2>/dev/null && echo yes), \ + $(if $(FS_INCLUDE),$(wildcard $(FS_INCLUDE)/switch.h)), \ + $(wildcard /usr/include/freeswitch/switch.h /usr/local/freeswitch/include/freeswitch/switch.h)) +PBX ?= $(if $(HAVE_ASTERISK),asterisk) $(if $(HAVE_FREESWITCH),freeswitch) +PBX := $(strip $(PBX)) + +SYNTHS := $(if $(filter yes,$(SYNTH)),mssam macintalk) +VOICEDATA := $(if $(filter yes,$(FETCH)),$(addprefix voices-,$(SYNTHS))) +SUBMAKE = $(MAKE) PREFIX=$(PREFIX) + +all: check-pbx $(PBX) $(SYNTHS) core $(VOICEDATA) + +check-pbx: + @if [ -z "$(PBX)" ]; then \ + echo "No Asterisk or FreeSWITCH headers found: building only the synthesisers"; \ + echo "and sclock-render. Install asterisk-dev or libfreeswitch-dev, or set"; \ + echo "PBX=asterisk / PBX=freeswitch with ASTERISK_INCLUDE= / FS_INCLUDE=."; \ + else echo "Building for: $(PBX)"; fi + +asterisk freeswitch core: + $(MAKE) -C $@ + +mssam macintalk: + $(SUBMAKE) -C synth/$@ + +voices-mssam voices-macintalk: + $(SUBMAKE) -C synth/$(@:voices-%=%) voices + +# voices/ goes into each PBX's sounds directory with its module +install: all $(addprefix install-,$(PBX)) $(if $(VOICEDATA),$(addprefix install-,$(SYNTHS)),$(addprefix install-bin-,$(SYNTHS))) + +install-asterisk install-freeswitch: + $(MAKE) -C $(@:install-%=%) install + +install-mssam install-macintalk: + $(SUBMAKE) -C synth/$(@:install-%=%) install + +# FETCH=no: the program only; its voice data can be installed later +install-bin-mssam install-bin-macintalk: + install -d $(DESTDIR)$(PREFIX)/bin + install -m 755 synth/$(@:install-bin-%=%)/$(@:install-bin-%=%) $(DESTDIR)$(PREFIX)/bin/ + +test: core + cd core && ./sclock-render -v ../voices tim-pat-simmons 1762791295 30 /tmp/sclock-test.sln Europe/London + @echo "/tmp/sclock-test.sln (8 kHz signed linear)" + +clean: + $(MAKE) -C asterisk clean + $(MAKE) -C freeswitch clean + $(MAKE) -C core clean + $(MAKE) -C synth/mssam clean + $(MAKE) -C synth/macintalk clean + +distclean: clean + rm -rf sources/mssam sources/macintalk + +.PHONY: all check-pbx asterisk freeswitch core mssam macintalk \ + voices-mssam voices-macintalk install install-asterisk install-freeswitch \ + install-mssam install-macintalk install-bin-mssam install-bin-macintalk \ + test clean distclean diff --git a/README.md b/README.md index c3f3843..01e9176 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,28 @@ able to give the time to the second. The recordings in `voices/` belong to their original owners, and **are not covered by the code's licence**. See [NOTICE.md](NOTICE.md). +## Building and installing + +From the top of the repository: + +```sh +make # modules for the PBXs found here, synth/mssam, synth/macintalk, + # sclock-render, and the Microsoft and Apple voice data +sudo make install # modules, configs, voices/ into each PBX's sounds/speaking-clock, + # and the synthesisers with their voice data under /usr/local +make test # render 30 seconds of Pat Simmons with sclock-render +``` + +It builds `app_speakingclock` if Asterisk's headers are installed and +`mod_speakingclock` if FreeSWITCH's are. `make PBX="asterisk freeswitch"` +picks them yourself (with `ASTERISK_INCLUDE=` or `FS_INCLUDE=` for headers +somewhere else). Microsoft's and Apple's voice files are not in this +repository: `make` downloads them from the Internet Archive into +`sources/` (cabextract or 7z for Microsoft's, unar or unrar for the +PlainTalk voices). `FETCH=no` skips the download, `SYNTH=no` skips the +synthesisers, and `PREFIX=` and `DESTDIR=` work as usual. The sections +below build one part at a time. + ## How it keeps time The old machines were one recording that every caller listened in on. The diff --git a/synth/macintalk/Makefile b/synth/macintalk/Makefile index 4004486..7430b73 100644 --- a/synth/macintalk/Makefile +++ b/synth/macintalk/Makefile @@ -10,7 +10,7 @@ CFLAGS ?= -O2 -Wall -Wextra -Wno-missing-field-initializers SOURCES ?= ../../sources/macintalk macintalk: macintalk.c plaintalk.c rules.h - $(CC) $(CFLAGS) -o $@ macintalk.c -lm + $(CC) $(CFLAGS) -DVOICEDIR='"$(VOICEDIR)"' -o $@ macintalk.c -lm voices: $(SOURCES)/fred.ttvd diff --git a/synth/macintalk/macintalk.c b/synth/macintalk/macintalk.c index e317207..509bdce 100644 --- a/synth/macintalk/macintalk.c +++ b/synth/macintalk/macintalk.c @@ -1203,9 +1203,13 @@ static int write_wav(FILE *f, const float *x, int n) return ferror(f) ? -1 : 0; } +#ifndef VOICEDIR +#define VOICEDIR "/usr/local/share/macintalk" +#endif + static const char *default_dir(void) { - static const char *dirs[] = { "/usr/local/share/macintalk", "/usr/share/macintalk", + static const char *dirs[] = { VOICEDIR, "/usr/local/share/macintalk", "/usr/share/macintalk", "sources/macintalk", NULL }; const char *e = getenv("MACINTALK_VOICES"); int i;