2024-01-15 22:30:21 +00:00
|
|
|
|
# Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
2024-01-16 07:06:48 +00:00
|
|
|
|
# Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
2023-12-25 02:22:05 +00:00
|
|
|
|
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
|
2024-03-27 03:36:19 +00:00
|
|
|
|
# Copyright (c) 2024 Aaditya Aryal <aryalaadi123@gmail.com>
|
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:
|
2024-03-09 18:53:03 +00:00
|
|
|
|
|
|
|
|
|
# if using BSD make(1), remove these pragmas because they break it
|
2024-01-15 21:34:59 +00:00
|
|
|
|
.PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1)
|
2024-02-01 08:35:31 +00:00
|
|
|
|
.PRAGMA: command_comment # breaks without this?
|
2024-01-15 21:34:59 +00:00
|
|
|
|
|
2024-03-24 19:28:42 +00:00
|
|
|
|
DESTDIR ?= dist
|
|
|
|
|
PREFIX ?= /usr/local
|
2023-12-26 02:00:17 +00:00
|
|
|
|
|
2024-04-25 18:40:20 +00:00
|
|
|
|
MANDIR != [ $(PREFIX) = / ] && printf '/usr/share/man\n' \
|
|
|
|
|
|| printf '/share/man\n'
|
2024-03-24 19:28:42 +00:00
|
|
|
|
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | sed 's/ /\n/g' \
|
|
|
|
|
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
2023-12-26 02:00:17 +00:00
|
|
|
|
|
2024-03-24 19:28:42 +00:00
|
|
|
|
CC ?= cc
|
|
|
|
|
RUSTC ?= rustc
|
|
|
|
|
RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \
|
2024-03-02 06:04:53 +00:00
|
|
|
|
--extern sysexits=build/o/libsysexits.rlib \
|
|
|
|
|
--extern strerror=build/o/libstrerror.rlib
|
2024-03-24 19:28:42 +00:00
|
|
|
|
CFLAGS += -I$(SYSEXITS)
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-16 06:54:42 +00:00
|
|
|
|
.PHONY: all
|
2024-03-26 11:34:21 +00:00
|
|
|
|
all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab 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
|
|
|
|
|
2024-01-16 06:54:42 +00:00
|
|
|
|
.PHONY: clean
|
2023-12-25 00:13:17 +00:00
|
|
|
|
clean:
|
2024-03-24 19:28:42 +00:00
|
|
|
|
rm -rf build dist
|
2024-01-15 21:34:59 +00:00
|
|
|
|
|
|
|
|
|
dist: all
|
2024-03-24 19:28:42 +00:00
|
|
|
|
mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1
|
|
|
|
|
cp build/bin/* $(DESTDIR)/$(PREFIX)/bin
|
2024-04-25 18:40:20 +00:00
|
|
|
|
cp docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1
|
2024-01-15 21:34:59 +00:00
|
|
|
|
|
2024-01-16 06:54:42 +00:00
|
|
|
|
.PHONY: install
|
2024-01-15 21:34:59 +00:00
|
|
|
|
install: dist
|
2024-03-09 18:53:03 +00:00
|
|
|
|
cp -r $(DESTDIR)/* /
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-16 06:54:42 +00:00
|
|
|
|
.PHONY: test
|
2023-12-25 00:13:17 +00:00
|
|
|
|
test: build
|
|
|
|
|
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-03-02 06:04:53 +00:00
|
|
|
|
.PHONY: rustlibs
|
|
|
|
|
rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \
|
|
|
|
|
build/o/libstrerror.rlib
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2024-03-10 05:02:19 +00:00
|
|
|
|
build/o/libsysexits.rlib: build $(SYSEXITS)sysexits.h
|
2023-12-28 06:20:31 +00:00
|
|
|
|
# bandage solution until bindgen(1) gets stdin support
|
2024-03-10 05:02:19 +00:00
|
|
|
|
printf '#define EXIT_FAILURE 1\n' | cat - $(SYSEXITS)sysexits.h \
|
2023-12-28 06:20:31 +00:00
|
|
|
|
> build/include/sysexits.h
|
2024-01-15 21:34:59 +00:00
|
|
|
|
bindgen --default-macro-constant-type signed --use-core --formatter=none \
|
2024-03-10 05:02:19 +00:00
|
|
|
|
build/include/sysexits.h | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ -
|
2024-01-15 22:50:12 +00:00
|
|
|
|
|
2024-01-16 07:06:48 +00:00
|
|
|
|
.PHONY: dj
|
|
|
|
|
dj: build/bin/dj
|
|
|
|
|
build/bin/dj: src/dj.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/dj.c
|
2024-01-15 23:48:54 +00:00
|
|
|
|
|
2024-01-16 07:06:48 +00:00
|
|
|
|
.PHONY: false
|
|
|
|
|
false: build/bin/false
|
|
|
|
|
build/bin/false: src/false.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/false.c
|
2023-12-25 00:13:17 +00:00
|
|
|
|
|
2024-01-16 07:06:48 +00:00
|
|
|
|
.PHONY: fop
|
|
|
|
|
fop: build/bin/fop
|
2024-03-02 06:04:53 +00:00
|
|
|
|
build/bin/fop: src/fop.rs build rustlibs
|
|
|
|
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/fop.rs
|
2024-01-16 07:06:48 +00:00
|
|
|
|
|
2024-02-08 03:58:57 +00:00
|
|
|
|
.PHONY: hru
|
|
|
|
|
hru: build/bin/hru
|
2024-03-02 06:04:53 +00:00
|
|
|
|
build/bin/hru: src/hru.rs build rustlibs
|
|
|
|
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/hru.rs
|
2024-02-08 03:58:57 +00:00
|
|
|
|
|
2024-01-16 07:06:48 +00:00
|
|
|
|
.PHONY: intcmp
|
|
|
|
|
intcmp: build/bin/intcmp
|
|
|
|
|
build/bin/intcmp: src/intcmp.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/intcmp.c
|
|
|
|
|
|
2024-02-18 06:43:22 +00:00
|
|
|
|
.PHONY: mm
|
|
|
|
|
mm: build/bin/mm
|
|
|
|
|
build/bin/mm: src/mm.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/mm.c
|
|
|
|
|
|
2024-03-26 11:34:21 +00:00
|
|
|
|
|
|
|
|
|
.PHONY: npc
|
|
|
|
|
npc: build/bin/npc
|
|
|
|
|
build/bin/npc: src/npc.c build
|
|
|
|
|
$(CC) $(CFLAGAS) -o $@ src/npc.c
|
|
|
|
|
|
2024-02-01 07:31:41 +00:00
|
|
|
|
.PHONY: rpn
|
|
|
|
|
rpn: build/bin/rpn
|
2024-03-02 06:04:53 +00:00
|
|
|
|
build/bin/rpn: src/rpn.rs build rustlibs
|
|
|
|
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/rpn.rs
|
2024-02-01 07:31:41 +00:00
|
|
|
|
|
2024-01-16 07:06:48 +00: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-24 03:49:24 +00:00
|
|
|
|
.PHONY: swab
|
|
|
|
|
swab: build/bin/swab
|
|
|
|
|
build/bin/swab: src/swab.rs build build/o/libsysexits.rlib
|
2024-02-24 10:04:05 +00:00
|
|
|
|
$(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \
|
2024-02-24 03:49:24 +00:00
|
|
|
|
--extern sysexits=build/o/libsysexits.rlib \
|
|
|
|
|
-o $@ src/swab.rs
|
|
|
|
|
|
2024-01-16 07:06:48 +00:00
|
|
|
|
.PHONY: true
|
|
|
|
|
true: build/bin/true
|
|
|
|
|
build/bin/true: src/true.c build
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ src/true.c
|