reflow

Преобликује пасусе у редове
git clone https://git.sr.ht/~strahinja/reflow
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 57136a65f21e87c285386608a745bcbfa77e0a95
родитељ 6be93bebfb0f7faf324b54a03d577a5d4af076db
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Thu, 19 Mar 2026 12:58:55 +0100

Synchronize build scripts with my other projects

Diffstat:
MINSTALL | 24++++++------------------
Aconfig.Haiku | 18++++++++++++++++++
Aconfig.Linux | 16++++++++++++++++
Aconfig.OpenBSD | 16++++++++++++++++
Dconfig.mk | 22----------------------
Mlib/makedate | 42+++++++++++++++++++++++++++++++++++++++---
Mlib/makeversion | 34+++++++++++++++++++++++++++++-----
измењених датотека: 7, додавања: 124(+), брисања: 48(-)

diff --git a/INSTALL b/INSTALL @@ -1,7 +1,7 @@ Prerequisites ============= -* C compiler - defaults in config.mk +* C compiler - defaults in config.mk (HaikuOS needs Clang/LLVM) Install @@ -9,6 +9,7 @@ Install $ git clone https://git.sr.ht/~strahinja/reflow $ cd reflow + $ cp config.$(uname -s) config.mk $ su # make install @@ -17,6 +18,7 @@ With got[1]: $ got clone https://git.sr.ht/~strahinja/reflow $ got checkout reflow.git $ cd reflow + $ cp config.$(uname -s) config.mk $ su # make install @@ -28,21 +30,7 @@ The file config.mk will be sourced when building targets which also accept configuration through environment variables. For example, CPPFLAGS and PREFIX are specified in config.mk. +Initially, there will be no config.mk, you will need to copy one of the +customized config.* files or write your own: -OpenBSD -------- - -Before running make(1), comment the CPPFLAGS definition in config.mk above the -line with the "OpenBSD" comment and uncomment the one below it: - - #CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \ - # -D_XOPEN_SOURCE=700 - # OpenBSD - CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \ - -D_XOPEN_SOURCE=700 -D_BSD_SOURCE - -Also, do the same for MANPREFIX: - - #MANPREFIX = $(DESTDIR)$(PREFIX)/share/man - # OpenBSD - MANPREFIX = $(DESTDIR)$(PREFIX)/man + $ cp config.$(uname -s) config.mk || echo Write config.mk from scratch diff --git a/config.Haiku b/config.Haiku @@ -0,0 +1,18 @@ +CC = clang +CFLAGS = -Os -Wextra -Wall -pedantic -std=c99 +CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \ + -D_XOPEN_SOURCE=700 -DNDEBUG +DESTDIR = /boot/home/config/non-packaged +INSTALL = install +LIBS = +SRC = reflow.c +HEADERS = defs.h +OBJS = reflow.o +PREFIX = +PROG = reflow + +# Derived macros +BINDIR = $(DESTDIR)$(PREFIX)/bin +DOCDIR = $(DESTDIR)$(PREFIX)/documentation/$(PROG) +MANPREFIX = $(DESTDIR)$(PREFIX)/documentation/man +MANPAGE = $(PROG).1 diff --git a/config.Linux b/config.Linux @@ -0,0 +1,16 @@ +CFLAGS = -Os -Wextra -Wall -pedantic -std=c99 +CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \ + -D_XOPEN_SOURCE=700 -DNDEBUG +INSTALL = install +LIBS = +SRC = reflow.c +HEADERS = defs.h +OBJS = reflow.o +PREFIX = /usr/local +PROG = reflow + +# Derived macros +BINDIR = $(DESTDIR)$(PREFIX)/bin +DOCDIR = $(DESTDIR)$(PREFIX)/share/doc/$(PROG) +MANPREFIX = $(DESTDIR)$(PREFIX)/share/man +MANPAGE = $(PROG).1 diff --git a/config.OpenBSD b/config.OpenBSD @@ -0,0 +1,16 @@ +CFLAGS = -Os -Wextra -Wall -pedantic -std=c99 +CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \ + -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -DNDEBUG +INSTALL = install +LIBS = +SRC = reflow.c +HEADERS = defs.h +OBJS = reflow.o +PREFIX = /usr/local +PROG = reflow + +# Derived macros +BINDIR = $(DESTDIR)$(PREFIX)/bin +DOCDIR = $(DESTDIR)$(PREFIX)/share/doc/$(PROG) +MANPREFIX = $(DESTDIR)$(PREFIX)/man +MANPAGE = $(PROG).1 diff --git a/config.mk b/config.mk @@ -1,22 +0,0 @@ -#CC = cc -CFLAGS = -Os -Wextra -Wall -pedantic -std=c99 -CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \ - -D_XOPEN_SOURCE=700 -DNDEBUG -# OpenBSD -#CPPFLAGS = -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \ -# -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -DNDEBUG -INSTALL = install -LIBS = -SRC = reflow.c -HEADERS = defs.h -OBJS = reflow.o -PREFIX = /usr/local -PROG = reflow - -# Derived macros -BINDIR = $(DESTDIR)$(PREFIX)/bin -DOCDIR = $(DESTDIR)$(PREFIX)/share/doc/$(PROG) -MANPREFIX = $(DESTDIR)$(PREFIX)/share/man -# OpenBSD -#MANPREFIX = $(DESTDIR)$(PREFIX)/man -MANPAGE = $(PROG).1 diff --git a/lib/makedate b/lib/makedate @@ -4,17 +4,53 @@ FALLBACKDATE=${FALLBACKDATE:-unknown} LC_ALL=C export LC_ALL +getent() +{ + geresult='' + if geresult=$(command getent "$@" 2>/dev/null); then + return + fi + case "$1" in + passwd|group) + if [ -z "$2" ]; then + geresult=$(cat /etc/"$1") + else + geresult=$(awk -F: -vu="$2" '{ if ($3 == u) print }' /etc/"$1") + fi + ;; + *) ;; + esac +} + if [ -d .got ] && command -v got >/dev/null 2>&1; then got log | awk ' /^date: / { sub(/^date: /,"",$0) - print $2 " " $3 ", " $5 + # Convert to proper form for `mandoc -Tlint` + month_names["Jan"] = "January" + month_names["Feb"] = "February" + month_names["Mar"] = "March" + month_names["Apr"] = "April" + month_names["May"] = "May" + month_names["Jun"] = "June" + month_names["Jul"] = "July" + month_names["Aug"] = "August" + month_names["Sep"] = "September" + month_names["Oct"] = "October" + month_names["Nov"] = "November" + month_names["Dec"] = "December" + print month_names[$2] " " $3 ", " $5 exit }' >date.new elif [ -d .git ] && command -v git >/dev/null 2>&1; then - user=$(unalias ls >/dev/null 2>&1 || true; \ - command ls -ld . | awk '{print $3}') + getent passwd "$(unalias ls >/dev/null 2>&1 || true; \ + command ls -nd . | awk '{print $3}')" + user=$(printf "%s\n" "$geresult" | awk -F: '{print $1}') + if [ -z "$user" ]; then + printf "$0: error: Cannot determine owner of %s" "$(pwd)" >&2 + exit 1 + fi e_user=$(id -un) if [ "$e_user" = "$user" ]; then git log --format=format:%cd \ diff --git a/lib/makeversion b/lib/makeversion @@ -2,15 +2,33 @@ # vim: set ft=bash: FALLBACKVER=${FALLBACKVER:-unknown} +getent() +{ + geresult='' + if geresult=$(command getent "$@" 2>/dev/null); then + return + fi + case "$1" in + passwd|group) + if [ -z "$2" ]; then + geresult=$(cat /etc/"$1") + else + geresult=$(awk -F: -vu="$2" '{ if ($3 == u) print }' /etc/"$1") + fi + ;; + *) ;; + esac +} + if [ -d .got ] && command -v got >/dev/null 2>&1; then lastcommit=$(got log | - awk '/^commit/ {print substr($2,1,9); exit}') + awk '/^commit/ {print substr($2,1,7); exit}') got tag -l | awk -v lastcommit="$lastcommit" ' /^object: commit/ { if (!lasttagcom) { - lasttagcom = substr($3,1,9) + lasttagcom = substr($3,1,7) } next } @@ -28,17 +46,23 @@ if [ -d .got ] && command -v got >/dev/null 2>&1; then { printf "-g%s", lastcommit } + printf "\n" }' >version.new elif [ -d .git ] && command -v git >/dev/null 2>&1; then LC_ALL=C export LC_ALL - user=$(unalias ls >/dev/null 2>&1 || true; \ - command ls -ld . | awk '{print $3}') + getent passwd "$(unalias ls >/dev/null 2>&1 || true; \ + command ls -nd . | awk '{print $3}')" + user=$(printf "%s\n" "$geresult" | awk -F: '{print $1}') + if [ -z "$user" ]; then + printf "$0: error: Cannot determine owner of %s" "$(pwd)" >&2 + exit 1 + fi e_user=$(id -un) if [ "$e_user" = "$user" ]; then git describe 2>/dev/null | sed 's/^v//' >version.new else - su "${user}" -c 'git describe' 2>/dev/null | + su "$user" -c 'git describe' 2>/dev/null | sed 's/^v//' >version.new fi else