1
0
forked from bonsai/harakit

Makefile, .gitignore, .editorconfig, configure, tests/cc-compat.sh: added configure script for compiler optimizations

This commit is contained in:
Emma Tebibyte 2024-01-15 15:30:21 -07:00
parent 622c13021d
commit 49a3bb9f30
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270
5 changed files with 55 additions and 13 deletions

View File

@ -6,3 +6,6 @@ end_of_line = lf
indent_style = tab
indent_size = 4
insert_final_newline = true
[configure]
indent_size = 2

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
build/
dist/
*.mk

View File

@ -1,4 +1,4 @@
# Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media>
# Copyright (c) 20232024 Emma Tebibyte <emma@tebibyte.media>
# Copyright (c) 2023 DTB <trinity@trinity.moe>
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
# SPDX-License-Identifier: FSFAP
@ -18,19 +18,17 @@
PREFIX=/usr/local
CC=cc
CFLAGS=-O3 -Lbuild/lib -idirafter include
RUSTC=rustc
RUSTCFLAGS=-Copt-level=z -Ccodegen-units=1 -Cpanic=abort -Clto=y \
-Cstrip=symbols -Ctarget-cpu=native \
--extern sysexits=build/o/libsysexits.rlib
all: false fop intcmp scrut str strcmp true test
# to build, first run ./configure
include *.mk
all: false fop intcmp scrut str strcmp true
build:
# 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/o # build/lib
mkdir -p build/bin build/include build/o build/lib
clean:
rm -rf build/ dist/
@ -65,10 +63,10 @@ sysexits: build
| $(RUSTC) $(RUSTCFLAGS) --crate-type lib -o build/o/libsysexits.rlib -
false: src/false.rs build
$(RUSTC) $(RUSTCFLAGS) -o build/bin/false src/false.rs
$(RUSTC) $(RUSTFLAGS) -o build/bin/false src/false.rs
fop: src/fop.rs build sysexits
$(RUSTC) $(RUSTCFLAGS) -o build/bin/fop src/fop.rs
$(RUSTC) $(RUSTFLAGS) -o build/bin/fop src/fop.rs
intcmp: src/intcmp.c build
$(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c
@ -83,4 +81,4 @@ strcmp: src/strcmp.c build
$(CC) $(CFLAGS) -o build/bin/strcmp src/strcmp.c
true: src/true.rs build
$(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs
$(RUSTC) $(RUSTFLAGS) -o build/bin/true src/true.rs

39
configure vendored Executable file
View File

@ -0,0 +1,39 @@
#!/bin/sh
# Copyright (c) 20232024 Emma Tebibyte <emma@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.
set -e
CFLAGS='-Lbuild/lib -idirafter include -O3'
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
printf 'CFLAGS=%s\n' "$CFLAGS" >cc.mk
printf 'RUSTFLAGS=%s\n' "$RUSTFLAGS" >rustc.mk

View File

@ -9,18 +9,19 @@
set -e
if ! ls GNUmakefile >/dev/null 2>&1
if ! ls Makefile >/dev/null 2>&1
then
printf '%s: Run this script in the root of the project.\n' "$0" 1>&2
exit 64 # sysexits.h(3) EX_USAGE
fi
make clean
./configure clean
./configure
for CC in cc \
clang \
gcc \
tcc \
'zig cc'
do
export CC