From 49a3bb9f30a2d492b20420a504fe4e331eb9f0d0 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 15 Jan 2024 15:30:21 -0700 Subject: [PATCH] Makefile, .gitignore, .editorconfig, configure, tests/cc-compat.sh: added configure script for compiler optimizations --- .editorconfig | 3 +++ .gitignore | 1 + Makefile | 20 +++++++++----------- configure | 39 +++++++++++++++++++++++++++++++++++++++ tests/cc-compat.sh | 5 +++-- 5 files changed, 55 insertions(+), 13 deletions(-) create mode 100755 configure diff --git a/.editorconfig b/.editorconfig index 416f893..30fb7fc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,6 @@ end_of_line = lf indent_style = tab indent_size = 4 insert_final_newline = true + +[configure] +indent_size = 2 diff --git a/.gitignore b/.gitignore index edd9d60..3882502 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ dist/ +*.mk diff --git a/Makefile b/Makefile index 871b5ba..951044b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Emma Tebibyte +# Copyright (c) 2023–2024 Emma Tebibyte # Copyright (c) 2023 DTB # Copyright (c) 2023 Sasha Koshka # 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 diff --git a/configure b/configure new file mode 100755 index 0000000..eb1c8ae --- /dev/null +++ b/configure @@ -0,0 +1,39 @@ +#!/bin/sh + +# Copyright (c) 2023–2024 Emma Tebibyte +# 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 diff --git a/tests/cc-compat.sh b/tests/cc-compat.sh index f6f66ea..b5762c8 100755 --- a/tests/cc-compat.sh +++ b/tests/cc-compat.sh @@ -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