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

65 commits

Author SHA1 Message Date
Trey Valenta
c86713455c Fix typo "HOSTYPE" in package.sh documentation (#477)
This commit fixes typos in the documentation of:
-  src/cmd/INIT/package.sh: HOSTYPE is corrected as HOSTTYPE
2022-04-30 13:44:09 +02:00
Martijn Dekker
7b99b7cf04 Restore full 'bin/package test' functionality
package now uses mamake to run all available regression tests
(currently iffe, mamake and ksh93) instead of just the ksh tests.

However, as a consequence, passing options or other arguments to
the shtests script via bin/package is no longer possible -- run
bin/shtests directly for that.

src/Mamfile, src/*/Mamfile:
- Make the 'test' virtual target execute subdirectories by
  including the 'install' and 'all' virtual targets within it.

src/cmd/ksh93/Mamfile:
- Simplify and update the script in the 'test' virtual target.

src/cmd/builtin/Mamfile:
- Add dummy 'test' target to avoid an error.

bin/package, src/cmd/INIT/package.sh:
- Run 'mamake test' from the arch/*/src directory. This is the one
  that must be the initial working directory for mamake, though the
  Mamfiles aren't here; mamake finds them via the VPATH variable.
- Update self-doc.
2022-03-11 21:17:03 +01:00
Martijn Dekker
9c313c7fe3 Update copyright years in files changed since 1st Jan 2022 2022-01-30 20:49:04 +00:00
Martijn Dekker
41829efa06 Various minor cleanups and fixes
The more notable ones are:

src/lib/libast/features/standards:
- Do not redefine _GNU_SOURCE and _FILE_OFFSET_BITS if already
  defined from $CCFLAGS. Thanks to @hyanias for the heads-up.
  (re: 289dd46c)

src/cmd/ksh93/data/builtins.c,
src/cmd/ksh93/include/shell.h,
src/cmd/ksh93/sh/args.c,
src/cmd/ksh93/sh/name.c:
- Remove -T test code activation option. It was basically unused.
  The only thing it did was intentionally introduce a memory leak
  in table_unset() if the 4th bit in the option argument was set.
  A search in ast-open-history reveals a few more trivial test uses
  that were later deleted, but nothing interesting.

src/cmd/ksh93/tests/{basic,path}.sh:
- Skip a couple of tests on AIX avoid hangs, at least one of which
  is not ksh's fault. Thanks to @HansH111 for the report.

src/cmd/ksh93/tests/builtins.sh:
- Change one awk use to a more portable sed invocation to placate
  systems with ancient awk commands, such as AIX. (re: de795e1f)
2022-01-20 00:54:42 +00:00
Martijn Dekker
a1c613c48d package: more flat view fixes (re: 336e82f9, aeda3502)
bin/package, src/cmd/INIT/package.sh:
- Automatically update an existing flat view even if 'flat' wasn't
  given for a make action. This stops a flat view becoming
  inaccurate if you forget to use 'bin/package flat make'
  consistently. If the $PACKAGEROOT/lib/package/gen directory
  exists, an existing flat view is assumed.
- Correct symlink fallbacks. We need an absolute path for the
  symlink target or it's going to be broken.

.gitignore:
- Update.
2022-01-07 15:56:15 +00:00
Martijn Dekker
ecce82c3ca package: report 'failed' if build failed
bin/package, src/cmd/INIT/package.sh:
- Make the EXIT (0) trap report failure based on $error_status
  (see d18469d6), replacing 'done' with 'failed' if it is nonzero.
- Remove extra space before 'at' in that report line.
- If we get a signal, we have to set error_status to nonzero
  manually so that the correct exit message is printed.
2022-01-01 02:43:04 +00:00
Martijn Dekker
aeda350298 more package and iffe tweaks/cleanups
I've reconsidered excluding build system internals (and also '*.o'
files) from the flat view. Really the only thing that should be
excluded are *.old files.

bin/package, src/cmd/INIT/package.sh:
- Do not exclude anything except *.old files from the flat view.
- This would delete bin/package when cleaning up the flat view,
  so explicitly keep bin/package in the clean routine.
- Be much faster about updating an existing flat view by checking
  if a link already exists before creating one.
- Add silent cleanup for dozens of orphaned macOS *.dSYM bundles
  belonging to deleted temporary feature test executables.

src/cmd/INIT/{iffe,ignore,silent}.sh, bin/{ignore,silent}:
- Remove obsolete Bourne shell fallbacks.
- Modernise command substitutions.
- Remove unused literal() function.
- Update copy() function to use printf.
- Distinguish just two shell types now: ksh and POSIX.
- compile(): Remove obsolete/incorrect grepping for signal messages.
  Add a POSIX-compiliant check with 'kill -l' to see if the
  compiler was terminated by a signal.
2022-01-01 02:28:54 +00:00
Martijn Dekker
336e82f942 package: reintroduce/rewrite flat view (re: 20f8557c)
I called the flat view featuritis, but it turns out the dtksh build
system depends on it. But it was broken, so let's make a proper
version instead. This new approach does not symlink directories
before make, but hardlinks files after make. To make performance
tolerable, it requires a modern POSIX 'find' utility with '{} +'.

bin/package, src/cmd/INIT/package.sh:

- We're going to depend on 'test X -ef Y' to check if X is the same
  file as Y, so add that to the $min_posix checks even though it is
  not technically POSIX. But it's so close to universally available
  it doesn't really make a difference.

- After 'make', create a flat view by hardlinking arch/$HOSTTYPE
  files, minus build system internals, onto their corresponding
  paths in $PACKAGEROOT. Fall back to symlinking if hardlinking
  fails (this would happen when crossing device boundaries).

- Clean up flat view when doing clean/clobber. This is done by
  using 'find' to loop through the files in arch/ again and
  removing any root paths that are the same file as their
  corresponding arch/ path (this is where test X -ef Y comes in).
  Then delete arch/$HOSTTYPE, then delete empty directories left.

- Check for the 'flat' qualifier when doing clean/clobber. If
  given, do not delete arch/$HOSTTYPE but only clean up the flat
  view and remove empty directories.

src/cmd/INIT/Mamfile:
- Do not create the lib/package directory. (re: beb3c64a)

.gitignore:
- Update.
2022-01-01 02:28:38 +00:00
Martijn Dekker
a1f5c99204 INIT: remove proto, ratz (re: 46593a89, 6137b99a); major cleanup
This takes another step towards cleaning up the build system. We
now do not even pretend to be theoretically compatible with
pre-1989 K&R C compilers or with C++ compilers. In practice, this
had already been broken for many years due to bit rot.

Commit 46593a89 already removed the license handling enormity that
depended on proto, so now we can cleanly remove it altogether. But
we do need to leave some backwards compatibility stubs to keep the
build system compatible with older AST code; it should remain
possible to build older ksh versions with the current build system
(the bin/ and src/cmd/INIT/ directories) for testing purposes.

So as of now there is no more __MANGLE__d rubbish in your generated
header files. This is only about a quarter of a century overdue...

This commit also includes a huge amount of code cleanup to remove
thousands of unused K&R C fallbacks and other cruft, particularly
in libast. This code base should now be a little easier to
understand for people who are familiar with a modern(ish) C
standard.

ratz is now also removed; this was a standalone and simplified 2005
version of gunzip. As of 6137b99a, none of our code uses it, even
theoretically. And the real g(un)zip is now everywhere.

src/cmd/INIT/proto.c, src/cmd/INIT/ratz.c:
- Removed.

COPYRIGHT:
- Remove zlib license; this only applied to ratz.

bin/package, src/cmd/INIT/package.sh:
- Related cleanups.
- Unset LC_ALL before invoking a new shell, respecting the user's
  locale again and avoiding multibyte character corruption on the
  command line.

src/cmd/INIT/proto.sh:
- Add stub for backwards compatibility with Mamfiles that depend on
  proto. It does nothing but pass input without modification and is
  now installed as the new arch/*/bin/proto by src/cmd/INIT/Mamfile.

src/cmd/INIT/iffe.sh:
- Ignore the proto-related -e (--package) and -p (--prototyped)
  options; keep parsing them for backwards compatibility.
- Trim the macros passed to every test to their standard C
  versions, removing K&R C and C++ versions. These are now
  considered to be for backwards compatibility only.

src/cmd/INIT/iffe.tst:
- Remove proto(1) mangling code.
  By the way, iffe can be regression-tested as follows:
        $ bin/package use   # set up environment in a child shell
        $ regress src/cmd/INIT/iffe.tst
        $ exit              # leave package environment

src/cmd/INIT/make.probe, src/cmd/INIT/probe.win32:
- Remove code to handle C++.

src/lib/libast/features/common:
- As in iffe.sh above, trim macros designed for compatibility with
  C++ and ancient C compilers to their standard C versions and
  comment that they are for backwards compatibility with AST code.
  This is needed to keep all the old ast and ksh code compiling.

src/cmd/ksh93/sh/init.c,
src/cmd/ksh93/sh/name.c:
- Clarify libshell ABI compatibility function versions of macros.
  A "proto workaround" comment in the original code mislead me into
  thinking this had something to do with the removed proto(1), but
  it's unrelated. Call the workaround macro BYPASS_MACRO instead.

src/cmd/ksh93/include/defs.h:
- sh_sigcheck() macro: allow &sh as an argument: parenthesise shp.

src/cmd/ksh93/sh/nvtype.c:
- Remove unused nv_mkstruct() function. (re: d0a5cab1)

**/features/*:
- Remove obsolete iffe 'set prototyped' option.

**/Mamfile:
- Remove all references to the ast/prototyped.h header.
- Remove all use of the proto command. Simply copy instead.

*** 850-ish source files: ***
- Remove all '#pragma prototyped' directives.
- Remove all C++ compat code conditional upon defined(__cplusplus).
- Remove all use of the _ARG_ macro, which on standard C expands to
  its argument:
        #define _ARG_(x)        x
  (on K&R C, it expanded to nothing)
- Remove all use of _BEGIN_EXTERNS_ and _END_EXTERNS_ macros (empty
  on standard C; this was for C++ compatibility)
- Reduce all #if __STD_C (standard code) #else (K&R code) #endif
  blocks to the standard code only, without use of the macro.
- Same for _STD_ macro which seems to have had the same function.
- Change all instances of 'Void_t' to standard 'void'.
2021-12-24 07:05:22 +00:00
Martijn Dekker
0ead68b704 bin/package: fix 64-bit detection on systems without 'cc'
If the compiler is called gcc but not cc, the 64-bit detection
didn't work and $HOSTTYPE (and the arch/ subdirectory) did not get
the -64 suffix.

bin/package, src/cmd/INIT/package.sh:
- Run checkcc() before attempting to compile the program. This will
  set $cc to the path to gcc if there is no 'cc' command.
- trap: use 'rm -rf' to also delete .dSYM directories (macOS).
- checkcc(): Since we're here, find clang as well.
2021-12-21 07:11:44 +00:00
Martijn Dekker
69e0de9274 bin/package: more cleanups (re: 9166545a)
src/cmd/INIT/package.sh, bin/package:
- Derive the command name from $0 instead of hardcoding it.
- Remove NPROC and related code to support parallel building. This
  is not supported with mamake, is unlikely to be reintroduced any
  time soon, and if it ever is it will need to be done in a
  different way anwyay.
- Invoke 'sed' and 'tr' directly instead of via $SED and $TR
  variables. We're not building our own dynamically linked 'sed'
  and 'tr' in this distribution so LD_LIBRARY_PATH is irrelevant.
  If we ever do again, there are better ways to make sure the OS
  standard 'sed' and 'tr' are invoked than this kludge.
- Use note() consistently to print warnings to standard error.
  note() is changed to print each argument on a new line prefixed
  by the command name, so arguments need to be quoted now if they
  are to be shown on a single line.
- Use a new err_out() function to error out, avoiding code
  repetition.
2021-12-18 14:47:24 +00:00
Martijn Dekker
9166545aa3 bin/package: go POSIX
Yes, we're finally abandoning the old Bourne shell so we can
use sane $(command substitutions) and the like. POSIX sh (with
tolerance for shell bugs) is very highly portable these days.
Even Solaris 10 has a POSIX shell, though not as /bin/sh.

bin/package, src/cmd/INIT/package.sh:
- Be nice: if we're on an obsolete or broken shell, try hard to
  escape to a good one. This should preserve the possibility to
  just run 'bin/package make' via ancient /bin/sh on Solaris 10.
  - Note: zsh without sh emulation is considered broken because
    $path, which we use, is linked to $PATH. You have to run it via
    a symlink named sh or via 'zsh --emulate sh' to disable this.
    Enabling emulation mode after initialisation will not work.
- More self-documentation cleanups and updates.
- Regenerate the text-only fallback version of the self-doc.
- Remove flat view functionality (no arch directory); it may have
  been broken for some time, but quite frankly I could not care
  less. It's yet more featuritis. Building in arch/ is fine.
2021-12-16 09:08:20 +01:00
Martijn Dekker
7c30a59e25 package: allow 'tee' to catch up before returning (re: beb3c64a)
In the referenced commit message I neglected to mention that, when
doing bin/package make, we're now running 'tee' in the background
again and the building job in the foreground, as opposed to the
other way around. Foreground jobs are more reliably interruptable.
But that reintroduced the problem fixed in 5b8d29d3. Now I don't
know what I was thinking then -- the obvious fix is to add a 'wait'
command, allowing 'tee' to catch up before returning to the prompt.
2021-12-15 00:50:56 +01:00
Martijn Dekker
6137b99a6b package: remove a lot more unused AT&T cruft
This reduces the bin/package script by more than half!

bin/package, src/cmd/INIT/package.sh:
- Remove obsolete and unused package commands: admin, contents,
  license, list, remote, regress, setup, update, verify, write.
- Remove associated documentation.
- Replace install command with a dummy. It'll come back when we
  reintroduce the building of dynamic libaries.
- Update the test command to run the regression tests properly
  and capture the output in arch/*/lib/package/gen/tests.out, as
  documented. Arguments are simply passed to bin/shtests.

src/cmd/INIT/{ditto.sh,hurl.sh,release.c}:
- Removed. These were support scripts for some of the removed
  package commands.

src/cmd/ksh93/tests/pty.sh:
- Avoid failure when capturing output via 'bin/package test' by
  redirecting standard error to /dev/tty when running the tests.
2021-12-15 00:50:45 +01:00
Johnothan King
5084bef41f Fix buggy bin/package environment behavior (#377)
Running 'bin/package environment' should only show what will happen
during the build process, but in it's current state the feature has
some bugs:

1. Errors can occur relating to the failed creation of files and a
   failed attempt to change the directory. Various errors from
   'bin/package environment make' and 'bin/package environment make
   CC=tcc':
   bin/package[5632]: cd: /home/johno/GitRepos/KornShell/ksh/arch/linux.i386-64/lib/package/gen: [No such file or directory]
   bin/package: line 5869: /home/johno/GitRepos/KornShell/ksh/arch/linux.i386-64/lib/package/gen/CC: cannot create [No such file or directory]
   bin/package: line 5869: /home/johno/GitRepos/KornShell/ksh/arch/linux.i386-64/lib/package/gen/CCFLAGS: cannot create [No such file or directory]
   bin/package: line 5869: /home/johno/GitRepos/KornShell/ksh/arch/linux.i386-64/lib/package/gen/CCLDFLAGS: cannot create [No such file or directory]
   bin/package: line 5869: /home/johno/GitRepos/KornShell/ksh/arch/linux.i386-64/lib/package/gen/LDFLAGS: cannot create [No such file or directory]
   bin/package: line 5869: /home/johno/GitRepos/KornShell/ksh/arch/linux.i386-64/lib/package/gen/KSH_RELFLAGS: cannot create [No such file or directory]
   bin/package[5888]: /home/johno/GitRepos/KornShell/ksh/arch/linux.i386-64/lib/package/gen/host: cannot create [No such file or directory]

2. The package script may in some scenarios create a temporary file
   at the root of the repository, such as 'pkg77213.c'.

bin/package, src/cmd/INIT/package.sh:
- Avoid creating files or changing the directory while the
  environment qualifier is on (this also affects the debug
  qualifier). Part of this fix is based on a patch from Marcin
  Cieślak[*], with other fixes applied for similar problems the
  environment qualifier had.
2021-12-14 03:54:50 +01:00
Martijn Dekker
46593a89b7 Get rid of overcomplicated AT&T copyright/license maintenance code
I'm now taking another small step towards extricating this build
system from the long-dead AT&T AST universe.

This commit modifies/reduces the tool called proto. AT&T used proto
for two purposes:

  1. To convert ANSI C code to a form compatible with ancient
     (pre-ANSI) K&R C compilers using extremely complex macro
     voodo. It was similarly capable of translating to C++.
     Theoretically, this entire code base should compile on
     anything from a 1980s K&R C compiler to a modern C++ compiler.
     In practice, given the massive amount of bit rot we inherited,
     I am 99.9% sure that this has been broken for many years.

  2. To automagically insert license comments into source files
     based on an extremely complicated license database system.
     (In all-too-typical AT&T fashion, this second function of
     proto is completely unrelated to the first.)

Function 2 has now been removed because, unlike the AT&T legal
department, I don't think it's worth going to unspeakably extreme
lengths to avoid maintaining license information in source code
files by hand.

In the process, proto.c was cleaned up to look halfway like actual
C code, but it's still processed code: most macros have been
expanded to their numeric value, all comments were stripped, etc.
So don't expect to understand this code. The actual source code is
in these two directories in the ast-open-history repo:

https://github.com/ksh93/ast-open-history/tree/master/src/cmd/proto
https://github.com/ksh93/ast-open-history/tree/master/src/lib/libpp

Meanwhile, nobody wants to compile ksh with a pre-ANSI K&R C
compiler in 2021 -- and there's no good reason to be compatible
with C++ because standard C compilers are universally available.
So, proto will go away when I manage to figure out how to pry it
loose from the innards of this build system.

src/lib/libast/port/astlicense.c:
- Removed. This is al the license handling code that was
  incorporated in proto.c in stripped form. It was not used
  anywhere else, and the environment where it was useful is gone.

src/cmd/INIT/proto.c:
- Cleanup to make this halfway maintainable: indentation, huge
  blocks of empty lines, #line directives, etc.
- Delete all the code corresponding to astlicense.c. This was
  actually easy as it was in a discrete block.
- proto(), pppopen(): Remove 'license'/'notice' and 'options'
  arguments.
- main(): Remove processing of -l (license) and -o (license
  options) flags.

**/Mamfile:
- Update all the proto invocations to remove the -l and -o flags.

bin/package, src/cmd/INIT/package.sh:
- Delete the 'copyright' command, which used the -l and -o
  options to tell proto to extract copyright information from
  *.lic/*.def files in lib/package.

COPYRIGHT:
- Added. This has the information from 'bin/package copyright', with
  the copyright years corrected to plausible values as the AST code
  used the current year (2021) for all of them. It adds ksh 93u+m
  copyright and contributor information at the top as well.
     (Yes, some of the lines in the old non-AT&T copyright notices
  are clipped. This is the actual output of the 'bin/package
  copyright' command as generated by 'proto' in the AST
  distribution. For all that extreme complexity, they couldn't even
  reproduce the notices correctly. But it's officially sanctioned
  by AT&T in exactly this form, so there you have it.)

lib/package/**:
- Removed. All these files are now obsolete and redundant.
2021-12-14 03:15:16 +01:00
Johnothan King
e54001d58b Various minor capitalization and typo fixes (#371)
This commit fixes various minor typos, punctuation errors and
corrects the capitalization of many names.
2021-12-13 01:49:42 +01:00
Martijn Dekker
77c7de7cc7 package: fix Bourne compat (re: 48e6dd98)
Tried to compile on Solaris 10.1 for the first time in a while.
Turns out the obsolete Bourne /bin/sh does not support 'test -e'.

bin/package, src/cmd/INIT/package.sh:
- Use 'test -f' instead.
2021-11-17 06:09:35 +01:00
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
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