Skip to content

Commit

Permalink
tweak nsh Makefile to support release and development builds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stspdotname committed May 24, 2023
1 parent 03d64e4 commit f201a58
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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 <bsd.prog.mk>
9 changes: 9 additions & 0 deletions externs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 65 additions & 0 deletions nsh-dist.txt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions nsh-version.mk
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f201a58

Please sign in to comment.