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>
|
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-01-15 14:34:59 -07:00
|
|
|
|
.POSIX:
|
|
|
|
|
.PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1)
|
2024-02-01 01:35:31 -07:00
|
|
|
|
.PRAGMA: command_comment # breaks without this?
|
2024-01-15 14:34:59 -07:00
|
|
|
|
|
2023-12-24 17:13:17 -07:00
|
|
|
|
PREFIX=/usr/local
|
2023-12-25 19:00:17 -07:00
|
|
|
|
|
2023-12-24 17:13:17 -07:00
|
|
|
|
CC=cc
|
2024-01-15 14:34:59 -07:00
|
|
|
|
RUSTC=rustc
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-01-15 23:54:42 -07:00
|
|
|
|
.PHONY: all
|
2024-02-07 19:42:11 -07:00
|
|
|
|
all: dj false fop intcmp rpn scrut str strcmp true
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-01-15 14:34:59 -07:00
|
|
|
|
build:
|
2023-12-27 23:20:31 -07:00
|
|
|
|
# keep build/include until bindgen(1) has stdin support
|
|
|
|
|
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
2024-01-15 15:50:12 -07:00
|
|
|
|
mkdir -p build/bin 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-01-15 14:34:59 -07:00
|
|
|
|
rm -rf build/ dist/
|
|
|
|
|
|
|
|
|
|
dist: all
|
2024-01-15 23:13:53 -07:00
|
|
|
|
mkdir -p dist/bin dist/share/man/man1
|
2024-01-15 14:34:59 -07:00
|
|
|
|
cp build/bin/* dist/bin/
|
2024-01-15 23:13:53 -07:00
|
|
|
|
cp docs/*.1 dist/share/man/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
|
|
|
|
|
mkdir -p $(PREFIX)
|
|
|
|
|
cp -r dist/* $(PREFIX)/
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-01-15 23:54:42 -07:00
|
|
|
|
.PHONY: test
|
2023-12-24 17:13:17 -07:00
|
|
|
|
test: build
|
|
|
|
|
tests/posix-compat.sh
|
2024-01-15 15:50:12 -07:00
|
|
|
|
$(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt
|
2023-12-24 17:13:17 -07:00
|
|
|
|
|
2024-02-06 22:21:46 -07:00
|
|
|
|
build/o/libsysexits.rlib: build
|
2023-12-27 23:20:31 -07: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 14:34:59 -07:00
|
|
|
|
bindgen --default-macro-constant-type signed --use-core --formatter=none \
|
2023-12-27 23:20:31 -07:00
|
|
|
|
"$$(printf '#include <sysexits.h>\n' \
|
2023-12-28 22:33:04 -07:00
|
|
|
|
| cpp -M -idirafter "build/include" - \
|
|
|
|
|
| sed 's/ /\n/g' | grep sysexits.h)" \
|
2024-02-01 01:33:47 -07:00
|
|
|
|
| $(RUSTC) $(RUSTFLAGS) --crate-type lib -o build/o/libsysexits.rlib -
|
2023-12-27 22:42:50 -07:00
|
|
|
|
|
2024-02-06 22:21:46 -07:00
|
|
|
|
build/o/libgetopt.rlib: src/getopt-rs/lib.rs
|
2024-02-18 20:03:04 -07:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \
|
2024-01-15 16:30:00 -07:00
|
|
|
|
-o build/o/libgetopt.rlib src/getopt-rs/lib.rs
|
2024-01-15 15:50:12 -07:00
|
|
|
|
|
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-02-06 22:21:46 -07:00
|
|
|
|
build/bin/fop: src/fop.rs build build/o/libgetopt.rlib build/o/libsysexits.rlib
|
2024-01-15 15:50:12 -07:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \
|
2024-02-06 22:21:46 -07:00
|
|
|
|
--extern sysexits=build/o/libsysexits.rlib \
|
2024-01-16 00:06:48 -07:00
|
|
|
|
-o $@ src/fop.rs
|
|
|
|
|
|
|
|
|
|
.PHONY: intcmp
|
|
|
|
|
intcmp: build/bin/intcmp
|
|
|
|
|
build/bin/intcmp: src/intcmp.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/intcmp.c
|
|
|
|
|
|
2024-02-01 00:31:41 -07:00
|
|
|
|
.PHONY: rpn
|
|
|
|
|
rpn: build/bin/rpn
|
2024-02-07 19:23:51 -07:00
|
|
|
|
build/bin/rpn: src/rpn.rs build build/o/libsysexits.rlib
|
|
|
|
|
$(RUSTC) $(RUSTFLAGS) \
|
|
|
|
|
--extern sysexits=build/o/libsysexits.rlib \
|
|
|
|
|
-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
|
|
|
|
|
|
|
|
|
|
.PHONY: true
|
|
|
|
|
true: build/bin/true
|
|
|
|
|
build/bin/true: src/true.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/true.c
|