GNUmakefile: replaced with POSIX Makefile

This commit is contained in:
Emma Tebibyte 2024-01-15 14:34:59 -07:00
parent f89a686d3c
commit 622c13021d
Signed by: emma
GPG Key ID: 06FA419A1698C270
2 changed files with 35 additions and 39 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
build/ build/
dist/

View File

@ -7,9 +7,10 @@
# permitted in any medium without royalty provided the copyright notice and this # permitted in any medium without royalty provided the copyright notice and this
# notice are preserved. This file is offered as-is, without any warranty. # notice are preserved. This file is offered as-is, without any warranty.
# If we want to use POSIX make we cant use ifeq .POSIX:
# .POSIX: .PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1)
# .PRAGMA: posix_202x
.PHONY: all
.PHONY: clean .PHONY: clean
.PHONY: install .PHONY: install
.PHONY: test .PHONY: test
@ -19,73 +20,67 @@ PREFIX=/usr/local
CC=cc CC=cc
CFLAGS=-O3 -Lbuild/lib -idirafter include CFLAGS=-O3 -Lbuild/lib -idirafter include
RUSTC=rustc +nightly RUSTC=rustc
RUSTCFLAGS=-Zlocation-detail=none -Copt-level=z -Ccodegen-units=1 \ RUSTCFLAGS=-Copt-level=z -Ccodegen-units=1 -Cpanic=abort -Clto=y \
-Cpanic=abort -Clto=y -Cstrip=symbols -Ctarget-cpu=native \ -Cstrip=symbols -Ctarget-cpu=native \
--extern sysexits=build/o/libsysexits.rlib --extern sysexits=build/o/libsysexits.rlib
ifeq ($(CC), gcc) all: false fop intcmp scrut str strcmp true test
CFLAGS=-O3 -s -Wl,-z,noseparate-code,-z,nosectionheader -flto -Lbuild/lib \
-idirafter include
endif
ifeq ($(CC), clang) build:
CFLAGS=-O3 -Wall -Lbuild/lib -idirafter include
endif
ifeq ($(CC), tcc)
CFLAGS=-O3 -s -Wl -flto -Lbuild/lib -idirafter include
endif
build: build_dir false intcmp scrut str strcmp true
build_dir:
# keep build/include until bindgen(1) has stdin support # keep build/include until bindgen(1) has stdin support
# https://github.com/rust-lang/rust-bindgen/issues/2703 # https://github.com/rust-lang/rust-bindgen/issues/2703
mkdir -p build/bin build/include build/lib build/o mkdir -p build/bin build/include build/o # build/lib
clean: clean:
rm -rf build/ rm -rf build/ dist/
install: build dist: all
mkdir -p $(PREFIX)/bin $(PREFIX)/lib mkdir -p \
mkdir -p $(PREFIX)/man/man1 $(PREFIX)/man/man3 dist/bin \
cp -f build/lib/*.so $(PREFIX)/lib/ dist/man/man1 \
cp -f build/bin/* $(PREFIX)/bin/ # dist/$(PREFIX)/lib \
cp -f docs/*.1 $(PREFIX)/man/man1/ # dist/$(PREFIX)/man/man3
cp -f docs/*.3 $(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)/
test: build test: build
tests/cc-compat.sh tests/cc-compat.sh
tests/posix-compat.sh tests/posix-compat.sh
sysexits: build_dir sysexits: build
# bandage solution until bindgen(1) gets stdin support # bandage solution until bindgen(1) gets stdin support
printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \ printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \
> build/include/sysexits.h > build/include/sysexits.h
bindgen --default-macro-constant-type signed --use-core \ bindgen --default-macro-constant-type signed --use-core --formatter=none \
"$$(printf '#include <sysexits.h>\n' \ "$$(printf '#include <sysexits.h>\n' \
| cpp -M -idirafter "build/include" - \ | cpp -M -idirafter "build/include" - \
| sed 's/ /\n/g' | grep sysexits.h)" \ | sed 's/ /\n/g' | grep sysexits.h)" \
| $(RUSTC) $(RUSTCFLAGS) --crate-type lib -o build/o/libsysexits.rlib - | $(RUSTC) $(RUSTCFLAGS) --crate-type lib -o build/o/libsysexits.rlib -
false: src/false.rs build_dir false: src/false.rs build
$(RUSTC) $(RUSTCFLAGS) -o build/bin/false src/false.rs $(RUSTC) $(RUSTCFLAGS) -o build/bin/false src/false.rs
fop: src/fop.rs build_dir sysexits fop: src/fop.rs build sysexits
$(RUSTC) $(RUSTCFLAGS) -o build/bin/fop src/fop.rs $(RUSTC) $(RUSTCFLAGS) -o build/bin/fop src/fop.rs
intcmp: src/intcmp.c build_dir intcmp: src/intcmp.c build
$(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c $(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c
scrut: src/scrut.c build_dir scrut: src/scrut.c build
$(CC) $(CFLAGS) -o build/bin/scrut src/scrut.c $(CC) $(CFLAGS) -o build/bin/scrut src/scrut.c
str: src/str.c build_dir str: src/str.c build
$(CC) $(CFLAGS) -o build/bin/str src/str.c $(CC) $(CFLAGS) -o build/bin/str src/str.c
strcmp: src/strcmp.c build_dir strcmp: src/strcmp.c build
$(CC) $(CFLAGS) -o build/bin/strcmp src/strcmp.c $(CC) $(CFLAGS) -o build/bin/strcmp src/strcmp.c
true: src/true.rs build_dir true: src/true.rs build
$(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs $(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs