From f201a586df776ae7ef5262bb9446869c4f54cec4 Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Wed, 24 May 2023 10:26:53 +0000 Subject: [PATCH] tweak nsh Makefile to support release and development builds The default 'make' target now behaves differently depending on whether we are building from the Git repository or from a release tarball. Data in nsh-version.mk controls the nsh version number (to be increased manually as needed) and the build type. In a distribution tarball the file nsh-version.mk will always contain NSH_RELEASE=Yes, which ensures that the default 'make' target will compile a release-style build out of the box. Builds from the Git repository now always contain debug symbols and are compiled without any compiler optimization flags, for proper backtracing and easy access to values of variables in gdb. Unlike release builds the debug builds report the suffix "-current" in their version number. Add a 'make release' target which generates a source distribution of nsh source code for consumption by the OpenBSD ports tree. This target uses the new files nsh-dist.txt and nsh-version.mk. When running 'make release' no uncommitted changes must exist in the work tree, and no unknown/unversioned files must be present, apart from any build artifacts removed by 'make clean'. The nsh-dist.txt file provides a sanity check for files included in the release tarball. If the list of packaged files changes then differences will be displayed, which must be reconciled by adding or removing lines from nsh-dist.txt as appropriate or by making sure that build artifacts or other temporary files are properly cleaned up by 'make clean' to prevent them from appearing in the distribution. The 'make release' must then be run again after removing the botched release tarball from disk and committing any local changes to nsh-dist.txt. --- Makefile | 27 +++++++++++++++++++++ externs.h | 9 +++++++ main.c | 2 +- nsh-dist.txt | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ nsh-version.mk | 12 ++++++++++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 nsh-dist.txt create mode 100644 nsh-version.mk diff --git a/Makefile b/Makefile index ac27f32..2e32eb3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,14 @@ # PROG= nsh +.PHONY: release dist + +.include "nsh-version.mk" + +.if ${NSH_RELEASE} != Yes +DEBUG?=-O0 -g +.endif + .if make(install) DESTDIR?=/usr/local BINDIR?=/bin @@ -11,6 +19,7 @@ MANDIR?=/man/man #CFLAGS=-O -DDHCPLEASES=\"/flash/dhcpd.leases\" -Wmissing-prototypes -Wformat -Wall -Wpointer-arith -Wbad-function-cast #-W CFLAGS?=-O CFLAGS+=-Wmissing-prototypes -Wformat -Wall -Wbad-function-cast -I/usr/local/include #-W -Wpointer-arith +CPPFLAGS+=-DNSH_VERSION=${NSH_VERSION} SRCS=arp.c compile.c main.c genget.c commands.c stats.c kroute.c SRCS+=ctl.c show.c if.c version.c route.c conf.c complete.c ieee80211.c @@ -25,4 +34,22 @@ MAN=nsh.8 compile.c: compile.sh sh ${.CURDIR}/compile.sh +release: clean + sed -i -e "s/_RELEASE=No/_RELEASE=Yes/" ${.CURDIR}/nsh-version.mk + ${MAKE} -C ${.CURDIR} dist + sed -i -e "s/_RELEASE=Yes/_RELEASE=No/" ${.CURDIR}/nsh-version.mk + +dist: clean + mkdir /tmp/nsh-${NSH_VERSION} + (cd ${.CURDIR} && pax -rw * /tmp/nsh-${NSH_VERSION}) + find /tmp/nsh-${NSH_VERSION} -name obj -type d -delete + rm /tmp/nsh-${NSH_VERSION}/nsh-dist.txt + tar -C /tmp -zcf ${.CURDIR}/nsh-${NSH_VERSION}.tar.gz nsh-${NSH_VERSION} + rm -rf /tmp/nsh-${NSH_VERSION} + tar -ztf ${.CURDIR}/nsh-${NSH_VERSION}.tar.gz | \ + sed -e 's/^nsh-${NSH_VERSION}//' | \ + sort > ${.CURDIR}/nsh-dist.txt.new + diff -u ${.CURDIR}/nsh-dist.txt ${.CURDIR}/nsh-dist.txt.new + rm ${.CURDIR}/nsh-dist.txt.new + .include diff --git a/externs.h b/externs.h index cc6533d..75755d4 100644 --- a/externs.h +++ b/externs.h @@ -2,6 +2,15 @@ * nsh externs, prototypes and macros */ +#ifndef NSH_VERSION +#error "NSH_VERSION is undefined" +#endif + +#define NSH_STRINGIFY_VERSION(x) #x +#define NSH_STRINGVAL_VERSION(x) NSH_STRINGIFY_VERSION(x) + +#define NSH_VERSION_STR NSH_STRINGVAL_VERSION(NSH_VERSION) + #define NO_ARG(x) (strcasecmp(x, "no") == 0) /* absolute "no" */ #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) /* sys/param.h */ diff --git a/main.c b/main.c index afe1459..5b1c31e 100644 --- a/main.c +++ b/main.c @@ -35,7 +35,7 @@ void usage(void); jmp_buf toplevel; -char *vers = "1.1"; +char *vers = NSH_VERSION_STR; int bridge = 0; /* bridge mode for interface() */ int verbose = 0; /* verbose mode */ int priv = 0, cli_rtable = 0; diff --git a/nsh-dist.txt b/nsh-dist.txt new file mode 100644 index 0000000..c6ecde6 --- /dev/null +++ b/nsh-dist.txt @@ -0,0 +1,65 @@ + +/COPYRIGHT +/MANUAL +/Makefile +/README +/TODO +/arp.c +/bridge.c +/bridge.h +/carp.c +/commands.c +/commands.h +/compile.sh +/complete.c +/conf.c +/ctl.c +/ctl.h +/editing.h +/externs.h +/genget.c +/ieee80211.c +/if.c +/ip.h +/kroute.c +/main.c +/media.c +/more.c +/nameserver.c +/ndp.c +/nopt.c +/nsh-scripts +/nsh-scripts/bin +/nsh-scripts/bin/enable-sshd.nshrc +/nsh-scripts/bin/initial-config.nshrc +/nsh-scripts/bin/mg-env-settings +/nsh-scripts/bin/nsh +/nsh-scripts/bin/nsh-openbsd-integration.sh +/nsh-scripts/bin/write-config.nshrc +/nsh-version.mk +/nsh.8 +/nwrapper.c +/passwd.c +/pflow.c +/pfsync.c +/ppp.c +/route.c +/save-ro.sh +/save-rw.sh +/show.c +/sqlite3.c +/stats.c +/stringlist.c +/stringlist.h +/sysctl.c +/sysctl.h +/test +/test/basic-show-run.nshrc +/test/broken-commands.nshrc +/trunk.c +/tunnel.c +/umb.c +/utils.c +/version.c +/wg.c +/who.c diff --git a/nsh-version.mk b/nsh-version.mk new file mode 100644 index 0000000..e4340eb --- /dev/null +++ b/nsh-version.mk @@ -0,0 +1,12 @@ +# NSH_RELEASE is only set to "Yes" in a release tarball +NSH_RELEASE=No + +# Version number of the next upcoming release. +# Should be cranked immediately after publishing a release. +NSH_VERSION_NUMBER=1.2 + +.if ${NSH_RELEASE} == Yes +NSH_VERSION=${NSH_VERSION_NUMBER} +.else +NSH_VERSION=${NSH_VERSION_NUMBER}-current +.endif