2024-01-15 15:30:21 -07:00
|
|
|
|
# Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
2024-01-16 00:06:48 -07:00
|
|
|
|
# Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
2023-12-24 19:22:05 -07:00
|
|
|
|
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
|
2024-03-26 21:36:19 -06:00
|
|
|
|
# Copyright (c) 2024 Aaditya Aryal <aryalaadi123@gmail.com>
|
2023-12-24 17:13:17 -07:00
|
|
|
|
# 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.
|
|
|
|
|
|
2024-06-19 23:29:22 -06:00
|
|
|
|
# The octal escape \043 is utilized twice in this file as make(1p) will
|
|
|
|
|
# interpret a hash in a rule as an inline comment.
|
|
|
|
|
|
2024-01-15 14:34:59 -07:00
|
|
|
|
.POSIX:
|
2024-03-09 11:53:03 -07:00
|
|
|
|
|
2024-03-24 13:28:42 -06:00
|
|
|
|
DESTDIR ?= dist
|
|
|
|
|
PREFIX ?= /usr/local
|
2023-12-25 19:00:17 -07:00
|
|
|
|
|
2024-08-10 12:49:35 -06:00
|
|
|
|
# for conditionally compiling OS features
|
|
|
|
|
OS != uname
|
2024-08-10 13:04:41 -06:00
|
|
|
|
OS_INCLUDE != test -e include/$(OS).mk && printf 'include/$(OS).mk\n' \
|
2024-08-13 11:56:09 -06:00
|
|
|
|
|| printf '/dev/null\n'
|
2024-08-10 12:49:35 -06:00
|
|
|
|
|
2024-06-29 08:24:11 -06:00
|
|
|
|
# normalized prefix
|
2024-07-29 23:04:08 -06:00
|
|
|
|
PREFIX_N != dirname $(PREFIX)/.
|
2024-08-01 13:12:54 -06:00
|
|
|
|
MANDIR != test $(PREFIX_N) = / && printf '/usr/share/man\n' \
|
2024-04-25 12:40:20 -06:00
|
|
|
|
|| printf '/share/man\n'
|
2024-06-30 21:21:02 -06:00
|
|
|
|
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | tr ' ' '\n' \
|
2024-03-24 13:28:42 -06:00
|
|
|
|
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
2023-12-25 19:00:17 -07:00
|
|
|
|
|
2024-03-24 13:28:42 -06:00
|
|
|
|
CC ?= cc
|
|
|
|
|
RUSTC ?= rustc
|
2024-07-29 23:04:08 -06:00
|
|
|
|
RUSTFLAGS += --extern getopt=build/o/libgetopt.rlib \
|
2024-08-10 12:49:35 -06:00
|
|
|
|
--extern strerror=build/o/libstrerror.rlib \
|
|
|
|
|
--extern sysexits=build/o/libsysexits.rlib
|
2024-03-24 13:28:42 -06:00
|
|
|
|
CFLAGS += -I$(SYSEXITS)
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-08-02 17:29:30 -06:00
|
|
|
|
# testing requires the absolute path to the bin directory set
|
|
|
|
|
BIN = build/bin
|
|
|
|
|
|
|
|
|
|
.PHONY: default
|
|
|
|
|
default: all test
|
|
|
|
|
|
2024-01-15 23:54:42 -07:00
|
|
|
|
.PHONY: all
|
2024-06-26 09:46:32 -06:00
|
|
|
|
all: dj false fop hru intcmp mm npc peek rpn scrut str strcmp swab true
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-06-18 16:32:20 -06:00
|
|
|
|
# keep build/include until bindgen(1) has stdin support
|
|
|
|
|
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
2024-01-15 14:34:59 -07:00
|
|
|
|
build:
|
2024-06-23 23:47:29 -06:00
|
|
|
|
mkdir -p build/bin build/docs build/include build/lib build/o build/test
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-01-15 23:54:42 -07:00
|
|
|
|
.PHONY: clean
|
2023-12-24 17:13:17 -07:00
|
|
|
|
clean:
|
2024-03-24 13:28:42 -06:00
|
|
|
|
rm -rf build dist
|
2024-01-15 14:34:59 -07:00
|
|
|
|
|
2024-06-29 08:24:11 -06:00
|
|
|
|
dist: all docs
|
2024-06-29 08:36:12 -06:00
|
|
|
|
mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1
|
2024-03-24 13:28:42 -06:00
|
|
|
|
cp build/bin/* $(DESTDIR)/$(PREFIX)/bin
|
2024-06-23 23:47:29 -06:00
|
|
|
|
cp build/docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1
|
2024-01-15 14:34:59 -07:00
|
|
|
|
|
2024-01-15 23:54:42 -07:00
|
|
|
|
.PHONY: install
|
2024-01-15 14:34:59 -07:00
|
|
|
|
install: dist
|
2024-03-09 11:53:03 -07:00
|
|
|
|
cp -r $(DESTDIR)/* /
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-08-09 23:50:31 -06:00
|
|
|
|
include tests/tests.mk
|
|
|
|
|
|
2024-01-15 23:54:42 -07:00
|
|
|
|
.PHONY: test
|
2024-08-02 17:29:30 -06:00
|
|
|
|
test: all $(TESTS) /tmp/getopt
|
|
|
|
|
@echo $(TESTS)
|
2024-06-27 14:04:31 -06:00
|
|
|
|
/tmp/getopt
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-06-27 14:04:31 -06:00
|
|
|
|
/tmp/getopt: src/libgetopt.rs
|
|
|
|
|
$(RUSTC) --test -o /tmp/getopt src/libgetopt.rs
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-06-23 23:47:29 -06:00
|
|
|
|
.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
|
|
|
|
|
|
2024-08-10 12:49:35 -06:00
|
|
|
|
# include OS feature libraries for compilation
|
2024-08-10 13:04:41 -06:00
|
|
|
|
include $(OS_INCLUDE)
|
2024-08-10 12:49:35 -06:00
|
|
|
|
|
2024-03-01 23:04:53 -07:00
|
|
|
|
.PHONY: rustlibs
|
2024-08-10 12:49:35 -06:00
|
|
|
|
rustlibs: build/o/libgetopt.rlib build/o/libstrerror.rlib \
|
|
|
|
|
build/o/libsysexits.rlib $(OSLIB)
|
2024-03-01 23:04:53 -07:00
|
|
|
|
|
2024-06-27 14:04:31 -06:00
|
|
|
|
build/o/libgetopt.rlib: build src/libgetopt.rs
|
2024-03-01 23:04:53 -07:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \
|
2024-06-27 14:04:31 -06:00
|
|
|
|
-o $@ src/libgetopt.rs
|
2024-03-01 23:04:53 -07:00
|
|
|
|
|
2024-06-27 14:04:31 -06:00
|
|
|
|
build/o/libstrerror.rlib: build src/libstrerror.rs
|
2024-03-01 23:04:53 -07:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \
|
2024-06-27 14:04:31 -06:00
|
|
|
|
src/libstrerror.rs
|
2024-03-01 23:04:53 -07:00
|
|
|
|
|
2024-06-29 08:01:33 -06:00
|
|
|
|
build/o/libsysexits.rlib: build/include/sysexits.h
|
2024-01-15 14:34:59 -07:00
|
|
|
|
bindgen --default-macro-constant-type signed --use-core --formatter=none \
|
2024-03-09 22:02:19 -07:00
|
|
|
|
build/include/sysexits.h | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ -
|
2024-01-15 15:50:12 -07:00
|
|
|
|
|
2024-06-29 08:01:33 -06:00
|
|
|
|
# bandage solution until bindgen(1) gets stdin support
|
|
|
|
|
build/include/sysexits.h: build $(SYSEXITS)sysexits.h
|
|
|
|
|
printf '\043define EXIT_FAILURE 1\n' | cat - $(SYSEXITS)sysexits.h > $@
|
|
|
|
|
|
2024-01-16 00:06:48 -07:00
|
|
|
|
.PHONY: dj
|
|
|
|
|
dj: build/bin/dj
|
|
|
|
|
build/bin/dj: src/dj.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/dj.c
|
2024-01-15 16:48:54 -07:00
|
|
|
|
|
2024-01-16 00:06:48 -07:00
|
|
|
|
.PHONY: false
|
|
|
|
|
false: build/bin/false
|
|
|
|
|
build/bin/false: src/false.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/false.c
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-01-16 00:06:48 -07:00
|
|
|
|
.PHONY: fop
|
|
|
|
|
fop: build/bin/fop
|
2024-03-01 23:04:53 -07:00
|
|
|
|
build/bin/fop: src/fop.rs build rustlibs
|
2024-08-01 13:12:54 -06:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) -o $@ src/fop.rs
|
2024-01-16 00:06:48 -07:00
|
|
|
|
|
2024-02-07 20:58:57 -07:00
|
|
|
|
.PHONY: hru
|
|
|
|
|
hru: build/bin/hru
|
2024-03-01 23:04:53 -07:00
|
|
|
|
build/bin/hru: src/hru.rs build rustlibs
|
2024-08-01 13:12:54 -06:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) -o $@ src/hru.rs
|
2024-02-07 20:58:57 -07:00
|
|
|
|
|
2024-01-16 00:06:48 -07:00
|
|
|
|
.PHONY: intcmp
|
|
|
|
|
intcmp: build/bin/intcmp
|
2024-07-15 03:14:57 -06:00
|
|
|
|
build/bin/intcmp: src/intcmp.rs build rustlibs
|
2024-08-01 13:12:54 -06:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) -o $@ src/intcmp.rs
|
2024-01-16 00:06:48 -07:00
|
|
|
|
|
2024-02-17 23:43:22 -07:00
|
|
|
|
.PHONY: mm
|
|
|
|
|
mm: build/bin/mm
|
2024-07-13 23:49:27 -06:00
|
|
|
|
build/bin/mm: src/mm.rs build rustlibs
|
2024-08-01 13:12:54 -06:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) -o $@ src/mm.rs
|
2024-02-17 23:43:22 -07:00
|
|
|
|
|
2024-03-26 05:34:21 -06:00
|
|
|
|
.PHONY: npc
|
|
|
|
|
npc: build/bin/npc
|
|
|
|
|
build/bin/npc: src/npc.c build
|
2024-07-29 23:04:08 -06:00
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/npc.c
|
2024-03-26 05:34:21 -06:00
|
|
|
|
|
2024-04-17 16:37:54 -06:00
|
|
|
|
.PHONY: peek
|
|
|
|
|
peek: build/bin/peek
|
|
|
|
|
build/bin/peek: src/peek.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/peek.c
|
|
|
|
|
|
2024-02-01 00:31:41 -07:00
|
|
|
|
.PHONY: rpn
|
|
|
|
|
rpn: build/bin/rpn
|
2024-03-01 23:04:53 -07:00
|
|
|
|
build/bin/rpn: src/rpn.rs build rustlibs
|
2024-08-01 13:12:54 -06:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) -o $@ src/rpn.rs
|
2024-02-01 00:31:41 -07:00
|
|
|
|
|
2024-01-16 00:06:48 -07:00
|
|
|
|
.PHONY: scrut
|
|
|
|
|
scrut: build/bin/scrut
|
|
|
|
|
build/bin/scrut: src/scrut.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/scrut.c
|
|
|
|
|
|
|
|
|
|
.PHONY: str
|
|
|
|
|
str: build/bin/str
|
|
|
|
|
build/bin/str: src/str.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/str.c
|
|
|
|
|
|
|
|
|
|
.PHONY: strcmp
|
|
|
|
|
strcmp: build/bin/strcmp
|
|
|
|
|
build/bin/strcmp: src/strcmp.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/strcmp.c
|
|
|
|
|
|
2024-02-23 20:49:24 -07:00
|
|
|
|
.PHONY: swab
|
|
|
|
|
swab: build/bin/swab
|
2024-06-29 07:49:47 -06:00
|
|
|
|
build/bin/swab: src/swab.rs build rustlibs
|
2024-08-01 13:12:54 -06:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) -o $@ src/swab.rs
|
2024-02-23 20:49:24 -07:00
|
|
|
|
|
2024-01-16 00:06:48 -07:00
|
|
|
|
.PHONY: true
|
|
|
|
|
true: build/bin/true
|
|
|
|
|
build/bin/true: src/true.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/true.c
|