Bug #3248 » 0001-sh-1-bring-sh-from-freebsd.patch
bin/sh/Makefile | ||
---|---|---|
# Makefile for /bin/sh
|
||
#
|
||
# @(#)Makefile 8.4 (Berkeley) 5/5/95
|
||
# $FreeBSD$
|
||
.include <src.opts.mk>
|
||
CONFGROUPS= ETC ROOT
|
||
ETC= profile
|
||
ROOT= dot.shrc dot.profile
|
||
ROOTDIR= /root
|
||
ROOTNAME_dot.shrc= .shrc
|
||
ROOTNAME_dot.profile= .profile
|
||
PACKAGE=runtime
|
||
PROG= sh
|
||
INSTALLFLAGS= -S
|
||
SHSRCS= alias.c arith_yacc.c arith_yylex.c cd.c echo.c error.c eval.c \
|
||
exec.c expand.c \
|
||
histedit.c input.c jobs.c kill.c mail.c main.c memalloc.c miscbltin.c \
|
||
mystring.c options.c output.c parser.c printf.c redir.c \
|
||
mystring.c options.c output.c parser.c printf.c redir.c show.c \
|
||
test.c trap.c var.c
|
||
GENSRCS= builtins.c nodes.c syntax.c
|
||
GENHDRS= builtins.h nodes.h syntax.h token.h
|
||
SRCS= ${SHSRCS} ${GENSRCS} ${GENHDRS}
|
||
# would be needed if WARNS upgraded to 3, but lets keep the stderr output
|
||
# clean, so WARNS has been lowered to 2.
|
||
#
|
||
WARNS?= 2
|
||
# MLINKS for Shell built in commands for which there are no userland
|
||
# utilities of the same name are handled with the associated manpage,
|
||
# builtin.1 in share/man/man1/.
|
||
LIBADD= edit
|
||
CFLAGS+=-DSHELL -I. -I${.CURDIR}
|
||
# for debug:
|
||
# DEBUG_FLAGS+= -g -DDEBUG=2 -fno-inline
|
||
# SHSRCS+=show.c
|
||
.if defined(BOOTSTRAPPING)
|
||
CFLAGS+= -DNO_HISTORY
|
||
# LIBEDIT is not needed here
|
||
.else
|
||
CFLAGS+= ${PRIVATELIB_CFLAGS}
|
||
DPADD= ${LIBEDIT} ${LIBNCURSES}
|
||
LDADD= ${LIBEDIT} ${LIBNCURSES}
|
||
.endif
|
||
.PATH: ${.CURDIR}/bltin \
|
||
${.CURDIR}/../kill \
|
||
${.CURDIR}/../test \
|
||
${.CURDIR}/../../usr.bin/printf
|
||
#
|
||
# NOTE: the headers and sources in pregenerated/ must be updated upon any
|
||
# changes to the nodetypes nodes.c.pat mkbuiltins mknodes.c mksyntax.c mktokens
|
||
# files using following scripts and build programs.
|
||
#
|
||
.if 1 # not updating sh(1)
|
||
.PATH: ${.CURDIR}/pregenerated
|
||
CFLAGS+= -I${.CURDIR}/pregenerated
|
||
.else
|
||
${.CURDIR:H}/kill \
|
||
${.CURDIR:H}/test \
|
||
${SRCTOP}/usr.bin/printf
|
||
CLEANFILES+= mknodes mksyntax
|
||
CLEANFILES+= ${GENSRCS} ${GENHDRS}
|
||
build-tools: mknodes mksyntax
|
||
.ORDER: builtins.c builtins.h
|
||
builtins.h: .NOMETA
|
||
builtins.c builtins.h: mkbuiltins builtins.def
|
||
sh ${.CURDIR}/mkbuiltins ${.CURDIR}
|
||
# XXX this is just to stop the default .c rule being used, so that the
|
||
# intermediate object has a fixed name.
|
||
# XXX we have a default .c rule, but no default .o rule.
|
||
.o:
|
||
${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
|
||
DEPENDOBJS+= mknodes mksyntax
|
||
mknodes mksyntax: ${BUILD_TOOLS_META}
|
||
.ORDER: nodes.c nodes.h
|
||
nodes.c nodes.h: nodetypes nodes.c.pat
|
||
${.OBJDIR}/mknodes/mknodes.nx ${.ALLSRC}
|
||
nodes.h: .NOMETA
|
||
nodes.c nodes.h: mknodes nodetypes nodes.c.pat
|
||
${BTOOLSPATH:U.}/mknodes ${.CURDIR}/nodetypes ${.CURDIR}/nodes.c.pat
|
||
.ORDER: syntax.c syntax.h
|
||
syntax.c syntax.h:
|
||
${.OBJDIR}/mksyntax/mksyntax.nx
|
||
syntax.h: .NOMETA
|
||
syntax.c syntax.h: mksyntax
|
||
${BTOOLSPATH:U.}/mksyntax
|
||
token.h: mktokens
|
||
sh ${.CURDIR}/mktokens
|
||
.endif
|
||
regress: sh
|
||
cd ${.CURDIR}/../../tools/regression/bin/sh && ${MAKE} SH=${.OBJDIR}/sh
|
||
HAS_TESTS=
|
||
SUBDIR.${MK_TESTS}+= tests
|
||
beforeinstallconfig:
|
||
rm -f ${DESTDIR}/.profile
|
||
afterinstallconfig:
|
||
${INSTALL_LINK} ${TAG_ARGS} ${DESTDIR}/root/.profile ${DESTDIR}/.profile
|
||
.include <bsd.prog.mk>
|
bin/sh/Makefile.depend | ||
---|---|---|
# $FreeBSD$
|
||
# Autogenerated - do NOT edit!
|
||
DIRDEPS = \
|
||
gnu/lib/csu \
|
||
include \
|
||
include/xlocale \
|
||
lib/${CSU_DIR} \
|
||
lib/libc \
|
||
lib/libcompiler_rt \
|
||
lib/libedit \
|
||
lib/ncurses/ncursesw \
|
||
.include <dirdeps.mk>
|
||
.if ${DEP_RELDIR} == ${_DEP_RELDIR}
|
||
# local dependencies - needed for -jN in clean tree
|
||
.endif
|
bin/sh/TOUR | ||
---|---|---|
program input files generates
|
||
------- ----------- ---------
|
||
mkbuiltins builtins builtins.h builtins.c
|
||
mkbuiltins builtins.def builtins.h builtins.c
|
||
mknodes nodetypes nodes.h nodes.c
|
||
mksyntax - syntax.h syntax.c
|
||
mktokens - token.h
|
||
... | ... | |
exceptions.c. The C language doesn't include exception handling,
|
||
so I implement it using setjmp and longjmp. The global variable
|
||
exception contains the type of exception. EXERROR is raised by
|
||
calling error. EXINT is an interrupt.
|
||
calling error or errorwithstatus. EXINT is an interrupt.
|
||
INTERRUPTS: In an interactive shell, an interrupt will cause an
|
||
EXINT exception to return to the main command loop. (Exception:
|
||
... | ... | |
word. The text consists of ordinary characters and a number of
|
||
special codes defined in parser.h. The special codes are:
|
||
CTLVAR Variable substitution
|
||
CTLENDVAR End of variable substitution
|
||
CTLVAR Parameter expansion
|
||
CTLENDVAR End of parameter expansion
|
||
CTLBACKQ Command substitution
|
||
CTLBACKQ|CTLQUOTE Command substitution inside double quotes
|
||
CTLARI Arithmetic expansion
|
||
CTLENDARI End of arithmetic expansion
|
||
CTLESC Escape next character
|
||
A variable substitution contains the following elements:
|
||
... | ... | |
VSQUESTION|VSNUL ${var:?text}
|
||
VSASSIGN ${var=text}
|
||
VSASSIGN|VSNUL ${var:=text}
|
||
VSTRIMLEFT ${var#text}
|
||
VSTRIMLEFTMAX ${var##text}
|
||
VSTRIMRIGHT ${var%text}
|
||
VSTRIMRIGHTMAX ${var%%text}
|
||
VSLENGTH ${#var}
|
||
VSERROR delayed error
|
||
In addition, the type field will have the VSQUOTE flag set if the
|
||
variable is enclosed in double quotes. The name of the variable
|
||
comes next, terminated by an equals sign. If the type is not
|
||
VSNORMAL, then the text field in the substitution follows, ter-
|
||
minated by a CTLENDVAR byte.
|
||
variable is enclosed in double quotes and the VSLINENO flag if
|
||
LINENO is being expanded (the parameter name is the decimal line
|
||
number). The parameter's name comes next, terminated by an equals
|
||
sign. If the type is not VSNORMAL (including when it is VSLENGTH),
|
||
then the text field in the substitution follows, terminated by a
|
||
CTLENDVAR byte.
|
||
The type VSERROR is used to allow parsing bad substitutions like
|
||
${var[7]} and generate an error when they are expanded.
|
||
Commands in back quotes are parsed and stored in a linked list.
|
||
The locations of these commands in the string are indicated by
|
||
CTLBACKQ and CTLBACKQ+CTLQUOTE characters, depending upon whether
|
||
the back quotes were enclosed in double quotes.
|
||
Arithmetic expansion starts with CTLARI and ends with CTLENDARI.
|
||
The character CTLESC escapes the next character, so that in case
|
||
any of the CTL characters mentioned above appear in the input,
|
||
they can be passed through transparently. CTLESC is also used to
|
||
... | ... | |
variable and command substitution, the parser doesn't insert any
|
||
CTLESC characters to begin with (so the contents of the text
|
||
field can be written without any processing). Other here docu-
|
||
ments, and words which are not subject to splitting and file name
|
||
generation, have the CTLESC characters removed during the vari-
|
||
able and command substitution phase. Words which are subject to
|
||
splitting and file name generation have the CTLESC characters re-
|
||
moved as part of the file name phase.
|
||
ments, and words which are not subject to file name generation,
|
||
have the CTLESC characters removed during the variable and command
|
||
substitution phase. Words which are subject to file name
|
||
generation have the CTLESC characters removed as part of the file
|
||
name phase.
|
||
EXECUTION: Command execution is handled by the following files:
|
||
eval.c The top level routines.
|
||
... | ... | |
The routine shellexec is the interface to the exec system call.
|
||
EXPAND.C: Arguments are processed in three passes. The first
|
||
(performed by the routine argstr) performs variable and command
|
||
substitution. The second (ifsbreakup) performs word splitting
|
||
and the third (expandmeta) performs file name generation.
|
||
EXPAND.C: As the routine argstr generates words by parameter
|
||
expansion, command substitution and arithmetic expansion, it
|
||
performs word splitting on the result. As each word is output,
|
||
the routine expandmeta performs file name generation (if enabled).
|
||
VAR.C: Variables are stored in a hash table. Probably we should
|
||
switch to extensible hashing. The variable name is stored in the
|
||
... | ... | |
tered throughout the code, depending on which location appears
|
||
most appropriate. They can be recognized because their names al-
|
||
ways end in "cmd". The mapping from names to procedures is
|
||
specified in the file builtins, which is processed by the mkbuilt-
|
||
ins command.
|
||
specified in the file builtins.def, which is processed by the
|
||
mkbuiltins command.
|
||
A builtin command is invoked with argc and argv set up like a
|
||
normal program. A builtin command is allowed to overwrite its
|
||
... | ... | |
ing. This is kind of like getopt, but you don't pass argc and
|
||
argv to it. Builtin routines can also call error. This routine
|
||
normally terminates the shell (or returns to the main command
|
||
loop if the shell is interactive), but when called from a builtin
|
||
command it causes the builtin command to terminate with an exit
|
||
status of 2.
|
||
loop if the shell is interactive), but when called from a non-
|
||
special builtin command it causes the builtin command to
|
||
terminate with an exit status of 2.
|
||
The directory bltins contains commands which can be compiled in-
|
||
dependently but can also be built into the shell for efficiency
|
||
reasons. The makefile in this directory compiles these programs
|
||
in the normal fashion (so that they can be run regardless of
|
||
whether the invoker is ash), but also creates a library named
|
||
bltinlib.a which can be linked with ash. The header file bltin.h
|
||
takes care of most of the differences between the ash and the
|
||
stand-alone environment. The user should call the main routine
|
||
"main", and #define main to be the name of the routine to use
|
||
when the program is linked into ash. This #define should appear
|
||
before bltin.h is included; bltin.h will #undef main if the pro-
|
||
gram is to be compiled stand-alone.
|
||
reasons. The header file bltin.h takes care of most of the
|
||
differences between the ash and the stand-alone environment.
|
||
The user should call the main routine "main", and #define main to
|
||
be the name of the routine to use when the program is linked into
|
||
ash. This #define should appear before bltin.h is included;
|
||
bltin.h will #undef main if the program is to be compiled
|
||
stand-alone. A similar approach is used for a few utilities from
|
||
bin and usr.bin.
|
||
CD.C: This file defines the cd and pwd builtins.
|
||
... | ... | |
When an interrupt is caught and no trap has been set for that
|