-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ability to link 3rd party code against libshell (re: f2bc1f4)
Over the course of developing ksh, the three public ksh/libshell interface headers (shell.h, nval.h, history.h), which should make it possible to embed the shell in third party programs by linking against libshell, got messed up so they are no longer suitable for public interface use. This commit fixes that, restoring this ability. src/cmd/ksh93/Mamfile: - Define _BLD_ksh=1 while building ksh. src/cmd/ksh93/include/{shell,nval,history}.h: - Compile out all non-public parts of the interface if _BLD_ksh is not defined. - Similarly hide ann internal #include directive based on _BLD_ksh. - Make most other checks for SHOPT_* shell options conditional upon _BLD_ksh being defined; if not, we're building a third-party program and the SHOPT_* macros aren't available, so just assume them to be on. src/cmd/INIT/dylink.sh: - While we're here, fix a minor omission in $prefix usage ('lib' was still hardcoded in one place). (re: 4d35de0) bin/package, src/cmd/INIT/Mamfile: - Set C_INCLUDE_PATH to $INSTALLROOT/include/ast for (at least) gcc and clang, allowing users to omit the corresponding -I flag while compiling against libast on the command line from the 'bin/package use' environment. - This invalidates some iffe regression tests that assume non-AST headers, so we have to unset it again before running those. ___________________________________________________________________ For reference, below is a little test program that demonstrates some aspects of writing a libshell program in C. Here are the manual pages needed to understand the program (the 'man' command will work with full path arguments on most systems): - src/lib/libast/man/LIBAST.3 - src/lib/libast/man/sfio.3 - src/lib/libast/man/cdt.3 - src/cmd/ksh93/shell.3 - src/cmd/ksh93/nval.3 Save as test.c, then build and run from the test environment: $ bin/package make -j3 # if not already done $ bin/package use $ cc test.c -l ast -l shell $ ./a.out ===begin test.c=== #include <shell.h> void myuserinit(Shell_t *shp, int reinit) { char *greet; NOT_USED(shp); if (reinit == 0) greet = "Hello"; else if (reinit > 0) greet = "Hi again"; else greet = "Bye"; sfprintf(sfstdout, "%s! reinit==%d\n", greet, reinit); } int main(int argc, char *argv[]) { Namval_t *np; sh_init(argc, argv, myuserinit); /* Write an introduction using a shell command */ sh_trap("print \"This is libshell ${.sh.version}\"", 0); /* Walk through the variables table and print all the * pre-set and inherited variables */ for(np = dtfirst(sh.var_tree); np; np = dtnext(sh.var_tree,np)) { sfprintf(sfstdout, " * %s == %s\n", nv_name(np), sh_fmtq(nv_getval(np))); } return 0; } ===end test.c===
- Loading branch information
Showing
8 changed files
with
72 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ command=${0##*/} | |
case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in | ||
0123) USAGE=$' | ||
[-? | ||
@(#)$Id: '$command$' (ksh 93u+m) 2024-08-16 $ | ||
@(#)$Id: '$command$' (ksh 93u+m) 2024-12-07 $ | ||
] | ||
[-author?Glenn Fowler <[email protected]>] | ||
[-author?Contributors to https://github.com/ksh93/ksh] | ||
|
@@ -564,7 +564,7 @@ SEE ALSO | |
pkgadd(1), pkgmk(1), rpm(1), sh(1), tar(1), optget(3) | ||
|
||
IMPLEMENTATION | ||
version package (ksh 93u+m) 2024-08-16 | ||
version package (ksh 93u+m) 2024-12-07 | ||
author Glenn Fowler <[email protected]> | ||
author Contributors to https://github.com/ksh93/ksh | ||
copyright (c) 1994-2012 AT&T Intellectual Property | ||
|
@@ -2080,7 +2080,7 @@ case $x in | |
$show _RLD_ROOT=$_RLD_ROOT | ||
$show export _RLD_ROOT | ||
export _RLD_ROOT | ||
# Haiku | ||
# dynamic library search path for gcc and clang; also used for runtime linking on Haiku | ||
case $LIBRARY_PATH: in | ||
$INSTALLROOT/dyn/lib:*) | ||
;; | ||
|
@@ -2090,6 +2090,16 @@ case $x in | |
export LIBRARY_PATH | ||
;; | ||
esac | ||
# include header search path for gcc and clang | ||
case $C_INCLUDE_PATH: in | ||
$INSTALLROOT/include/ast:*) | ||
;; | ||
*) C_INCLUDE_PATH=$INSTALLROOT/include/ast${C_INCLUDE_PATH:+:$C_INCLUDE_PATH} | ||
$show C_INCLUDE_PATH=$C_INCLUDE_PATH | ||
$show export C_INCLUDE_PATH | ||
export C_INCLUDE_PATH | ||
;; | ||
esac | ||
;; | ||
esac | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters