Skip to content

Commit

Permalink
build: ksh93: some iffe and SHOPT.sh streamlining
Browse files Browse the repository at this point in the history
In ksh93/Mamfile there are four iffe invocations that don't run
a script but run one 'def' command directly from the iffe command
line. The 'def' command causes 8 probes to be run (per iffe --man):

    def name
          Equivalent to cmd,dat,hdr,key,lib,mth,sys,typ name.

This was quite inefficient as only one or two of them were used.

The process is streamlined by eliminating the individual iffe
invocations and adding only the probes whose results are actually
used to FEATURE/options (the test for sys/acct.h) and
FEATURE/externs (the rest).

The execargs.h probe and the code depending on it (in main.c) are
removed as this is only relevant for the PDP-11 (RIP, 1970-1997).

This commit also has a bugfix for SHOPT.sh processing in
ksh93/Mamfile. It was not effective to set SHOPT_GLOBCASEDET to 0
on systems where case-insensitive file systems are detected (e.g.
macOS). The fix is to include FEATURE/options in shopt.h after, not
before, the SHOPT.sh-based defines.
  • Loading branch information
McDutchie committed Jan 21, 2024
1 parent 9a3e86b commit 2ada957
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 45 deletions.
24 changes: 5 additions & 19 deletions src/cmd/ksh93/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ make install
exec - exec >shopt.h
exec - echo '/* Generated from ksh93/SHOPT.sh by ksh93/Mamfile */'
exec - echo
exec - echo '#include "FEATURE/options"'
exec - echo
exec - . "$PACKAGEROOT/src/cmd/ksh93/SHOPT.sh"
exec - ${STDCAT} <<-EOF
exec - #include "FEATURE/options"
exec -
exec - /* overrides */
exec - #if SHOPT_SCRIPTONLY
exec - # undef SHOPT_ACCT
Expand All @@ -99,6 +99,9 @@ make install
exec - # undef SHOPT_SYSRC
exec - # undef SHOPT_VSH
exec - #endif
exec - #if !_sys_acct
exec - # undef SHOPT_ACCT
exec - #endif
exec - EOF
done shopt.h generated
make pmain.o
Expand Down Expand Up @@ -269,10 +272,6 @@ make install
prev include/builtins.h
prev include/name.h
make include/path.h implicit
make FEATURE/acct implicit
prev Mamfile
exec - iffe ${IFFEFLAGS} -v -c "${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS}" ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdll} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libnsl} : def acct
done FEATURE/acct generated
prev include/defs.h
prev include/nval.h
done include/path.h
Expand Down Expand Up @@ -559,21 +558,8 @@ make install
done whence.o generated
make main.o
make sh/main.c
prev execargs.h implicit dontcare virtual
prev nc.h implicit dontcare virtual
prev FEATURE/externs
make FEATURE/execargs implicit
prev Mamfile
exec - iffe ${IFFEFLAGS} -v -c "${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS}" ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdll} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libnsl} : def execargs
done FEATURE/execargs generated
make FEATURE/pstat implicit
prev Mamfile
exec - iffe ${IFFEFLAGS} -v -c "${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS}" ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdll} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libnsl} : def pstat
done FEATURE/pstat generated
make FEATURE/setproctitle implicit
prev Mamfile
exec - iffe ${IFFEFLAGS} -v -c "${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS}" ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdll} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libnsl} : def setproctitle
done FEATURE/setproctitle generated
prev FEATURE/time
prev include/timeout.h implicit
prev include/history.h
Expand Down
11 changes: 7 additions & 4 deletions src/cmd/ksh93/features/externs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
hdr nc,exec_attr
hdr nc
mem exception.name,_exception.name math.h
lib setreuid,setregid,nice,fork,spawnveg,fchdir
lib pathnative,pathposix,fts_notify
lib setreuid,setregid,nice,fork,fchdir
lib pathnative,pathposix
lib memcntl sys/mman.h
lib getexecuser,free_execattr exec_attr.h -lsecdb

# for main.c fixargs():
lib,sys pstat
lib setproctitle

reference unistd.h

Expand Down
3 changes: 3 additions & 0 deletions src/cmd/ksh93/features/options
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ tst note{ can we probe file system case insensitivity }end output{
return !r;
}
}end

# for SHOPT_ACCT:
sys acct
7 changes: 1 addition & 6 deletions src/cmd/ksh93/include/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -118,15 +118,10 @@ extern const char is_ufunction[];
extern const char e_autoloadfrom[];

#if SHOPT_ACCT
# include "FEATURE/acct"
# ifdef _sys_acct
extern void sh_accinit(void);
extern void sh_accbegin(const char*);
extern void sh_accend(void);
extern void sh_accsusp(void);
# else
# undef SHOPT_ACCT
# endif /* _sys_acct */
#endif /* SHOPT_ACCT */

#endif /*! PATH_OFFSET */
19 changes: 3 additions & 16 deletions src/cmd/ksh93/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -40,9 +40,6 @@
#include "history.h"
#include "timeout.h"
#include "FEATURE/time"
#include "FEATURE/pstat"
#include "FEATURE/setproctitle"
#include "FEATURE/execargs"
#include "FEATURE/externs"
#ifdef _hdr_nc
# include <nc.h>
Expand Down Expand Up @@ -712,14 +709,8 @@ static void chkmail(char *files)
stkset(sh.stk,savstak,offset);
}

#undef EXECARGS
#undef PSTAT
#if defined(_hdr_execargs) && defined(pdp11)
# include <execargs.h>
# define EXECARGS 1
#endif

#if defined(_lib_pstat) && defined(_sys_pstat)
#if _lib_pstat && _sys_pstat
# include <sys/pstat.h>
# define PSTAT 1
#endif
Expand All @@ -738,11 +729,7 @@ static void chkmail(char *files)
*/
static void fixargs(char **argv, int mode)
{
# if EXECARGS
if(mode==0)
return;
*execargs=(char *)argv;
# elif PSTAT
# if PSTAT
char *cp;
int offset=0,size;
static int command_len;
Expand Down

0 comments on commit 2ada957

Please sign in to comment.