# Copyright (c) 2023–2024 Emma Tebibyte # Copyright (c) 2023–2024 DTB # Copyright (c) 2023 Sasha Koshka # Copyright (c) 2024 Aaditya Aryal # SPDX-License-Identifier: FSFAP # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. # The octal escape \043 is utilized twice in this file as make(1p) will # interpret a hash in a rule as an inline comment. .POSIX: DESTDIR ?= dist PREFIX ?= /usr/local MANDIR != [ $(PREFIX) = / ] && printf '/usr/share/man\n' \ || printf '/share/man\n' CC ?= cc RUSTC ?= rustc RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \ --extern sysexits=build/o/libsysexits.rlib \ --extern strerror=build/o/libstrerror.rlib CFLAGS += -Ibuild/include .PHONY: all all: docs dj false fop hru intcmp mm npc rpn scrut str strcmp swab true build: mkdir -p build/bin build/docs build/include build/lib build/o build/test .PHONY: clean clean: rm -rf build dist dist: all mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1 cp build/bin/* $(DESTDIR)/$(PREFIX)/bin cp build/docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1 .PHONY: install install: dist cp -r $(DESTDIR)/* / .PHONY: test test: build tests/posix-compat.sh $(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt .PHONY: docs docs: docs/ build for file in docs/*; do original="$$(sed -n '/^\.TH/p' <"$$file")"; \ title="$$(printf '%s\n' "$$original" | sed \ "s/X\.X\.X/$$(git describe --tags --long | cut -d'-' -f1)/g")"; \ sed "s/$$original/$$title/g" <"$$file" >"build/$$file"; done .PHONY: rustlibs rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \ build/o/libstrerror.rlib build/include/sysexits.h: build cpp -dM -include sysexits.h /dev/null \ | grep '^.define EX_' >$@ \ || cpp -dM -include stdlib.h include/sysexits.h.template \ | grep -e '^.define EX_' -e '^.define EXIT_' >$@ build/o/libgetopt.rlib: build src/getopt-rs/lib.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \ -o $@ src/getopt-rs/lib.rs build/o/libstrerror.rlib: build src/strerror.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \ src/strerror.rs build/o/libsysexits.rlib: build build/include/sysexits.h