чување 02d7f808c2c7da49b9537326e4ff3436d64387ff
родитељ fc21ca894d3a6a63f4e185dc3d78f20b09f765be
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Thu, 19 Mar 2026 14:54:20 +0100
Synchronize build scripts from my other projects
Diffstat:
измењених датотека: 7, додавања: 132(+), брисања: 50(-)
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)
Testing
@@ -17,6 +17,7 @@ Install
$ git clone https://git.sr.ht/~strahinja/ufold
$ cd ufold
+ $ cp config.$(uname -s) config.mk
$ su
# make install
@@ -25,6 +26,7 @@ With got[1]:
$ got clone https://git.sr.ht/~strahinja/ufold
$ got checkout ufold.git
$ cd ufold
+ $ cp config.$(uname -s) config.mk
$ su
# make install
@@ -36,21 +38,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 = ufold.c utf8.c
+HEADERS = defs.h utf8.h version.h
+OBJS = ufold.o utf8.o
+PREFIX = /usr/local
+PROG = ufold
+
+# 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 = ufold.c utf8.c
+HEADERS = defs.h utf8.h version.h
+OBJS = ufold.o utf8.o
+PREFIX = /usr/local
+PROG = ufold
+
+# 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 = ufold.c utf8.c
+HEADERS = defs.h utf8.h version.h
+OBJS = ufold.o utf8.o
+PREFIX = /usr/local
+PROG = ufold
+
+# 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 -Wall -pedantic -std=c99
-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
-INSTALL = install
-LIBS =
-SRC = ufold.c utf8.c
-HEADERS = defs.h utf8.h version.h
-OBJS = ufold.o utf8.o
-PREFIX = /usr/local
-PROG = ufold
-
-# 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,7 +4,39 @@ FALLBACKDATE=${FALLBACKDATE:-unknown}
LC_ALL=C
export LC_ALL
-if [ -d .got ] && command -v got >/dev/null 2>&1; then
+die()
+{
+ printf "%s\n" "$@" >&2
+ exit 1
+}
+
+exists()
+{
+ command -v $* >/dev/null 2>&1
+}
+
+getent()
+{
+ geresult=''
+ if exists getent; then
+ geresult=$(command getent "$@" 2>/dev/null)
+ 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
+}
+
+exists diff || die "The build script $0 requires diff(1), none found"
+
+if [ -d .got ] && exists got; then
got log |
awk '
/^date: / {
@@ -25,9 +57,10 @@ if [ -d .got ] && command -v got >/dev/null 2>&1; then
print month_names[$2] " " $3 ", " $5
exit
}' >date.new
-elif [ -d .git ] && command -v git >/dev/null 2>&1; then
- user=$(getent passwd "$(unalias ls >/dev/null 2>&1 || true; \
- command ls -lnd . | awk '{print $3}')" | awk -F: '{print $1}')
+elif [ -d .git ] && exists git; then
+ 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
diff --git a/lib/makeversion b/lib/makeversion
@@ -1,8 +1,42 @@
#!/bin/sh -x
# vim: set ft=bash:
FALLBACKVER=${FALLBACKVER:-unknown}
+LC_ALL=C
+export LC_ALL
-if [ -d .got ] && command -v got >/dev/null 2>&1; then
+die()
+{
+ printf "%s\n" "$@" >&2
+ exit 1
+}
+
+exists()
+{
+ command -v $* >/dev/null 2>&1
+}
+
+getent()
+{
+ geresult=''
+ if exists getent; then
+ geresult=$(command getent "$@" 2>/dev/null)
+ 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
+}
+
+exists diff || die "The build script $0 requires diff(1), none found"
+
+if [ -d .got ] && exists got; then
lastcommit=$(got log |
awk '/^commit/ {print substr($2,1,7); exit}')
got tag -l |
@@ -30,11 +64,10 @@ if [ -d .got ] && command -v got >/dev/null 2>&1; then
}
printf "\n"
}' >version.new
-elif [ -d .git ] && command -v git >/dev/null 2>&1; then
- LC_ALL=C
- export LC_ALL
- user=$(getent passwd "$(unalias ls >/dev/null 2>&1 || true; \
- command ls -lnd . | awk '{print $3}')" | awk -F: '{print $1}')
+elif [ -d .git ] && exists git; then
+ 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