2026-10-03 13:12:54 +03:00
|
|
|
# Makefile for Solo-C.
|
|
|
|
|
#
|
|
|
|
|
# Written for the POSIX make utility (IEEE Std 1003.1, XCU make) and a POSIX
|
|
|
|
|
# shell (/bin/sh), so it works with any conforming make and no GNU-only
|
|
|
|
|
# features. Deliberately avoided:
|
|
|
|
|
#
|
|
|
|
|
# $(shell ...) not POSIX - pkg-config is run by the recipe shell
|
|
|
|
|
# ?= not POSIX - defaults are plain "=" and are overridden on
|
|
|
|
|
# the command line, e.g. make CC=clang CFLAGS=-O1
|
|
|
|
|
# .PHONY not POSIX - see the FORCE target at the bottom
|
|
|
|
|
# target-specific variables, ifeq, wildcard, -include, ... all non-POSIX
|
|
|
|
|
#
|
|
|
|
|
# Rule syntax used here: recipe lines start with a TAB, macros are written
|
|
|
|
|
# $(NAME) (POSIX also accepts ${NAME}), and the only automatic macro used is
|
|
|
|
|
# $@, the name of the target. Prerequisite names are written out: $< is POSIX
|
|
|
|
|
# for inference rules only, and "$< is the first prerequisite" in a plain rule
|
|
|
|
|
# is a GNU extension that even BusyBox make lacks.
|
|
|
|
|
|
|
|
|
|
SHELL = /bin/sh
|
|
|
|
|
|
|
|
|
|
# Standard macros. POSIX defaults CC to c99; Solo-C uses the system compiler
|
|
|
|
|
# driver "cc" instead, which is the compiler a platform actually ships
|
|
|
|
|
# (gcc, clang, musl-gcc, ...). Every macro here can be overridden from the
|
|
|
|
|
# command line: make CC=clang, make CFLAGS=-O1, make LDLIBS=-lcurl.
|
|
|
|
|
CC = cc
|
|
|
|
|
CFLAGS = -Wall -Wextra -O2 -std=c99 -march=native
|
|
|
|
|
LDFLAGS =
|
|
|
|
|
LDLIBS =
|
|
|
|
|
LINT = lint
|
|
|
|
|
LINTFLAGS =
|
|
|
|
|
LINTLIBS = -lc
|
|
|
|
|
|
|
|
|
|
# Link-time discovery of the shared dependencies. POSIX make cannot run
|
|
|
|
|
# commands while reading a makefile, so the flags are collected by the shell
|
|
|
|
|
# that runs the recipe instead of by $(shell ...) while parsing.
|
|
|
|
|
PKG_CONFIG = pkg-config
|
|
|
|
|
PKGS = libcurl json-c readline
|
|
|
|
|
# $$(...) survives expansion of the macro and reaches the shell as $(...).
|
|
|
|
|
PKG_CFLAGS = $$($(PKG_CONFIG) --cflags $(PKGS))
|
|
|
|
|
PKG_LIBS = $$($(PKG_CONFIG) --libs $(PKGS))
|
2026-10-03 09:15:02 +03:00
|
|
|
|
|
|
|
|
# Fully static binary.
|
|
|
|
|
#
|
|
|
|
|
# The distro libcurl.a cannot be linked statically on Alpine: it pulls in
|
|
|
|
|
# libpsl, libbrotli, libzstd and libnghttp2, whose static archives hold LTO
|
|
|
|
|
# bytecode from GCC 14 that the installed GCC 15 cannot read ("bytecode
|
|
|
|
|
# stream ... generated with LTO version 14.0 instead of the expected 15.1"),
|
|
|
|
|
# so psl_*/Brotli*/ZSTD* never resolve. -fno-lto does not help; the objects
|
|
|
|
|
# are bytecode, not C.
|
|
|
|
|
#
|
|
|
|
|
# static-deps/libcurl.a is curl built without those four libraries, leaving
|
|
|
|
|
# only LTO-free static deps. Regenerate with: make static-deps
|
|
|
|
|
#
|
|
|
|
|
# c-ares is built from source by the same script, for two reasons: a minimal
|
|
|
|
|
# system often has no libcares.a at all (Void's c-ares-devel ships the shared
|
|
|
|
|
# library only), and where an archive does exist it can carry the same LTO
|
|
|
|
|
# bytecode as the distro libcurl.a. Building it also pins the version.
|
|
|
|
|
#
|
|
|
|
|
# Archive order matters: libcurl.a pulls in ares_* symbols, so libcares.a has to
|
|
|
|
|
# come after it on the link line.
|
2026-10-03 13:12:54 +03:00
|
|
|
CURL_STATIC = static-deps/libcurl.a
|
|
|
|
|
CARES_STATIC = static-deps/libcares.a
|
2026-10-03 09:15:02 +03:00
|
|
|
STATIC_LIBS = $(CURL_STATIC) $(CARES_STATIC) -lssl -lcrypto -lz -lidn2 -lunistring \
|
|
|
|
|
-lreadline -lncursesw -ljson-c -lm -ldl -pthread
|
|
|
|
|
|
|
|
|
|
solo: main.c
|
2026-10-03 13:12:54 +03:00
|
|
|
$(CC) $(CFLAGS) $(PKG_CFLAGS) $(LDFLAGS) -o $@ main.c $(PKG_LIBS) $(LDLIBS)
|
|
|
|
|
strip $@
|
2026-10-03 09:15:02 +03:00
|
|
|
|
2026-10-03 13:12:54 +03:00
|
|
|
# Writes solo-static, not a file called "static", so $@ is not used here.
|
2026-10-03 09:15:02 +03:00
|
|
|
static: main.c
|
|
|
|
|
@for f in $(CURL_STATIC) $(CARES_STATIC); do \
|
|
|
|
|
test -f $$f || { echo "missing $$f - run: make static-deps"; exit 1; }; \
|
|
|
|
|
done
|
2026-10-03 13:12:54 +03:00
|
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -fno-lto -static -o solo-static main.c $(STATIC_LIBS) $(LDLIBS)
|
2026-10-03 09:15:02 +03:00
|
|
|
strip solo-static
|
|
|
|
|
|
2026-10-03 13:12:54 +03:00
|
|
|
static-deps: FORCE
|
2026-10-03 09:15:02 +03:00
|
|
|
sh ./mkstaticdeps.sh
|
|
|
|
|
|
|
|
|
|
# Rebuild both archives from scratch, ignoring what is already there.
|
2026-10-03 13:12:54 +03:00
|
|
|
static-deps-force: FORCE
|
2026-10-03 09:15:02 +03:00
|
|
|
FORCE=1 sh ./mkstaticdeps.sh
|
|
|
|
|
|
2026-10-03 13:12:54 +03:00
|
|
|
# Install paths. DESTDIR and PREFIX may be set on the command line:
|
|
|
|
|
# make install DESTDIR=/tmp/pkg PREFIX=/usr
|
|
|
|
|
PREFIX = /usr/local
|
2026-10-03 09:15:02 +03:00
|
|
|
BINDIR = $(PREFIX)/bin
|
2026-10-03 13:12:54 +03:00
|
|
|
INSTALL = install
|
2026-10-03 09:15:02 +03:00
|
|
|
|
2026-10-03 13:12:54 +03:00
|
|
|
install: solo FORCE
|
2026-10-03 09:15:02 +03:00
|
|
|
$(INSTALL) -d $(DESTDIR)$(BINDIR)
|
|
|
|
|
$(INSTALL) -m 755 solo $(DESTDIR)$(BINDIR)/solo
|
|
|
|
|
|
2026-10-03 13:12:54 +03:00
|
|
|
uninstall: FORCE
|
2026-10-03 09:15:02 +03:00
|
|
|
rm -f $(DESTDIR)$(BINDIR)/solo $(DESTDIR)$(BINDIR)/solo-static
|
|
|
|
|
|
2026-10-03 13:12:54 +03:00
|
|
|
clean: FORCE
|
2026-10-03 09:15:02 +03:00
|
|
|
rm -f solo solo-static
|
|
|
|
|
|
2026-10-03 13:12:54 +03:00
|
|
|
# POSIX lint target: runs the lint tool named by the LINT macro.
|
|
|
|
|
lint: main.c FORCE
|
|
|
|
|
$(LINT) $(LINTFLAGS) $(LINTLIBS) main.c
|
|
|
|
|
|
|
|
|
|
# POSIX make has no .PHONY special target. Any target that depends on FORCE is
|
|
|
|
|
# always out of date, because FORCE never creates a file, so its recipe always
|
|
|
|
|
# runs. Keep this target last: the first target in the file is the default goal.
|
|
|
|
|
FORCE:
|
|
|
|
|
@:
|