From c237af0e370b798463f2fb11c6b4906daba6499d Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 15 Jan 2024 23:54:42 -0700 Subject: [PATCH 1/4] Makefile: move PHONYs to their respective recipes --- Makefile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b7e7e5f..b47084e 100644 --- a/Makefile +++ b/Makefile @@ -10,11 +10,6 @@ .POSIX: .PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1) -.PHONY: all -.PHONY: clean -.PHONY: install -.PHONY: test - PREFIX=/usr/local CC=cc @@ -23,6 +18,7 @@ RUSTC=rustc # to build, first run ./configure include *.mk +.PHONY: all all: dj false fop intcmp scrut str strcmp true build: @@ -30,6 +26,7 @@ build: # https://github.com/rust-lang/rust-bindgen/issues/2703 mkdir -p build/bin build/include build/lib build/o build/test +.PHONY: clean clean: rm -rf build/ dist/ @@ -38,10 +35,12 @@ dist: all cp build/bin/* dist/bin/ cp docs/*.1 dist/share/man/man1/ +.PHONY: install install: dist mkdir -p $(PREFIX) cp -r dist/* $(PREFIX)/ +.PHONY: test test: build tests/cc-compat.sh tests/posix-compat.sh From a1b29bb6ed91bf43d49389bf97b5d6861d5d2a2a Mon Sep 17 00:00:00 2001 From: DTB Date: Tue, 16 Jan 2024 00:06:48 -0700 Subject: [PATCH 2/4] Makefile: fix PHONYness of existing recipes and make non-PHONY recipes --- Makefile | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index b47084e..083e262 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Copyright (c) 2023–2024 Emma Tebibyte -# Copyright (c) 2023 DTB +# Copyright (c) 2023–2024 DTB # Copyright (c) 2023 Sasha Koshka # SPDX-License-Identifier: FSFAP # @@ -60,27 +60,43 @@ libgetopt: src/getopt-rs/lib.rs $(RUSTC) $(RUSTCFLAGS) --crate-type=lib --crate-name=getopt \ -o build/o/libgetopt.rlib src/getopt-rs/lib.rs -dj: src/dj.c build - $(CC) $(CFLAGS) -o build/bin/dj src/dj.c +.PHONY: dj +dj: build/bin/dj +build/bin/dj: src/dj.c build + $(CC) $(CFLAGS) -o $@ src/dj.c -false: src/false.c build - $(CC) $(CFLAGS) -o build/bin/false src/false.c +.PHONY: false +false: build/bin/false +build/bin/false: src/false.c build + $(CC) $(CFLAGS) -o $@ src/false.c -fop: src/fop.rs build libgetopt sysexits +.PHONY: fop +fop: build/bin/fop +build/bin/fop: src/fop.rs build libgetopt sysexits $(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \ - -o build/bin/fop src/fop.rs + -o $@ src/fop.rs -intcmp: src/intcmp.c build - $(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c +.PHONY: intcmp +intcmp: build/bin/intcmp +build/bin/intcmp: src/intcmp.c build + $(CC) $(CFLAGS) -o $@ src/intcmp.c -scrut: src/scrut.c build - $(CC) $(CFLAGS) -o build/bin/scrut src/scrut.c +.PHONY: scrut +scrut: build/bin/scrut +build/bin/scrut: src/scrut.c build + $(CC) $(CFLAGS) -o $@ src/scrut.c -str: src/str.c build - $(CC) $(CFLAGS) -o build/bin/str src/str.c +.PHONY: str +str: build/bin/str +build/bin/str: src/str.c build + $(CC) $(CFLAGS) -o $@ src/str.c -strcmp: src/strcmp.c build - $(CC) $(CFLAGS) -o build/bin/strcmp src/strcmp.c +.PHONY: strcmp +strcmp: build/bin/strcmp +build/bin/strcmp: src/strcmp.c build + $(CC) $(CFLAGS) -o $@ src/strcmp.c -true: src/true.c build - $(CC) $(CFLAGS) -o build/bin/true src/true.c +.PHONY: true +true: build/bin/true +build/bin/true: src/true.c build + $(CC) $(CFLAGS) -o $@ src/true.c From f99cc797e66f0bcd152a43cefe8850d22fae2324 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 16 Jan 2024 16:43:00 -0700 Subject: [PATCH 3/4] Makefile: changed to be POSIX-compliant --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 083e262..61b67de 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ CC=cc RUSTC=rustc # to build, first run ./configure -include *.mk +include cc.mk rustc.mk .PHONY: all all: dj false fop intcmp scrut str strcmp true From 5e1749ca439e641e6389ed560a90350018d3c11d Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 16 Jan 2024 16:47:26 -0700 Subject: [PATCH 4/4] configure: now you can do multiple compilers! --- configure | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/configure b/configure index eb1c8ae..c710afb 100755 --- a/configure +++ b/configure @@ -14,26 +14,30 @@ RUSTFLAGS='-Copt-level=z -Ccodegen-units=1 -Cpanic=abort -Clto=y \ -Cstrip=symbols -Ctarget-cpu=native \ --extern sysexits=build/o/libsysexits.rlib' -case "$@" in - clang) - CFLAGS="$CFLAGS -Wall" - ;; - clean) - rm *.mk || true - exit 0 - ;; - gcc) - CFLAGS="$CFLAGS -s -Wl,-z,noseparate-code,-z,nosectionheader -flto" - ;; - 'rustc +nightly') - RUSTFLAGS="+nightly -Zlocation-detail=none $RUSTFLAGS" - ;; - '') ;; - *) - printf 'Usage: %s [compiler]\n' "$0" - exit 64 # sysexits.h(3) EX_USAGE - ;; -esac +if [ "$1" = "clean" ]; then + rm *.mk || true + exit 0 +fi + +while test -n "$1"; do + case "$1" in + clang) + CFLAGS="$CFLAGS -Wall" + ;; + gcc) + CFLAGS="$CFLAGS -s -Wl,-z,noseparate-code,-z,nosectionheader -flto" + ;; + 'rustc +nightly') + RUSTFLAGS="+nightly -Zlocation-detail=none $RUSTFLAGS" + ;; + *) + printf 'Usage: %s [clean | compiler]\n' "$0" + exit 64 # sysexits.h(3) EX_USAGE + ;; + esac + + shift +done printf 'CFLAGS=%s\n' "$CFLAGS" >cc.mk printf 'RUSTFLAGS=%s\n' "$RUSTFLAGS" >rustc.mk