1
0
forked from bonsai/harakit

Merge branch 'makefile-fixes' (closes #29)

This commit is contained in:
Emma Tebibyte 2024-01-19 20:29:14 -07:00
commit 9095602296
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270
2 changed files with 62 additions and 43 deletions

View File

@ -1,5 +1,5 @@
# Copyright (c) 20232024 Emma Tebibyte <emma@tebibyte.media> # Copyright (c) 20232024 Emma Tebibyte <emma@tebibyte.media>
# Copyright (c) 2023 DTB <trinity@trinity.moe> # Copyright (c) 20232024 DTB <trinity@trinity.moe>
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media> # Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
# SPDX-License-Identifier: FSFAP # SPDX-License-Identifier: FSFAP
# #
@ -10,19 +10,15 @@
.POSIX: .POSIX:
.PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1) .PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1)
.PHONY: all
.PHONY: clean
.PHONY: install
.PHONY: test
PREFIX=/usr/local PREFIX=/usr/local
CC=cc CC=cc
RUSTC=rustc RUSTC=rustc
# to build, first run ./configure # to build, first run ./configure
include *.mk include cc.mk rustc.mk
.PHONY: all
all: dj false fop intcmp scrut str strcmp true all: dj false fop intcmp scrut str strcmp true
build: build:
@ -30,6 +26,7 @@ build:
# 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 build/test mkdir -p build/bin build/include build/lib build/o build/test
.PHONY: clean
clean: clean:
rm -rf build/ dist/ rm -rf build/ dist/
@ -38,10 +35,12 @@ dist: all
cp build/bin/* dist/bin/ cp build/bin/* dist/bin/
cp docs/*.1 dist/share/man/man1/ cp docs/*.1 dist/share/man/man1/
.PHONY: install
install: dist install: dist
mkdir -p $(PREFIX) mkdir -p $(PREFIX)
cp -r dist/* $(PREFIX)/ cp -r dist/* $(PREFIX)/
.PHONY: test
test: build test: build
tests/cc-compat.sh tests/cc-compat.sh
tests/posix-compat.sh tests/posix-compat.sh
@ -61,27 +60,43 @@ libgetopt: src/getopt-rs/lib.rs
$(RUSTC) $(RUSTCFLAGS) --crate-type=lib --crate-name=getopt \ $(RUSTC) $(RUSTCFLAGS) --crate-type=lib --crate-name=getopt \
-o build/o/libgetopt.rlib src/getopt-rs/lib.rs -o build/o/libgetopt.rlib src/getopt-rs/lib.rs
dj: src/dj.c build .PHONY: dj
$(CC) $(CFLAGS) -o build/bin/dj src/dj.c dj: build/bin/dj
build/bin/dj: src/dj.c build
$(CC) $(CFLAGS) -o $@ src/dj.c
false: src/false.c build .PHONY: false
$(CC) $(CFLAGS) -o build/bin/false src/false.c 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 \ $(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \
-o build/bin/fop src/fop.rs -o $@ src/fop.rs
intcmp: src/intcmp.c build .PHONY: intcmp
$(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c intcmp: build/bin/intcmp
build/bin/intcmp: src/intcmp.c build
$(CC) $(CFLAGS) -o $@ src/intcmp.c
scrut: src/scrut.c build .PHONY: scrut
$(CC) $(CFLAGS) -o build/bin/scrut src/scrut.c scrut: build/bin/scrut
build/bin/scrut: src/scrut.c build
$(CC) $(CFLAGS) -o $@ src/scrut.c
str: src/str.c build .PHONY: str
$(CC) $(CFLAGS) -o build/bin/str src/str.c str: build/bin/str
build/bin/str: src/str.c build
$(CC) $(CFLAGS) -o $@ src/str.c
strcmp: src/strcmp.c build .PHONY: strcmp
$(CC) $(CFLAGS) -o build/bin/strcmp src/strcmp.c strcmp: build/bin/strcmp
build/bin/strcmp: src/strcmp.c build
$(CC) $(CFLAGS) -o $@ src/strcmp.c
true: src/true.c build .PHONY: true
$(CC) $(CFLAGS) -o build/bin/true src/true.c true: build/bin/true
build/bin/true: src/true.c build
$(CC) $(CFLAGS) -o $@ src/true.c

44
configure vendored
View File

@ -14,26 +14,30 @@ RUSTFLAGS='-Copt-level=z -Ccodegen-units=1 -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'
case "$@" in if [ "$1" = "clean" ]; then
clang) rm *.mk || true
CFLAGS="$CFLAGS -Wall" exit 0
;; fi
clean)
rm *.mk || true while test -n "$1"; do
exit 0 case "$1" in
;; clang)
gcc) CFLAGS="$CFLAGS -Wall"
CFLAGS="$CFLAGS -s -Wl,-z,noseparate-code,-z,nosectionheader -flto" ;;
;; gcc)
'rustc +nightly') CFLAGS="$CFLAGS -s -Wl,-z,noseparate-code,-z,nosectionheader -flto"
RUSTFLAGS="+nightly -Zlocation-detail=none $RUSTFLAGS" ;;
;; 'rustc +nightly')
'') ;; RUSTFLAGS="+nightly -Zlocation-detail=none $RUSTFLAGS"
*) ;;
printf 'Usage: %s [compiler]\n' "$0" *)
exit 64 # sysexits.h(3) EX_USAGE printf 'Usage: %s [clean | compiler]\n' "$0"
;; exit 64 # sysexits.h(3) EX_USAGE
esac ;;
esac
shift
done
printf 'CFLAGS=%s\n' "$CFLAGS" >cc.mk printf 'CFLAGS=%s\n' "$CFLAGS" >cc.mk
printf 'RUSTFLAGS=%s\n' "$RUSTFLAGS" >rustc.mk printf 'RUSTFLAGS=%s\n' "$RUSTFLAGS" >rustc.mk