forked from bonsai/harakit
92 lines
2.6 KiB
Makefile
92 lines
2.6 KiB
Makefile
# Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media>
|
||
# Copyright (c) 2023 DTB <trinity@trinity.moe>
|
||
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
|
||
# 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.
|
||
|
||
# If we want to use POSIX make we can’t use ifeq
|
||
# .POSIX:
|
||
# .PRAGMA: posix_202x
|
||
.PHONY: clean
|
||
.PHONY: install
|
||
.PHONY: test
|
||
|
||
PREFIX=/usr/local
|
||
|
||
CC=cc
|
||
CFLAGS=-O3 -Lbuild/lib -idirafter include
|
||
|
||
RUSTC=rustc +nightly
|
||
RUSTCFLAGS=-Zlocation-detail=none -Copt-level=z -Ccodegen-units=1 \
|
||
-Cpanic=abort -Clto=y -Cstrip=symbols -Ctarget-cpu=native \
|
||
--extern sysexits=build/o/libsysexits.rlib
|
||
|
||
ifeq ($(CC), gcc)
|
||
CFLAGS=-O3 -s -Wl,-z,noseparate-code,-z,nosectionheader -flto -Lbuild/lib \
|
||
-idirafter include
|
||
endif
|
||
|
||
ifeq ($(CC), clang)
|
||
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
|
||
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
||
mkdir -p build/bin build/include build/lib build/o
|
||
|
||
clean:
|
||
rm -rf build/
|
||
|
||
install: build
|
||
mkdir -p $(PREFIX)/bin $(PREFIX)/lib
|
||
mkdir -p $(PREFIX)/man/man1 $(PREFIX)/man/man3
|
||
cp -f build/lib/*.so $(PREFIX)/lib/
|
||
cp -f build/bin/* $(PREFIX)/bin/
|
||
cp -f docs/*.1 $(PREFIX)/man/man1/
|
||
cp -f docs/*.3 $(PREFIX)/man/man3/
|
||
|
||
test: build
|
||
tests/cc-compat.sh
|
||
tests/posix-compat.sh
|
||
|
||
sysexits: build_dir
|
||
# bandage solution until bindgen(1) gets stdin support
|
||
printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \
|
||
> build/include/sysexits.h
|
||
bindgen --default-macro-constant-type signed --use-core \
|
||
"$$(printf '#include <sysexits.h>\n' \
|
||
| cpp -M -idirafter "$$PWD/build/include" - \
|
||
| sed 's/ /\n/g' | grep sysexits.h)" \
|
||
| $(RUSTC) $(RUSTCFLAGS) --crate-type lib -o build/o/libsysexits.rlib -
|
||
|
||
false: src/false.rs build_dir
|
||
$(RUSTC) $(RUSTCFLAGS) -o build/bin/false src/false.rs
|
||
|
||
fop: src/fop.rs build_dir sysexits
|
||
$(RUSTC) $(RUSTCFLAGS) -o build/bin/fop src/fop.rs
|
||
|
||
intcmp: src/intcmp.c build_dir
|
||
$(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c
|
||
|
||
scrut: src/scrut.c build_dir
|
||
$(CC) $(CFLAGS) -o build/bin/scrut src/scrut.c
|
||
|
||
str: src/str.c build_dir
|
||
$(CC) $(CFLAGS) -o build/bin/str src/str.c
|
||
|
||
strcmp: src/strcmp.c build_dir
|
||
$(CC) $(CFLAGS) -o build/bin/strcmp src/strcmp.c
|
||
|
||
true: src/true.rs build_dir
|
||
$(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs
|