Skip to content

Commit

Permalink
more miscellaneous build system tweaks
Browse files Browse the repository at this point in the history
src/Mamfile:
- Avoid showing 'build done' announcement for the test target.

src/*/*/Mamfile, src/cmd/INIT/dylink.sh:
- Future-proof by using probe result for 'lib' prefix. Check for
  both 'dynamic' and 'shared' prefix/suffix result from mamprobe.
  This covers .dll files (in case we ever support them again).

src/cmd/INIT/mamake.c:
- loop: Use fseeko(3) and ftello(3) with an off_t variable if the
  POSIX version supports them. This may allow it to work on
  Mamfiles greater than 2 GiB. Our largest Mamfile is currently
  less than 90 KiB, so this is really just a pedantic correctness
  change to match the change to size_t variables (re: 1f86b28).
- When running the test target, announce 'testing', not 'making'.

src/cmd/INIT/README-mamake.md:
- Correct documentation of str=="*" in ${var?str?x?y?} expansion.
  • Loading branch information
McDutchie committed Jul 10, 2024
1 parent 1f86b28 commit 4d35de0
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 38 deletions.
24 changes: 12 additions & 12 deletions src/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ note *

setv MAMAKE_STRICT 3

make test virtual
make test_announce virtual
exec - : testing KornShell $KSH_VERSION :
make install virtual
make all virtual
exec - ${MAMAKE} -r '*/*' ${MAMAKEARGS}
done
make install virtual
make all virtual
exec - ${MAMAKE} -r '*/*' ${MAMAKEARGS}
done
make announce_build_done virtual notrace
prev cmd/ksh93/ksh
exec - ${<} -c 'print "# KornShell $KSH_VERSION"'
exec - echo "# Type 'bin/package use' to try it out"
done
make announce_build_done virtual notrace
prev cmd/ksh93/ksh
exec - ${<} -c 'print "# KornShell $KSH_VERSION"'
exec - echo "# Type 'bin/package use' to try it out"
done
done

make test virtual
exec - : testing KornShell $KSH_VERSION :
exec - ${MAMAKE} -r '*/*' ${MAMAKEARGS}
done
4 changes: 3 additions & 1 deletion src/cmd/INIT/README-mamake.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ avoiding any potential conflicts with the shell expansion syntax.
### Special expansion syntax ###

In `${`*variable*`?`*str*`?`*x*`?`*y*`?}`,
if the string value of the *variable* is identical to *str* or if *c* is `*`,
if the string value of the *variable* is identical to *str*,
then the value *x* is substituted, otherwise *y*.
A *str* of `*` is treated specially: if the *variable* is defined (even
as the empty string), then the value *x* is substituted, otherwise *y*.
The *x* and *y* values may result from nested variable references.
The last `?` is optional.

Expand Down
21 changes: 11 additions & 10 deletions src/cmd/INIT/dylink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ HIn) note "Building dynamic libraries was disabled; skipping"
esac

# Parse options.
exec_file= module_name= l_flags= version= suffix=
while getopts 'e:m:l:v:s:' opt
exec_file= module_name= l_flags= version= prefix= suffix=
while getopts 'e:m:l:v:p:s:' opt
do case $opt in
e) exec_file=$OPTARG ;;
m) module_name=$OPTARG ;;
l) l_flags="$l_flags -l$OPTARG" ;;
v) version=$OPTARG ;; # this should be like 6.0
p) prefix=$OPTARG ;; # this should be 'lib' or empty
s) suffix=$OPTARG ;; # this should be like .dylib or .so
'?') exit 2 ;;
*) err_out "Internal error (getopts)" ;;
Expand All @@ -76,10 +77,10 @@ case ${exec_file:+e}${module_name:+m} in
e | m) ;;
*) err_out "Either -e or -m should be specified" ;;
esac
case ${module_name:+m}${suffix:+s}${version:+v} in
'' | msv )
case ${module_name:+m}${prefix:+p}${suffix:+s}${version:+v} in
'' | mpsv )
;;
*) err_out "-m requires +v/-s and vice versa" ;;
*) err_out "-m requires -v/-p/-s and vice versa" ;;
esac

# Check for supported system.
Expand Down Expand Up @@ -111,14 +112,14 @@ case ${exec_file} in
'') # ... figure out library file name(s) and internal name for linking purposes
# on macOS we have version before extension (libast.6.0.dylib), on other systems, after (libast.so.6.0)
case $suffix in
.dylib) lib_file=lib$module_name.$version$suffix
lib_linkname=lib$module_name.${version%%.*}$suffix
.dylib) lib_file=$prefix$module_name.$version$suffix
lib_linkname=$prefix$module_name.${version%%.*}$suffix
;;
*) lib_file=lib$module_name$suffix.$version
lib_linkname=lib$module_name$suffix.${version%%.*}
*) lib_file=$prefix$module_name$suffix.$version
lib_linkname=$prefix$module_name$suffix.${version%%.*}
;;
esac
sym_links="$lib_linkname lib$module_name$suffix"
sym_links="$lib_linkname $prefix$module_name$suffix"
# ... remove possible old versions
(set +o noglob; exec rm -f "$dest_dir/lib/lib$module_name".*)
# ... execute linker command
Expand Down
21 changes: 15 additions & 6 deletions src/cmd/INIT/mamake.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* coded for portability
*/

#define RELEASE_DATE "2024-07-05"
#define RELEASE_DATE "2024-07-08"
static char id[] = "\n@(#)$Id: mamake (ksh 93u+m) " RELEASE_DATE " $\0\n";

#if _PACKAGE_ast
Expand Down Expand Up @@ -163,6 +163,13 @@ static const char usage[] =
#include <string.h>
#endif

/* backward compat for file offsets */
#if _POSIX_VERSION < 200112L
#define off_t long
#define fseeko fseek
#define ftello ftell
#endif

#define delimiter(c) (isspace(c)||(c)==';'||(c)=='('||(c)==')'||(c)=='`'||(c)=='|'||(c)=='&'||(c)=='=')

#define add(b,c) (((b)->nxt >= (b)->end) ? append(b, "") : NULL, *(b)->nxt++ = (c))
Expand Down Expand Up @@ -1967,15 +1974,15 @@ static unsigned long make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **

case KEY('l','o','o','p'):
{
long saveoff;
off_t saveoff;
char *vname, *words, *w, *nextw, *cp, *save_value;
Dict_item_t *vnode;
unsigned long saveline = state.sp->line;

if (!*v)
report(3, "syntax error", u, 0);
/* remember current offset for repeated reading */
if ((saveoff = ftell(state.sp->fp)) < 0)
if ((saveoff = ftello(state.sp->fp)) < 0)
report(3, "unseekable input", u, 0);
/* iterate through one or more whitespace-separated words */
vname = duplicate(expand(buf, t));
Expand All @@ -2000,7 +2007,7 @@ static unsigned long make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **
/* reposition input to the start of this loop block */
if (w != words)
{
if (fseek(state.sp->fp, saveoff, SEEK_SET) < 0)
if (fseeko(state.sp->fp, saveoff, SEEK_SET) < 0)
report(3, "fseek failed", u, 0);
state.sp->line = saveline;
}
Expand Down Expand Up @@ -2191,6 +2198,8 @@ static int update(Rule_t *r)
{
List_t *x;
Buf_t *buf;
char *args = getval(state.vars, "MAMAKEARGS");
int testing = !strcmp(args, "test");

/* topological sort */
r->flags |= RULE_made;
Expand All @@ -2214,7 +2223,7 @@ static int update(Rule_t *r)
q = getval(state.vars, "INSTALLROOT");
if (q && strncmp(p, q, n = strlen(q)) == 0)
p += n + 1;
fprintf(stderr, "\n# ... making %s ...\n", p);
fprintf(stderr, "\n# ... %sing %s ...\n", testing ? "test" : "mak", p);
if (state.explain)
fprintf(stderr, "# reason: recursion\n");
}
Expand All @@ -2225,7 +2234,7 @@ static int update(Rule_t *r)
append(buf, " -C ");
append(buf, r->name);
add(buf, ' ');
append(buf, getval(state.vars, "MAMAKEARGS"));
append(buf, args);
run(r, use(buf));
drop(buf);
return 0;
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/ksh93/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
setv IFFEFLAGS
setv LDFLAGS
setv SH_DICT \"libshell\"
setv DYLIB_PRE ${mam_cc_PREFIX_DYNAMIC-${mam_cc_PREFIX_SHARED}}
setv DYLIB_SUF ${mam_cc_SUFFIX_DYNAMIC-${mam_cc_SUFFIX_SHARED}}
setv DYLIB_VERSION 2.0

make install virtual
Expand Down Expand Up @@ -1239,11 +1241,11 @@ make install virtual
note * Dynamically linked version, if supported
note *

make ${INSTALLROOT}/dyn/lib/libshell${mam_cc_SUFFIX_SHARED} dontcare
make ${INSTALLROOT}/dyn/lib/${DYLIB_PRE}shell${DYLIB_SUF} dontcare
prev libshell.a
prev shell.req
exec - export LDFLAGS='${LDFLAGS} ${CCLDFLAGS} ${mam_cc_LD_NOASNEEDED}'
exec - dylink -m shell -v ${DYLIB_VERSION} -s ${mam_cc_SUFFIX_SHARED} $(sed 1d shell.req) ${_libshell_object_files_}
exec - dylink -m shell -v ${DYLIB_VERSION} -p '${DYLIB_PRE}' -s '${DYLIB_SUF}' $(sed 1d shell.req) ${_libshell_object_files_}
done

make ${INSTALLROOT}/dyn/bin/ksh dontcare
Expand Down
8 changes: 5 additions & 3 deletions src/lib/libast/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ setv CCFLAGS
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
setv IFFEFLAGS
setv LDFLAGS
setv DYLIB_PRE ${mam_cc_PREFIX_DYNAMIC-${mam_cc_PREFIX_SHARED}}
setv DYLIB_SUF ${mam_cc_SUFFIX_DYNAMIC-${mam_cc_SUFFIX_SHARED}}
setv DYLIB_VERSION 6.0

note *
Expand Down Expand Up @@ -4628,7 +4630,7 @@ make install virtual
prev include/ast.h
prev misc/univlib.h
done
exec - compile ${<} -Imisc -DCONF_LIBSUFFIX=\""${mam_cc_SUFFIX_DYNAMIC-${mam_cc_SUFFIX_SHARED}}"\" -DCONF_LIBPREFIX=\""${mam_cc_PREFIX_DYNAMIC-${mam_cc_PREFIX_SHARED}}"\" -DHOSTTYPE=\""${mam_cc_HOSTTYPE}"\"
exec - compile ${<} -Imisc -DCONF_LIBSUFFIX=\""${DYLIB_SUF}"\" -DCONF_LIBPREFIX=\""${DYLIB_PRE}"\" -DHOSTTYPE=\""${mam_cc_HOSTTYPE}"\"
done

make astdynamic.o
Expand Down Expand Up @@ -4928,11 +4930,11 @@ make install virtual
note * Dynamically linked version, if supported
note *

make ${INSTALLROOT}/dyn/lib/libast${mam_cc_SUFFIX_SHARED} dontcare
make ${INSTALLROOT}/dyn/lib/${DYLIB_PRE}ast${DYLIB_SUF} dontcare
prev libast.a
prev ast.req
exec - export LDFLAGS='${LDFLAGS} ${CCLDFLAGS} ${mam_cc_LD_NOASNEEDED}'
exec - dylink -m ast -v ${DYLIB_VERSION} -s ${mam_cc_SUFFIX_SHARED} $(sed 1d ast.req) ${_libast_object_files_}
exec - dylink -m ast -v ${DYLIB_VERSION} -p '${DYLIB_PRE}' -s '${DYLIB_SUF}' $(sed 1d ast.req) ${_libast_object_files_}
done

note *
Expand Down
6 changes: 4 additions & 2 deletions src/lib/libcmd/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ setv CCFLAGS
setv IFFEFLAGS
setv LDFLAGS
setv CCLDFLAGS
setv DYLIB_PRE ${mam_cc_PREFIX_DYNAMIC-${mam_cc_PREFIX_SHARED}}
setv DYLIB_SUF ${mam_cc_SUFFIX_DYNAMIC-${mam_cc_SUFFIX_SHARED}}
setv DYLIB_VERSION 2.0

make install virtual
Expand Down Expand Up @@ -492,11 +494,11 @@ make install virtual
note * Dynamically linked version, if supported
note *

make ${INSTALLROOT}/dyn/lib/libcmd${mam_cc_SUFFIX_SHARED} dontcare
make ${INSTALLROOT}/dyn/lib/${DYLIB_PRE}cmd${DYLIB_SUF} dontcare
prev libcmd.a
prev cmd.req
exec - export LDFLAGS='${LDFLAGS} ${CCLDFLAGS} ${mam_cc_LD_NOASNEEDED}'
exec - dylink -m cmd -v ${DYLIB_VERSION} -s ${mam_cc_SUFFIX_SHARED} $(sed 1d cmd.req) ${_libcmd_object_files_}
exec - dylink -m cmd -v ${DYLIB_VERSION} -p '${DYLIB_PRE}' -s '${DYLIB_SUF}' $(sed 1d cmd.req) ${_libcmd_object_files_}
done

note *
Expand Down
6 changes: 4 additions & 2 deletions src/lib/libdll/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ setv CCFLAGS
setv IFFEFLAGS
setv LDFLAGS
setv CCLDFLAGS
setv DYLIB_PRE ${mam_cc_PREFIX_DYNAMIC-${mam_cc_PREFIX_SHARED}}
setv DYLIB_SUF ${mam_cc_SUFFIX_DYNAMIC-${mam_cc_SUFFIX_SHARED}}
setv DYLIB_VERSION 2.0

make install virtual
Expand Down Expand Up @@ -195,11 +197,11 @@ make install virtual
note * Dynamically linked version, if supported
note *

make ${INSTALLROOT}/dyn/lib/libdll${mam_cc_SUFFIX_SHARED} dontcare
make ${INSTALLROOT}/dyn/lib/${DYLIB_PRE}dll${DYLIB_SUF} dontcare
prev libdll.a
prev dll.req
exec - export LDFLAGS='${LDFLAGS} ${CCLDFLAGS} ${mam_cc_LD_NOASNEEDED}'
exec - dylink -m dll -v ${DYLIB_VERSION} -s ${mam_cc_SUFFIX_SHARED} $(sed 1d dll.req) ${_libdll_object_files_}
exec - dylink -m dll -v ${DYLIB_VERSION} -p '${DYLIB_PRE}' -s '${DYLIB_SUF}' $(sed 1d dll.req) ${_libdll_object_files_}
done

note *
Expand Down

0 comments on commit 4d35de0

Please sign in to comment.