1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00
Commit graph

51 commits

Author SHA1 Message Date
Martijn Dekker
aa601a397d build system: do not look for nmake in $PATH
nmake was removed long ago (2940b3f5) and so were the outdated
Makefiles (6cc2f6a0). However, the build system still looked for an
AT&T nmake in $PATH. If a user had it installed, the build would
fail as the system tried to use it.

https://groups.google.com/g/korn-shell/c/2VK8kS0_VhA/m/-Rlnv7PRAgAJ

bin/package, src/cmd/INIT/package.sh:
- Remove all the code supporting nmake.
- Make 'bin/package test' work by simply exec'ing bin/shtests.

src/cmd/INIT/Mamfile:
- Do not install *.mk nmake support files.

lib/package/*.mk, src/cmd/INIT/*.mk:
- nmake support files removed.
2021-05-11 01:56:22 +02:00
Martijn Dekker
2aad3cab06 Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
Johnothan King
086d504393
Lots of man page fixes and some other minor fixes (#284)
Noteworthy changes:
- The man pages have been updated to fix a ton of instances of
  runaway underlining (this was done with `sed -i 's/\\f5/\\f3/g'`
  commands). This commit dramatically increased in size because
  of this change.
- The documentation for spawnveg(3) has been extended with
  information about its usage of posix_spawn(3) and vfork(2).
- The documentation for tmfmt(3) has been updated with the changes
  previously made to the man pages for the printf and date builtins
  (though the latter builtin is disabled by default).
- The shell's tracked alias tree (hash table) is now documented in
  the shell(3) man page.
- Removed the commented out regression test for an ERRNO variable
  as the COMPATIBILITY file states it was removed in ksh93.
2021-04-23 22:02:30 +01:00
Martijn Dekker
6b9a668f98 package: fix detection of 64-bit architectures
On some systems (such as Ubuntu on ARM), the output of `file`
contains a build hash, such as:

    SomeExecutable: ELF 32-bit LSB shared object, ARM, EABI5
    version 1 (SYSV), dynamically linked, interpreter
    /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0,
    BuildID[sha1]=8934dd61657aac875c190535066466849687a56b,
    not stripped

This build hash can contain the string '64', which caused package
to wrongly detect a 64-bit architecture.

bin/package, src/cmd/INIT/package.sh:
- Export LC_ALL=C to ensure 'file' output in English.
- To detect a 64-bit architecture, require the string "64-bit", "64
  bit" or "64bit" in 'file' output. The letters 'i' and 't' cannot
  occur in a hexadecimal hash, so hopefully that is safe enough. It
  is impossible to make this method completely safe, so in the long
  term it should be replaced.

Progresses: https://github.com/ksh93/ksh/issues/253
2021-04-07 01:28:17 +01:00
Martijn Dekker
48e6dd989c package: check for same compiler flags between build runs
I've had ksh crash one too many times when returning to a previous
build directory as I forgot to restore the previously-used CCFLAGS.

bin/package, src/cmd/INIT/package.sh:
- Save each of CC, CCFLAGS, CCLDFLAGS, LDFLAGS, KSH_RELFLAGS on the
  first build run. On subsequent runs, compare and refuse to run if
  they changed, issuing an informative error message.
- Allow override by exporting FORCE_FLAGS. Don't tell anyone :)
2021-03-19 14:59:32 +00:00
Martijn Dekker
82c6922330 package: fix SIGINT and SIGHUP handling
The package script was not well behaved with these. When you
pressed Ctrl+C, on some shells (including ksh) both the SIGINT (2)
and EXIT (0) traps are activated, showing a double 'make done'
message. The exit status also wasn't > 128 to indicate a signal.

bin/package, src/cmd/INIT/package.sh:
- Be UNIXly well-behaved. Signals should be passed on after
  handling, so when one is caught, make the trap handlers print
  their message and then unset both itself and EXIT/0 before
  resending the signal to self.
2021-03-17 10:09:57 +00:00
Martijn Dekker
5b8d29d358 package: don't exit prematurely (re: 3e140727, 936802f9, d18469d6)
Sometimes the shell returned to the prompt before bin/package was
finished writing all of its output. The problem was that 'tee',
which is used to write the output to both the terminal and the log
in arch/*lib/package/gen/make.out, hadn't caught up yet.

bin/package, src/cmd/INIT/package.sh:
- Run the build itself in the background and 'tee' in the
  foreground. This way, the script will not terminate until 'tee'
  is finished. The build's exit status is obtained with 'wait'.
2021-03-16 12:54:38 +00:00
sterlingjensen
e1690f61ff
package: Fix unspecified behavior after "unset PWD" (#176)
POSIX warns about "unset PWD" leading to unspecified behavior from
the pwd util, which we then use.

bin/package, src/cmd/INIT/package.sh:
- Determine if the shell has $PWD with a feature test. Only unset
  PWD if it does not (the old Bourne shell).
- Clean up 'case' flow.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
2021-02-20 13:58:52 +00:00
Martijn Dekker
dec10fee6a package: compat: no $PWD on Bourne shell (re: 6cc2f6a0, f5eaf217) 2021-02-12 15:21:38 +00:00
Martijn Dekker
43dfe3c8fa build system: rm unused variable declarations from Mamfiles
Now that the Make Abstract Machine files are maintained manually
and not generated automatically, unused variables are an annoying
distraction -- and there are many.

But the language/format is very simple and very parseable using
shell, awk, etc. -- so this was easy to automate. All variables are
declared with 'setv' and they are used if an expansion of the form
${varname} exists (the braces are mandatory in Mamfiles).

bin/Mamfile_rm_unused_vars:
- Added for reference and future use.

src/*/*/Mamfile:
- Remove all unused 'setv' variable declarations.
2021-02-05 15:39:31 +00:00
Martijn Dekker
f5eaf217ed build system: fix detection of default system directories
src/cmd/INIT/iffe.sh:
- Fix "standard system directories" for the cmd test, which were
  hardcoded as bin, /etc, /usr/bin, /usr/etc, /usr/ucb. That's both
  unportable and antiquated. Replace this with the path output by
  'getconf PATH'.
- Add fixes from modernish for 'getconf PATH' output to compensate
  for bugs/shortcomigns in NixOS and AIX. Source:
  https://github.com/modernish/modernish/blob/9e4bf5eb/lib/modernish/aux/defpath.sh
  Ref.: https://github.com/NixOS/nixpkgs/issues/65512

src/lib/libast/comp/conf.tab: PATH:
- Add the NixOS and AIX default path fixes here too; this fixes
  'command -p' and the builtin 'getconf PATH' on these systems.

bin/package, src/cmd/INIT/package.sh:
- Re-support being launched with just the command name 'package' in
  the command line (if the 'package' command is in $PATH). At least
  one other script in the build system does this. (re: 6cc2f6a0)
- Go back three levels (../../..) if we were invoked from
  arch/*/bin/package, otherwise we won't find src/cmd/ksh93/SHOPT.sh.
2021-02-03 17:49:00 +00:00
Martijn Dekker
ede479967f resolve/remove USAGE_LICENSE macros; remove repetitive (c) strings
This takes another small step towards disentangling the build
system from the old AT&T environment. The USAGE_LICENSE macros with
author and copyright information, which was formerly generated
dynamically for each file from a database, are eliminated and the
copyright/author information is instead inserted into the AST
getopt usage strings directly.

Repetitive license/copyright information is also removed from the
getopt strings in the builtin commands (src/lib/libcmd/*.c and
src/cmd/ksh93/data/builtins.c). There's no need to include 55
identical license/copyright strings in the ksh binary; one (in the
main ksh getopt string, shown by ksh --man) ought to be enough!
This makes the ksh binary about 10k smaller.

It does mean that something like 'enum --author', 'typeset
--license' or 'shift --copyright' will now not show those notices
for those builtins, but I doubt anyone will care.
2021-01-31 11:00:49 +00:00
Martijn Dekker
c2108888df bin/package: reallow building old ksh versions (re: 6cc2f6a0)
When building old code for debugging purposes (e.g. when doing 'git
bisect' runs), it's best to use the current build system even with
the old code, because the old build system was very broken. E.g.:

	git checkout (some old commit)
	git checkout master bin src/cmd/INIT # use new build system
	bin/package make

However, that became impossible in 6cc2f6a0 because the new
SHOPT.sh script was unconditionally sourced. The error caused the
script to exit because '.' is a special builtin.

bin/package, src/cmd/INIT/package.sh:
- If src/cmd/ksh93/SHOPT.sh doesn't exist, issue a warning instasd
  of trying to source it.
2021-01-23 14:42:52 +00:00
Martijn Dekker
6cc2f6a0af Build system: make SHOPT_* editable again; allow indenting Mamfiles
The build system is adapted to make SHOPT_* compile-time options
editable without nmake. We can now easily change ksh's compile-time
options by editing src/cmd/ksh93/SHOPT.sh. The bin/package script
is adapted to turn these into compile flags. This resolves the most
important drawback of not using nmake.

Also, mamake now has support for indented Mam (Make Abstract
Machine) code. Only one type of block (make...done) is supported in
Mamfiles, so they are easy to indent automatically. A script to
(re)do this is included.

Since nmake is not going to be restored (it has too many problems
that no one is interested in fixing), this at least makes mamake
significantly easier to work with.

The Makefiles are deleted. They may still be handy for reference to
understand the Mamfiles, but they haven't actually matched the
Mamfiles for a while -- and you can still look in the git history.

Deleting them requires some adaptations to bin/package and mamake.c
because, even though they do not use those files, they still looked
for them to decide whether to build code in a directory.

Finally, this commit incorporates some #pragmas for clang to
suppress annoying warnings about the coding style used in this
historic code base. (gcc does not complain so much.)

src/cmd/ksh93/SHOPT.sh:
- Added.

bin/package, src/cmd/INIT/package.sh:
- cd into our own directory in case we were run from another dir.
- $makefiles: only look for Mamfiles.
- Add ksh compile-options via KSH_SHOPTFLAGS. Include SHOPT.sh.
- make_recurse(): Do not write a missing Makefile.
- finalize environment: Look for Mamfiles instead of Makefiles.

src/cmd/INIT/mamake.c:
- Tell clang to suppress annoying warnings about coding style.
- Update version string and self-documentation.
- input(): Add support for indented Mam code by skipping initial
  whitespace on each input line.
- files[]: Instead of looking for various of Makefiles to decide
  where to build, only look for Mamfiles.

src/Makefile, src/cmd/INIT/Makefile, src/cmd/Makefile,
src/cmd/builtin/Makefile, src/cmd/ksh93/Makefile, src/lib/Makefile,
src/lib/libast/Makefile, src/lib/libcmd/Makefile,
src/lib/libdll/Makefile, src/lib/libsum/Makefile:
- Removed.

src/Mamfile, src/cmd/INIT/Mamfile, src/cmd/Mamfile,
src/cmd/builtin/Mamfile, src/cmd/ksh93/Mamfile, src/lib/Mamfile,
src/lib/libast/Mamfile, src/lib/libcmd/Mamfile,
src/lib/libdll/Mamfile, src/lib/libsum/Mamfile:
- Indent the code with tabs.
- In ksh93/Mamfile, add ${KSH_SHOPT_FLAGS} to every $CC command.
- In ksh93/Mamfile, add "prev SHOPT.sh" for every *.o file
  so they are rebuilt whenever SHOPT.sh changes.

bin/Mamfile_indent:
- Added, in case someone wants to re-indent a Mamfile.

src/cmd/INIT/proto.c, src/cmd/INIT/ratz.c, src/cmd/INIT/release.c,
src/lib/libast/features/common, src/lib/libast/include/ast.h:
- Tell clang to suppress annoying warnings about coding style that
  it disapproves of (mainly concerning the use of parentheses).

src/cmd/INIT/cc.darwin, src/cmd/INIT/cc.freebsd,
src/cmd/INIT/cc.openbsd:
- Remove now-redundant clang warning suppression flags.

Resolves: https://github.com/ksh93/ksh/issues/60
2021-01-22 23:39:59 +00:00
Martijn Dekker
7c7128e496 update bin/ scripts (re: 3b19944e) 2021-01-19 23:05:01 +00:00
Martijn Dekker
dd0d03b973 Eliminate LDFLAGS hack to compile on certain OSs
Instead, we now link to the libm system math library where needed
by adding -lm to the relevant compile commands in the Mamfiles.
This is not needed on every system but never does any harm.

(This adds more custom edits to the Mamfiles, which were originally
generated from the nmake Makefiles. This takes us further from
restoring nmake, but that already wasn't going to happen anyway,
due to its many problems... the path forward will be to translate
the Mamfiles to some other, current make system such as GNU make.)

bin/package, src/cmd/INIT/package.sh:
- Remove LDFLAGS=-lm hack for DragonFly BSD, NetBSD and Solaris.

src/cmd/builtin/Mamfile,
src/cmd/ksh93/Mamfile,
src/lib/libdll/Mamfile:
- Add -lm where linking failed on any of the three mentioned OSs.

src/lib/libdll/features/dll:
- In the output test program, add missing #include <math.h>, fixing
  unknown identifier errors on NetBSD (ldexp, ldexpl).

src/cmd/builtin/features/pty:
- Add missing #include <stdio.h> to make printf work on all systems
  (this is just a feature test, no need to bother with sfio here).

src/lib/libast/features/stdio:
- Undef __FILE_T to avoid interference from system headers on QNX.
  (There are still other problems preventing a build on QNX 6.5.0.
  The shipped version of gcc seems to be broken.)
2021-01-18 19:16:17 +00:00
Martijn Dekker
4dcf5c5066 Apply patches to build on DragonFly BSD and (older) FreeBSD
This now makes ksh build on DragonFly BSD.

bin/package, src/cmd/INIT/package.sh:
- DragonFly also needs the -lm hack for LDFLAGS.

src/cmd/ksh93/sh/main.c, src/cmd/ksh93/tests/basic.sh:
- fixargs() doesn't work on DragonFly either
  (re: 9b7c392a, 159fb9ee, cefe087d).

The following are backported from:
https://github.com/att/ast/issues/26#issuecomment-313927854
https://github.com/att/ast/pull/19

src/lib/libast/comp/setlocale.c:
- Add missing #include <errno.h> since errno is used.

src/lib/libast/features/standards:
- Do not set any standards macros (_POSIX_SOURCE etc) on FreeBSD or
  DragonflyBSD; they disable too much functionality on those.

src/lib/libast/features/wchar:
- Set _STDFILE_DECLARED on DragonFly, too.

src/lib/libast/include/sfio.h, src/lib/libast/include/sfio_t.h,
src/lib/libast/sfio/_sfopen.c, src/lib/libast/sfio/sfclrlock.c,
src/lib/libast/sfio/sfhdr.h, src/lib/libast/sfio/sfnew.c,
src/lib/libast/sfio/sfset.c:
- Rename SF_* macros to SFIO_* to avoid a conflict with system
  headers.

src/lib/libast/string/strexpr.c:
- Rename error() to err() to avoid a conflict.
2021-01-18 09:08:48 +00:00
Martijn Dekker
4cfe49aebb package: involve $CCFLAGS when determing 64-bit arch (re: 9a48ba15)
bin/package, src/cmd/INIT/package.sh:
- It can depend on the compiler flags passed whether the compiler
  produces code for a 64-bit architecture, so pass $CCFLAGS to
  the compiler when testing whether it creates 64-bit object code.

README.md:
- Copy-edit of build instructions.
2021-01-18 03:56:03 +00:00
Martijn Dekker
580ff61617 Fix release and standards build flags (re: 35672208, aa4669ad)
bin/package, src/cmd/INIT/package.sh:
- CCFLAGS overwrites the autodetected optimisation flags (e.g. -Os)
  if set. Unfortunately, that also happened when we added something
  to CCFLAGS for a release build or to add an extra flag needed by
  Solaris. The fix is to use a new flags variable (KSH_RELFLAGS)
  instead. This needs to be done in a different place as it needs
  to be added to the mamake command as an assignment argument.
- Remove the Solaris CCFLAGS hack; see features/common below.

src/*/*/Mamfile:
- Add ${KSH_RELFLAGS} to all the compiler commands.

src/lib/libast/features/common:
- Enable POSIX standard on Solaris (i.e.: if __sun is defined) by
  defining _XPG6 directly in the feature test that generates
  ast_std.h, which is indirectly included by everything. This
  removes the need to pass -D_XPG6 via CCFLAGS. (Doing so
  automatically with gcc was not otherwise possible.)

src/cmd/INIT/cc.sol11.*:
- No longer pass -D_XPG6, as per above.
2021-01-18 01:07:45 +00:00
Martijn Dekker
9a48ba1557 package: fix code for detecting 64-bit compiler
bin/package, src/cmd/INIT/package.sh:
- The code for detecting a 64-bit object file was seriously broken:
  the temporary file name could contain '64' because it included $$,
  the current PID, and 64-bit was detected if the output of 'file'
  (which includes the complete file name) contained '64'. Fix by
  removing the file name from 'file' output before testing.
- Also refactor that code a bit and remove the nonsensical test if
  /bin/sh is a 64-bit binary, which is neither here nor there. It's
  what the compiler produces that we need to care about.
2021-01-16 22:53:35 +00:00
Martijn Dekker
68a6f9a6e2 Fix Solaris cc wrappers (re: 4e67234a)
The versions from the Solaris patch require $CC_EXPLICIT to be set,
which is specific to the internal Solaris build environment.

src/cmd/INIT/cc.sol11.*:
- Cope without $CC_EXPLICIT set in environment; fall back to $CC
  and if that is not set either, detect whether to use cc or gcc.
- Set appropriate flags for cc (Solaris Studio) or gcc, including
  the necessary -D_XPG6 flag, without which ksh crashes on Solaris.

bin/package, src/cmd/INIT/package.sh:
- Update hack to add the -D_XPG6 flag so it applies to gcc only
  (note: the src/cmd/INIT/cc.* scripts are never used for gcc).
2021-01-16 19:25:39 +01:00
Martijn Dekker
e7202832fd Revert "bin/package: don't test-compile using possibly broken dev shell"
This reverts commit 600cb182.
$cc may be a system compiler binary, it is not necessarily a
src/cmd/INIT/cc.* wrapper script; so prefixing 'sh' is wrong.
2021-01-09 16:16:28 +00:00
Martijn Dekker
3567220898 New semantic versioning scheme; disable vmalloc in release builds
As of this commit, ksh 93u+m has a standard semantic version number
<https://semver.org/>, beginning with 1.0.0-alpha. This is added to
the version string in a way that should be compatible with scripts
parsing ${.sh.version} or $(ksh --version). This addition does not
replace the release date and does not affect $((.sh.version)).

For non-release builds, the version string will be:
	FORK/VERSION+HASH YYYY-MM-DD
e.g.:	93u+m/1.0.0-alpha+41ef7f76 2021-01-03

For release builds, it will be:
	FORK/VERSION YYYY-MM-DD
e.g.:	93u+m/1.0.0 2021-01-03

It is now automatically decided by bin/package whether to build a
release or development build. When building from a directory that
is not a git repository, or if the current git branch name starts
with a number (e.g. '1.0'), the release build is enabled; otherwise
a development build is the default. This is arranged by adding -D
flags to $CCFLAGS as described below. These flags are prepended to
$CCFLAGS, so they can be overridden by adding your own -D or -U
flags via the environment.

In addition, AST vmalloc is disabled for release builds as of this
commit, forcing the use of the OS's standard malloc(3). In 2021,
this is generally more reliable, faster, and more economical with
memory than AST vmalloc. Several memory leaks and crashing bugs are
avoided, e.g.: <https://github.com/ksh93/ksh/issues/95>.

For development builds, vmalloc stays enabled (along with its known
bugs) because this allows the use of the vmstat builtin, making it
much more efficient to test for memory leaks. For more info, see
the regression test script: src/cmd/ksh93/tests/leaks.sh

bin/package, src/cmd/INIT/package.sh:
- Add flags for build type. In $CCFLAGS, define _AST_ksh_release if
  we're not on any git branch or on a git branch whose name starts
  with a number. Otherwise, define _AST_git_commit as the first 8
  characters of the current git commit hash.

src/lib/libast/features/vmalloc:
- If _AST_ksh_release is defined, disable vmalloc and force use of
  the operating system's malloc. Discussion:
  https://github.com/ksh93/ksh/issues/95

src/cmd/ksh93/include/version.h:
- Define new format for version string, adding a semantic version
  number as well as (for non-release builds) the git commit hash.

src/cmd/ksh93/sh/init.c: e_version[]:
- Add a 'v' to the ${.sh.version} feature string if ksh was
  compiled with vmalloc enabled. This allows scripts, such as
  regression tests, to detect this.

src/cmd/ksh93/data/builtins.c: sh_optksh[]:
- Add a copyright line crediting the contributors to ksh 93u+m.

Resolves: https://github.com/ksh93/ksh/issues/95
2021-01-05 04:52:42 +00:00
Chase
cda1976e4c Properly clean and ignore flat make binaries and libs
bin/package, src/cmd/INIT/package.sh:
- When running bin/package flat make clean, also clean the flat
  hierarchy binaries.

.gitignore:
- Ignore flat hierarchy binaries.
2020-12-20 01:31:26 +00:00
Martijn Dekker
600cb182e3 bin/package: don't test-compile using possibly broken dev shell 2020-09-22 16:14:53 +02:00
Martijn Dekker
e08ca80d15 bin/package: do not use previously compiled shell
The package script searches for a good shell to run the build
scripts, preferring a ksh. But it also finds any recently compiled
development version of ksh in arch/*/bin that may be broken, or
have debug code, etc. -- and uses that in preference to anything
else. This is quite capable of breaking the build process.

The way to get around it is to do something like
	bin/package make SHELL=/bin/ksh
which is annoying to have to keep doing.

bin/package,
src/cmd/INIT/package.sh:
- When finding a good shell, use the saved user path ($path), not
  the current $PATH which includes arch/$HOSTTYPE/bin. Prefix this
  temporary path with `getconf PATH`, the system's default path,
  so that known-good system shells are found first.
2020-08-26 22:15:50 +01:00
Martijn Dekker
9b45f2ccbe build system: modernise shell compatibility checks
All changed files:
- Put the shell in POSIX mode if it has an '-o posix' option.
- Remove nonsense disabling 'set -x' on bash. It's not broken.

bin/package, src/cmd/INIT/package.sh:
- Add check blocking native zsh mode (e.g., "$path" conflicts).
  Using a 'sh -> zsh' symlink works, so recommend that.
- Remove old ksh93 version check for a supposed conflict with
  libcmd. It was broken; it would revert to /bin/sh, but on illumos
  distributions, /bin/sh is a ksh93 of a version that is supposedly
  affected. It builds fine anyway.
- Rewrite checksh() to incorporate the shell compatibility checks
  that were previously in two different places in 'package'.

bin/ignore, src/cmd/INIT/ignore.sh,
bin/silent, src/cmd/INIT/silent.sh:
- Change bad check for a full POSIX 'export' command (no, $RANDOM
  has nothing to do with that) with a proper feature test.
2020-08-23 23:41:31 +01:00
Martijn Dekker
52dc071a56 bin/package: fix a POSIX-ism (re: 3552a2ba)
The INIT scripts are supposed to be Bourne shell scripts, not
POSIX, so we can't use $( ... ) command substitutions.

bin/package,
src/cmd/INIT/package.sh:
- Change a POSIX command substitution to old-style backticks.
2020-08-20 22:49:46 +01:00
Martijn Dekker
07b240d4f9 src/cmd/INIT: allow compiling on system with noexec /tmp
Some systems disallow executing files in /tmp and there is nothing
regular users can do about it. The build would fail with a
misleading error message about cc being a cross-compiler.

This commit makes the build system consistently use $TMPDIR with
/tmp as a fallback if that variable is not defined. This allows the
user to use another temporary directory with execute permission.

The error message in bin/package is also extended to signal the
possibility of a noexec temp dir.
2020-08-03 23:52:41 +00:00
Martijn Dekker
aa4669ad17 Fix build on Solaris 11.4 (re: d3cd4cf)
It was working on Solaris 11.3, but there were still problems
building on Solaris 11.4 with GCC (as on the evaluation VM
downloaded directly from Oracle):
1. ksh immediately segfaulted. Experimenting with the compiler
   flags Oracle uses revealed that we need to define _XPG6 for ksh
   not to segfault. Why is a mystery.
2. The default path logic used by 'command -p' and the 'getconf
   PATH' builtin command was still broken: the result did not
   include any of the /usr/xpg?/bin directories where the standard
   POSIX utilities actually live. Testing shows that the result of
   the C language probe 'confstr(_CS_PATH,name,length)' is broken
   on Solaris (it only yields the paths to the historic
   non-standard utilities, defeating the purpose) unless _XPG7 is
   defined; but the latter makes ksh segfault again. So another
   solution is needed.

src/cmd/INIT/package.sh, bin/package:
- Add another hack to add the -D_XPG6 flag to CCFLAGS if we're
  running SunOS aka Solaris. (I've tried to add a 'cc.sol11' script
  to src/cmd/INIT/ instead, but for some reason that I just don't
  have time to figure out, the INIT system ignores that on Solaris
  with gcc, so this is the only way I could come up with. Any
  patches for less hacky alternatives would be welcome.)

src/lib/libast/comp/conf.sh:
- Sanitise the code for finding the best 'getconf' utility.

src/lib/libast/comp/conf.tab: PATH:
- Since the C-languge getconf(_CS_PATH,...) is broken on Solaris
  11.4, replace the C language probe with a shell script probe that
  uses the external 'getconf' utility.
- To avoid ksh overriding the result of this probe with the result
  of its own getconf(_CS_PATH,...) call, which would make Solaris
  use the wrong value again, specify this as an AST configuration
  entry instead of a POSIX entry. This should be good enough for
  all systems; the OS 'getconf' utility should be reliable and the
  default path value is constant for each OS, so can be hardcoded.

src/cmd/ksh93/tests/builtins.sh:
- Add another 'sleep .1' to the 'sleep -s 31' test as it was still
  intermittently failing on Solaris and possibly other systems.
2020-08-04 01:02:05 +02:00
Martijn Dekker
d3cd4cf906 Fixes to compile on Solaris variants, NetBSD, and NixOS
Solaris, Illumos distributions, and NetBSD need LDFLAGS set to link
explicitly to libm, otherwise, due to as-yet unknown reasons, the
src/lib/libdll/features/dll fails to write a valid header file and
compilation fails due to unknown identifiers such as Dllscan_t.
This commit adds the flag on those systems.

NixOS is a Linux distro that uses very different paths from the
usual Unix conventions (though it's POSIX compliant), and the
regression tests still needed a lot of tweaks to be compatible.

src/cmd/INIT/package.sh, bin/package:
- On SunOS (Solaris and illumos distros) and NetBSD, add '-lm' to
  LDFLAGS before compiling.

src/cmd/INIT/mamprobe.sh, bin/mamprobe,
src/cmd/INIT/execrate.sh, bin/execrate:
- Instead of only in /bin, /usr/bin, /sbin and /usr/sbin, search
  utilities in the path given by the OS 'getconf PATH', and use the
  user's original $PATH as a fallback.

src/cmd/ksh93/tests/*.sh:
- Miscellaneous portability fixes, mainly elimination of unportable
  hardcoded paths to commands.
- basic.sh: Remove test for 'time' keyword millisecond precision.
  It was racy and could fail depending on system and system load.
2020-08-03 09:24:16 +01:00
Johnothan King
05081dfc1c
Fix spurious creation of '=' file (#98)
The following is quoted from Marcin Cieślak [*]:
When running under FreeBSD /bin/sh (and not ksh) we get spurious
file named '=' created in the root. This is because the "checksh"
function runs /bin/sh -c '(( .sh.version >= 20111111 ))' which
produces a "=" file with /bin/sh as a side effect.

Fixes https://github.com/ksh93/ksh/issues/13

bin/package,
src/cmd/INIT/package.sh:
- Fix the creation of a spurious '=' file by making sure the shell
  has support for (( ... )) expressions.

.gitignore:
- Remove the '=' file entry since it no longer has a purpose.

[*]: https://bsd.network/@saper/103196289917156347
2020-07-27 13:27:20 +01:00
Johnothan King
af9c2144b8
Fix ./bin/package host cpu on FreeBSD (#99)
This bugfix is from Marcin Cieślak's fork of the INIT build
system. Before this bugfix, running 'bin/package host cpu'
on FreeBSD would always report one CPU core, even if the CPU
is multi-core:

$ ./bin/package host cpu
1

bin/package,
src/cmd/INIT/package.sh:
- Correctly report the number of CPUs on FreeBSD by using
  'sysctl -n hw.ncpu'.
2020-07-27 13:23:42 +01:00
Martijn Dekker
3613da4240 Remove unused libcoshell
The coshell(1) command, which is required for libcoshell to be
useful, is not known to be shipped by any distribution. It was
removed by the ksh-community fork and hence also by 93u+m (in
2940b3f5). The coshell facility as a whole is obsolete and
insecure. For a long time now, the statically linked libcoshell
library has been 40+ kilobytes of dead weight in the ksh binary.

Prior discussion (ksh2020): https://github.com/att/ast/issues/619

src/lib/libcoshell/*:
- Removed.

src/cmd/ksh93/*:
- Remove the SHOPT_COSHELL compiler option (which was enabled) and
  a lot of code that was conditional upon #ifdef SHOPT_COSHELL.

- init.c: e_version[]: Removing SHOPT_COSHELL changed the "J"
  feature identifier in ${.sh.version} to a lowercase "j", which
  was conditional upon SHOPT_BGX (background job extensions).
  But src/cmd/ksh93/RELEASE documents (at 08-12-04, on line 1188):
    | +SHOPT_BGX enables background job extensions. Noted by "J" in
    |  the version string when enabled. [...]
  That is the only available documentation. So change that "j" back
  to a "J", leaving the version string unchanged after this commit.

- jobs.c: job_walk(): We need to keep one 'job_waitsafe(SIGCHLD);'
  call that was conditional upon SHOPT_COSHELL; removing it caused
  a regression test failure in tests/sigchld.sh, 'SIGCHLD blocked
  for script at end of pipeline' (which means that until now, a ksh
  compiled without libcoshell had broken SIGCHLD handling.)

bin/package, src/cmd/INIT/package.sh:
- Don't export COSHELL variable.
2020-07-17 19:28:52 +01:00
Martijn Dekker
fbc6cd4286 Remove vestigial 3DFS support code (re: f88f302c)
Support for the long-dead 3DFS userland versioning file system was
already removed from ksh93 (although I'd overlooked some minor
things), but libast still supported it. This removes that too.

src/lib/libast/include/fs3d.h,
src/lib/libast/man/fs3d.3,
src/lib/libast/misc/fs3d.c:
- Removed.

bin/package,
src/cmd/INIT/package.sh:
- Remove attempted use of removed vpath builtin.

src/cmd/ksh93/*:
- Remove minor 3dfs vestiges.

src/lib/lib{ast,cmd,coshell}/*:
- Remove code supporting 3dfs.
2020-07-17 05:04:03 +01:00
Martijn Dekker
3e14072768 package.sh: clean up FIFO properly (re: 936802f9)
Not cleaning up the FIFO broke 'grep -r' in the arch directory,
making it hang forever. So we need a better way of cleaning it up.

bin/package,
src/cmd/INIT/package.sh:
- Unlink the FIFO early after sleeping a second in the background.
  This works because the named directory entry is only needed to
  establish the pipe, not to keep it going.
2020-06-30 04:45:02 +02:00
Martijn Dekker
f811482350 bin/shtests wrapper: export INSTALLROOT when using other ksh
When specifying another ksh to test using e.g. KSH=/bin/ksh to test
the system's stock ksh, the pty command was not found because it
resides in the arch/*/bin directory. The main shtests script bases
its $PATH on $INSTALLROOT, but does not set INSTALLROOT itself if
the shell to test is outside the installation hierarchy. Setting it
would allow the pty.sh regresssion tests to run on a shell
specified on the command line.

bin/shtests:
- Set and export INSTALLROOT to our default installation hierarchy
  if it wasn't already set on entry.
2020-06-26 12:22:25 +02:00
Anuradha Weeraman
54da7fc202
Fix 'bin/package clean' deleting entire git repo (#32)
This appears to be originating from:

2755         *)      if      test ! -d $INSTALLROOT
2756                 then    INSTALLROOT=$PACKAGEROOT;

where INSTALLROOT=PACKAGEROOT and 'clean' deletes everything under
INSTALLROOT thus deleting the entire git repo. This only applies when
there's no arch/$HOSTTYPE directory due to the condition above.

bin/package,
src/cmd/INIT/package.sh:
- Delete arch/$HOSTTYPE as stated in the documentation
  for the clean action instead of $INSTALLROOT.
2020-06-22 00:59:55 +01:00
Martijn Dekker
936802f92a Simplify exit status fix, restore interruptability
The exit status fix introduced in cherry-picked commit 22c3a6e1
introduced a problem: interrupting the build only interrupted the
main process, and the background job would happily continue.

bin/package, src/cmd/INIT/package.sh:
- Give up on the idea of a background job and put up with not
  cleaning up the FIFO. It's in a build directory that is going to
  get cleaned up anyway.
2020-06-12 02:11:46 +02:00
Martijn Dekker
7a8a46700c Build on more darwin/macOS versions
src/cmd/INIT/cc.darwin*:
- Build on ancient Mac OS X gcc versions (darwin 7+, Mac OS X
  10.3+), more recent gcc versions (darwin 11+, Mac OS X 10.7+), as
  well as current clang versions. So there are now three cc.darwin*
  wrapper scripts for these different darwin versions.

bin/package, src/cmd/INIT/package.sh:
- Differentiate the host ID and pick the correct Darwin script based on
  the detected OS release version.
2020-06-12 01:45:19 +02:00
Martijn Dekker
d18469d608 bin/package: exit with nonzero status on build failure
Build scripts and the like ought to be able to check the results of
the build using the exit status of the build command.

bin/package,
src/cmd/INIT/package.sh:
- Add global error_status variable to keep track of the highest
  exit status of all commands using capture(). Exit with that.
- capture():
  * When capturing build output using 'tee', change the regular
    pipe construct (which doesn't preserve the exit status of pipe
    elements except the last one) to a couple of background jobs
    connected with a FIFO (named pipe). This allows getting the
    build's exit status using the "wait" command.
  * Update error_status on every invocation of capture().

(cherry picked from commit 22c3a6e1b32f3ab7eeca45adb76863982dc3e334)
2020-06-12 01:45:17 +02:00
Johnothan King
22d6b4527d Avoid brute-forcing during the build process to prevent failed builds
The default behavior of the package script is to ignore
errors. This has disastrous effects if any part of ksh
or libast fails to build due to something like a syntax
error, as the build will stop long after the first error
occurred.

This commit removes the -k flag from the $makeflags variable
in both copies of the package script. This forces the build
to fail if a compiler error occurs.

bin/package and src/cmd/INIT/package.sh:
 - Remove the -k assignment to $makeflags so that compiler
   errors cause the build to fail.

(cherry picked from commit 87bfaa19f3d336feb7b7bd4f5d4caf8d553f2547)
2020-06-12 01:45:17 +02:00
Martijn Dekker
3552a2bafd Restore building on old Mac OS X (Darwin) with GCC (re: e74e98b8)
In making ksh build on new macOS, it stopped building on old Mac OS
X (old gcc-based Darwin). There is no real reason for this. We can
just restore the old cc wrapper script and use it if an old gcc
compiler is detected.

This is only tested on Mac OS X 10.3 on my old Power Mac G5 so far.
But at least that allows me to test fixes on that platform. Unusual
platforms sometimes expose corner case bugs...

bin/package, src/cmd/INIT/package.sh:
- If /usr/bin/cc is GCC, change 'darwin' host name to 'darwin_old'.
  This removes the long-obsolete 'darwin7' host name.

src/cmd/INIT/cc.darwin_old:
- Restore the old cc.darwin script for darwin_old hosts.

(cherry picked from commit 93d4c6497ea8e9cc9f4977b75d06a673a2229f80)
2020-06-12 01:45:15 +02:00
Martijn Dekker
e902633abe bin/shtests: fix SHELL=/path/to/ksh assignment argument
Passing a SHELL=/path/to/ksh assignment-argument after the
bin/shtest command (as documented in 'shtest --man') made the
wrapper script produce inconsistent results: it would launch and
claim to test the default shell, but src/cmd/ksh93/tests/shtests
would actually test the shell indicated in the argument.

bin/shtests:
- Scan arguments for a SHELL= (or KSH=) assignment-argument,
  setting $KSH (and then exporting $SHELL) based on that if found.

(cherry picked from commit 1e78fbbd094dfc84989ecadf06231c6515fb7412)
2020-06-12 01:45:14 +02:00
Martijn Dekker
2e7602da2a Add bin/shtests, convenient wrapper for regression tests
This new wrapper script sets up the correct environment for running
the ksh93 regression test suite. It allows running the tests
without AST nmake, which is not maintained in this repository.
An alternative ksh to test may be passed in the $KSH env var.

bin/shtests:
- Added. Sets up environment before passing control to
  'src/cmd/ksh93/tests/shtest'. Passes on any options given.

NEWS:
- Updated.

(cherry picked from commit 14ced94ed83991687c645a09bd2e45a5c2ffe8dc)
2020-06-12 01:45:13 +02:00
Martijn Dekker
e856094ca2 Fix build scripts so ksh compiles on recent macOS (Mac OS X)
This updates the cc.darwin* compiler compatibility wrapper scripts
and patches bin/package to identify a 64-bit system, allowing ksh
to build using a simple 'bin/package make' command on at least on
macOS Mojave (10.14.6). Testing on other macOS versions is invited.

src/cmd/INIT/cc.darwin:
- Remove obsolete compatibility cruft
- Update compiler flags:
  * remove obsolete/unneeded -DCLK_TCK=100 (this is already defined
    in the system header i386/limits.h included by time.h)
  * add necessary flags from Apple's Makefile in ksh-27.tar.gz:
    -DSHOPT_SPAWN=0 -D_ast_int8_t=int64_t -D_lib_memccpy
    source: https://opensource.apple.com/tarballs/ksh/
  * add -Wno-unused-value and -Wno-parentheses to suppress excessive
    clang warnings that object to David Korn's coding style.
- Update linker flags:
  * remove obsolete -Wl,-m
  * add flag from Apple's Makefile: -Wl,-search_paths_first

src/cmd/INIT/cc.darwin.i386,
src/cmd/INIT/cc.darwin.i386-64:
- Removed as superfluous (was identical to generic cc.darwin).

bin/package,
src/cmd/INIT/package.sh:
- Fix the recognition of a 64-bit system from the output of a 'file
  /bin/sh' command (what an ugly hack... never mind), so that the
  architecture is correctly identified as darwin.i386-64.

(cherry picked from commit e74e98b886a2bc5760166c124412474293f85fd8)
2020-06-12 01:45:13 +02:00
Martijn Dekker
39a14c1000 Fix 80 typos in comments
(cherry picked from commit 7dca902a85dc02e5df66f0f45a00d1575e7a0220)
2020-06-12 01:45:12 +02:00
Martijn Dekker
9c75314c71 Fix 181 typos in user-facing documentation
(cherry picked from commit fe365afb433bb39d4f3a6b68b3fd8e8daf5370c8)
2020-06-12 01:45:12 +02:00
Martijn Dekker
2940b3f536 Rebooting 93u+m
This commit reboots ksh 93u+m development with a new fork based off
the archived official AT&T ast repo, master branch.

README:
- Removed. Having two READMEs is a botch.

README.md:
- Imported and edited from the archived fork,
  https://github.com/modernish/ksh -- the newer instructions will
  become applicable as I cherry-pick all the changes from there :)
    - Copy-edits.
    - Added policy and rationale for this 93u+m fork.
    - Incorporated info from old README that is still relevant.

.gitignore:
- Added.

bin/execrate:
- Removed. This one keeps changing its license header, causing git
  to show an uncommitted file. It's always re-copied anyway, and
  not for direct invocation, so, exclude and add to .gitignore.
  The source file is: src/cmd/INIT/execrate.sh

src/cmd/*,
src/lib/*:
- Remove historical baggage: everything except ksh93 and
  dependencies. This is the same stuff the ksh-community fork
  removed. I wouldn't mind keeping it, but some of this stuff
  causes build failures on macOS (and probably other systems), and
  I need to get on with fixing ksh93.
     Hopefully, we can figure out how to re-add stuff we can use
  later -- particularly the pty command (pseudo-terminal utility
  for scripting interactive sessions) which is needed for
  regression-testing the interactive shell.
2020-06-12 01:43:13 +02:00
Lefteris Koutsofios
0b36868c8c - added code to install an 'ar' script which appends the U flag to the first
argument. the semantics for ar were changed to zero out the timestamp of
  each module. nmake relies on the timestamp to tell if the module has changed

- added modified 'cc' scripts for linux to add the -P flag. modern gcc's put
  # lines that confuse nmake

- changed make.probe script to drop -nostartfiles for gcc >= 7.0
2020-02-12 12:46:56 -05:00