logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 39c01fc1a04816c3774289865b455a4f21131e22
parent 733bb729d7a1e8a1a3241c229eac704ee27a7724
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed,  5 Feb 2025 04:17:26 +0100

bootstrap.sh: transform into bootstrap.mk

No more pre-generated files!

Diffstat:

MMakefile15++-------------
MREADME.md2+-
Dbootstrap-regen.sh43-------------------------------------------
Abootstrap.mk26++++++++++++++++++++++++++
Dbootstrap.sh27---------------------------
Acommon.mk12++++++++++++
6 files changed, 41 insertions(+), 84 deletions(-)

diff --git a/Makefile b/Makefile @@ -12,9 +12,6 @@ RM=rm all: $(EXE) $(MAN1SO) -bootstrap.sh: Makefile bootstrap-regen.sh - ./bootstrap-regen.sh - .c: $(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} $(CC) -std=c99 $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDSTATIC) @@ -23,6 +20,8 @@ bootstrap.sh: Makefile bootstrap-regen.sh $(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} $(CC) -std=c99 $(CFLAGS) -c -o $@ $< +include common.mk + # selfcheck: Check without extra dependencies .PHONY: selfcheck selfcheck: selfcheck-cmds selfcheck-libs @@ -104,16 +103,6 @@ cmd/seq: cmd/seq.c Makefile $(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} $(CC) -std=c99 $(CFLAGS) -o $@ cmd/seq.c -lm $(LDFLAGS) $(LDSTATIC) -# ./bootstrap.sh binaries should be kept simple -lib/fs.o: lib/fs.c lib/fs.h config.h -lib/err.o: lib/err.c lib/err.h -lib/consent.o: lib/consent.c lib/consent.h -lib/tr_str.o: lib/tr_str.c lib/tr_str.h -cmd/cat: cmd/cat.c lib/fs.o -cmd/printf: cmd/printf.c lib/err.o -cmd/rm: cmd/rm.c lib/consent.o -cmd/tr: cmd/tr.c lib/tr_str.o lib/err.o - cmd/chmod: cmd/chmod.c lib/utils.a cmd/chown: cmd/chown.c lib/utils.a cmd/date: cmd/date.c lib/utils.a diff --git a/README.md b/README.md @@ -22,7 +22,7 @@ Developed on Linux+musl, automatically tested on FreeBSD, NetBSD and ArchLinux t - The `./configure` script isn't auto*hell based, you can pass it arguments via key-value arguments or environment variables - You can define the `NO_BWRAP` environment variable to skip the bwrap-based tests which can cause issues in some environments like Gentoo `sandbox` - If you want statically linked executables, pass `LDSTATIC=-static` to configure (environment or argument) -- `./bootstrap.sh` will compile the few utilities used by `./configure` for you +- `make -f bootstrap.mk` will compile the few utilities used by `./configure` for you ## Cross-compiling Set the `CC` and `CFLAGS` environment variables for your target, the usual `CROSS_COMPILE` is also supported as a fallback. diff --git a/bootstrap-regen.sh b/bootstrap-regen.sh @@ -1,43 +0,0 @@ -#!/bin/sh -# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 - -# List of commands used by ./configure -# -# Can be checked with: -# $ strace -o configure.strace -f -e execve ./configure -# $ grep -F -e 'execve(' configure.strace | cut -f2 -d '"' | xargs -n1 basename | sort -u -#commands="cat echo grep printf rm sed test tr" -commands="cat echo printf rm test tr" -targets="$(printf 'cmd/%s ' $commands)" - -: ${MAKE:=make} - -$MAKE clean -( - printf '#!/bin/sh -# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 -# Generated using ./bootstrap-regen.sh -: ${CC:=cc} -: ${AR:=ar} -: ${YACC:=yacc} -: ${CFLAGS:=-Os -Wall} - -set -ex - -: >config.h - -' - $MAKE -n \ - CC='$$CC' CFLAGS='$$CFLAGS' \ - AR='$$AR' ARFLAGS='$$ARFLAGS' \ - LDFLAGS='$$LDFLAGS' LDSTATIC='$$LDSTATIC' \ - YACC='$$YACC' \ - $targets \ - | grep -vF -e .c.gcov -e 'make[1]:' - - printf " -./cmd/printf '\\nDone, you should now be able to run PATH=cmd/:\$PATH ./configure && make clean && make\\n' -" -)> bootstrap.sh diff --git a/bootstrap.mk b/bootstrap.mk @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +# Reduced Makefile dedicated to building executables for ./configure + +CC ?= cc + +# List of commands used by ./configure +# +# Can be checked with: +# $ strace -o configure.strace -f -e execve ./configure +# $ grep -F -e 'execve(' configure.strace | cut -f2 -d '"' | xargs -n1 basename | sort -u +#all: cmd/cat cmd/echo cmd/grep cmd/printf cmd/rm cmd/sed cmd/test cmd/tr +all: cmd/cat cmd/echo cmd/printf cmd/rm cmd/test cmd/tr + @./cmd/printf '%s\n' 'Done, you should now be able to run PATH=cmd/:$$PATH ./configure && make clean && make' + +config.h: + : >config.h + +.c: + $(CC) -std=c99 $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDSTATIC) + +.c.o: + $(CC) -std=c99 $(CFLAGS) -c -o $@ $< + +include common.mk diff --git a/bootstrap.sh b/bootstrap.sh @@ -1,27 +0,0 @@ -#!/bin/sh -# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 -# Generated using ./bootstrap-regen.sh -: ${CC:=cc} -: ${AR:=ar} -: ${YACC:=yacc} -: ${CFLAGS:=-Os -Wall} - -set -ex - -: >config.h - -$CC -std=c99 $CFLAGS -c -o lib/fs.o lib/fs.c -$CC -std=c99 $CFLAGS -o cmd/cat cmd/cat.c lib/fs.o $LDFLAGS $LDSTATIC -$CC -std=c99 $CFLAGS -o cmd/echo cmd/echo.c $LDFLAGS $LDSTATIC -$CC -std=c99 $CFLAGS -c -o lib/err.o lib/err.c -$CC -std=c99 $CFLAGS -o cmd/printf cmd/printf.c lib/err.o $LDFLAGS $LDSTATIC -$CC -std=c99 $CFLAGS -c -o lib/consent.o lib/consent.c -$CC -std=c99 $CFLAGS -o cmd/rm cmd/rm.c lib/consent.o $LDFLAGS $LDSTATIC -$CC -std=c99 $CFLAGS -o cmd/test cmd/test.c $LDFLAGS $LDSTATIC -$CC -std=c99 $CFLAGS -c -o lib/tr_str.o lib/tr_str.c -$CC -std=c99 $CFLAGS -o cmd/tr cmd/tr.c lib/tr_str.o lib/err.o $LDFLAGS $LDSTATIC - -./cmd/printf ' -Done, you should now be able to run PATH=cmd/:$PATH ./configure && make clean && make -' diff --git a/common.mk b/common.mk @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +# bootstrap.mk targets should be kept simple +lib/fs.o: lib/fs.c lib/fs.h config.h +lib/err.o: lib/err.c lib/err.h +lib/consent.o: lib/consent.c lib/consent.h +lib/tr_str.o: lib/tr_str.c lib/tr_str.h +cmd/cat: cmd/cat.c lib/fs.o +cmd/printf: cmd/printf.c lib/err.o +cmd/rm: cmd/rm.c lib/consent.o +cmd/tr: cmd/tr.c lib/tr_str.o lib/err.o