1
0
forked from bonsai/harakit
coreutils/GNUmakefile

82 lines
2.3 KiB
Makefile
Raw Normal View History

# Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media>
# Copyright (c) 2023 DTB <trinity@trinity.moe>
2023-12-24 19:22:05 -07:00
# 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 cant use ifeq
# .POSIX:
# .PRAGMA: posix_202x
.PHONY: clean
.PHONY: install
.PHONY: test
PREFIX=/usr/local
2023-12-25 19:00:17 -07:00
CC=cc
CFLAGS=-O3 -Lbuild/lib -idirafter include
2023-12-25 19:00:17 -07:00
2023-12-26 12:35:41 -07:00
RUSTC=rustc +nightly
RUSTCFLAGS=-Zlocation-detail=none -Copt-level=z -Ccodegen-units=1 \
-Cpanic=abort -Clto=y -Cstrip=symbols -Ctarget-cpu=native \
-Clink-args=-Wl,-n,-N,--no-dynamic-linker,--no-pie,--build-id=none
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:
mkdir -p build/o build/lib build/bin build/test
clean:
rm -rf build/
install: build
2023-12-24 19:30:05 -07:00
mkdir -p $(PREFIX)/bin $(PREFIX)/lib
mkdir -p $(PREFIX)/share/man/man1 $(PREFIX)/share/man/man3
# cp -f build/lib/*.so $(PREFIX)/lib/
cp -f build/bin/* $(PREFIX)/bin/
cp -f docs/*.1 $(PREFIX)/share/man/man1/
# cp -f docs/*.3 $(PREFIX)/share/man/man3/
test: build_dir tests/cc-compat.sh tests/posix-compat.sh src/getopt-rs/tests.rs
tests/cc-compat.sh
tests/posix-compat.sh
$(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt
2023-12-25 17:11:34 -07:00
false: src/false.rs build_dir
2023-12-25 19:00:17 -07:00
$(RUSTC) $(RUSTCFLAGS) -o build/bin/false src/false.rs
intcmp: src/intcmp.c build_dir
$(CC) $(CFLAGS) -o build/bin/intcmp src/intcmp.c
2023-12-25 17:50:23 -07:00
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
2023-12-25 19:00:17 -07:00
true: src/true.rs build_dir
$(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs
libgetopt: src/getopt-rs/lib.rs
$(RUSTC) $(RUSTCFLAGS) --crate-type=lib --crate-name=getopt \
-o build/o/libgetopt.rlib src/lib.rs