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) 2023 DTB <trinity@trinity.moe>
# Copyright (c) 20232024 DTB <trinity@trinity.moe>
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
# SPDX-License-Identifier: FSFAP
#
@ -10,19 +10,15 @@
.POSIX:
.PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1)
.PHONY: all
.PHONY: clean
.PHONY: install
.PHONY: test
PREFIX=/usr/local
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
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
@ -61,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

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 \
--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