2024-01-15 22:30:21 +00:00
|
|
|
|
# Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
2023-12-25 00:13:17 +00:00
|
|
|
|
# Copyright (c) 2023 DTB <trinity@trinity.moe>
|
2023-12-25 02:22:05 +00:00
|
|
|
|
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
|
2023-12-25 00:13:17 +00: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-01-15 21:34:59 +00:00
|
|
|
|
.POSIX:
|
|
|
|
|
.PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1)
|
|
|
|
|
|
|
|
|
|
.PHONY: all
|
2023-12-25 00:13:17 +00:00
|
|
|
|
.PHONY: clean
|
|
|
|
|
.PHONY: install
|
|
|
|
|
.PHONY: test
|
|
|
|
|
|
|
|
|
|
PREFIX=/usr/local
|
2023-12-26 02:00:17 +00:00
|
|
|
|
|
2023-12-25 00:13:17 +00:00
|
|
|
|
CC=cc
|
2024-01-15 21:34:59 +00:00
|
|
|
|
RUSTC=rustc
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-15 22:30:21 +00:00
|
|
|
|
# to build, first run ./configure
|
|
|
|
|
include *.mk
|
|
|
|
|
|
2024-01-15 23:48:54 +00:00
|
|
|
|
all: dj false fop intcmp scrut str strcmp true
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-15 21:34:59 +00:00
|
|
|
|
build:
|
2023-12-28 06:20:31 +00:00
|
|
|
|
# keep build/include until bindgen(1) has stdin support
|
|
|
|
|
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
2024-01-15 22:50:12 +00:00
|
|
|
|
mkdir -p build/bin build/include build/lib build/o build/test
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
|
|
|
|
clean:
|
2024-01-15 21:34:59 +00:00
|
|
|
|
rm -rf build/ dist/
|
|
|
|
|
|
|
|
|
|
dist: all
|
|
|
|
|
mkdir -p \
|
|
|
|
|
dist/bin \
|
|
|
|
|
dist/man/man1 \
|
|
|
|
|
# dist/$(PREFIX)/lib \
|
|
|
|
|
# dist/$(PREFIX)/man/man3
|
|
|
|
|
cp build/bin/* dist/bin/
|
|
|
|
|
# cp build/lib/* dist/$(PREFIX)/lib/
|
|
|
|
|
cp docs/*.1 dist/man/man1/
|
|
|
|
|
# cp docs/*.3 dist/$(PREFIX)/man/man3/
|
|
|
|
|
|
|
|
|
|
install: dist
|
|
|
|
|
mkdir -p $(PREFIX)
|
|
|
|
|
cp -r dist/* $(PREFIX)/
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
|
|
|
|
test: build
|
|
|
|
|
tests/cc-compat.sh
|
|
|
|
|
tests/posix-compat.sh
|
2024-01-15 22:50:12 +00:00
|
|
|
|
$(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-15 21:34:59 +00:00
|
|
|
|
sysexits: build
|
2023-12-28 06:20:31 +00:00
|
|
|
|
# bandage solution until bindgen(1) gets stdin support
|
|
|
|
|
printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \
|
|
|
|
|
> build/include/sysexits.h
|
2024-01-15 21:34:59 +00:00
|
|
|
|
bindgen --default-macro-constant-type signed --use-core --formatter=none \
|
2023-12-28 06:20:31 +00:00
|
|
|
|
"$$(printf '#include <sysexits.h>\n' \
|
2023-12-29 05:33:04 +00:00
|
|
|
|
| cpp -M -idirafter "build/include" - \
|
|
|
|
|
| sed 's/ /\n/g' | grep sysexits.h)" \
|
2023-12-28 05:42:50 +00:00
|
|
|
|
| $(RUSTC) $(RUSTCFLAGS) --crate-type lib -o build/o/libsysexits.rlib -
|
|
|
|
|
|
2024-01-15 22:50:12 +00:00
|
|
|
|
libgetopt: src/getopt-rs/lib.rs
|
|
|
|
|
$(RUSTC) $(RUSTCFLAGS) --crate-type=lib --crate-name=getopt \
|
2024-01-15 23:30:00 +00:00
|
|
|
|
-o build/o/libgetopt.rlib src/getopt-rs/lib.rs
|
2024-01-15 22:50:12 +00:00
|
|
|
|
|
2024-01-15 23:48:54 +00:00
|
|
|
|
dj: src/dj.c build_dir
|
|
|
|
|
$(CC) $(CFLAGS) -o build/bin/dj src/dj.c
|
|
|
|
|
|
2024-01-15 21:34:59 +00:00
|
|
|
|
false: src/false.rs build
|
2024-01-15 22:30:21 +00:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) -o build/bin/false src/false.rs
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-15 22:50:12 +00:00
|
|
|
|
fop: src/fop.rs build libgetopt sysexits
|
|
|
|
|
$(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \
|
|
|
|
|
-o build/bin/fop src/fop.rs
|
2023-12-27 22:44:19 +00:00
|
|
|
|
|
2024-01-15 21:34:59 +00:00
|
|
|
|
intcmp: src/intcmp.c build
|
2023-12-25 02:17:24 +00:00
|
|
|
|
$(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-15 21:34:59 +00:00
|
|
|
|
scrut: src/scrut.c build
|
2023-12-26 00:50:23 +00:00
|
|
|
|
$(CC) $(CFLAGS) -o build/bin/scrut src/scrut.c
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-15 21:34:59 +00:00
|
|
|
|
str: src/str.c build
|
2023-12-25 02:17:24 +00:00
|
|
|
|
$(CC) $(CFLAGS) -o build/bin/str src/str.c
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-15 21:34:59 +00:00
|
|
|
|
strcmp: src/strcmp.c build
|
2023-12-25 02:17:24 +00:00
|
|
|
|
$(CC) $(CFLAGS) -o build/bin/strcmp src/strcmp.c
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-15 21:34:59 +00:00
|
|
|
|
true: src/true.rs build
|
2024-01-15 22:30:21 +00:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) -o build/bin/true src/true.rs
|