1 | # $Id: Makefile.kmk 3477 2020-09-17 21:52:16Z bird $
|
---|
2 | ## @file
|
---|
3 | # Sub-makefile for kash.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (c) 2005-2020 knut st. osmundsen <[email protected]>
|
---|
8 | #
|
---|
9 | # This file is part of kBuild.
|
---|
10 | #
|
---|
11 | # kBuild is free software; you can redistribute it and/or modify
|
---|
12 | # it under the terms of the GNU General Public License as published by
|
---|
13 | # the Free Software Foundation; either version 3 of the License, or
|
---|
14 | # (at your option) any later version.
|
---|
15 | #
|
---|
16 | # kBuild is distributed in the hope that it will be useful,
|
---|
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | # GNU General Public License for more details.
|
---|
20 | #
|
---|
21 | # You should have received a copy of the GNU General Public License
|
---|
22 | # along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
---|
23 | #
|
---|
24 | #
|
---|
25 |
|
---|
26 | SUB_DEPTH = ../..
|
---|
27 | include $(KBUILD_PATH)/subheader.kmk
|
---|
28 |
|
---|
29 | KASH_WIN_FORKED_MODE =
|
---|
30 |
|
---|
31 | #
|
---|
32 | # The program.
|
---|
33 | #
|
---|
34 | PROGRAMS += kash
|
---|
35 | kash_TEMPLATE = BIN-THREADED
|
---|
36 | kash_NAME = kmk_ash
|
---|
37 | kash_ASTOOL = YASM
|
---|
38 | kash_DEFS = lint SHELL SMALL KASH_SEPARATE_PARSER_ALLOCATOR
|
---|
39 | if "$(KBUILD_TARGET)" != "win" || defined(KASH_WIN_FORKED_MODE)
|
---|
40 | kash_DEFS += SH_FORKED_MODE
|
---|
41 | else
|
---|
42 | kash_DEFS += KASH_SEPARATE_PARSER_ALLOCATOR KASH_ASYNC_CLOSE_HANDLE
|
---|
43 | endif
|
---|
44 | kash_DEFS.debug = DEBUG=2 K_STRICT
|
---|
45 | kash_DEFS.haiku = BSD
|
---|
46 | kash_DEFS.linux = BSD
|
---|
47 | kash_DEFS.solaris = BSD
|
---|
48 | ## @todo bring over PC_SLASHES?
|
---|
49 | kash_DEFS.win = \
|
---|
50 | BSD YY_NO_UNISTD_H \
|
---|
51 | SH_DEAL_WITH_CRLF PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS EXEC_HASH_BANG_SCRIPT \
|
---|
52 | KASH_USE_FORKSHELL2
|
---|
53 | kash_DEFS.os2 = \
|
---|
54 | HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME PC_OS2_LIBPATHS \
|
---|
55 | SH_DEAL_WITH_CRLF PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS EXEC_HASH_BANG_SCRIPT
|
---|
56 | kash_DEFS.darwin = \
|
---|
57 | HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
|
---|
58 | kash_DEFS.dragonfly = \
|
---|
59 | HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
|
---|
60 | kash_DEFS.freebsd = \
|
---|
61 | HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
|
---|
62 | kash_DEFS.gnukfbsd = HAVE_SYSCTL_H
|
---|
63 | kash_DEFS.netbsd = \
|
---|
64 | HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
|
---|
65 | kash_DEFS.openbsd = \
|
---|
66 | HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
|
---|
67 | kash_INCS = $(kash_0_OUTDIR) . # (the last is because of error.h)
|
---|
68 | kash_ASFLAGS.win = -g cv8
|
---|
69 | kash_ASFLAGS.win.x86 = -f win32
|
---|
70 | kash_ASFLAGS.win.amd64 = -f win64
|
---|
71 | if "$(USER)" == "bird" && "$(KBUILD_TARGET)" != "win"
|
---|
72 | kash_CFLAGS += -std=gnu99
|
---|
73 | endif
|
---|
74 | kash_CFLAGS.win.amd64 = -GS-
|
---|
75 | ifdef KASH_WIN_FORKED_MODE
|
---|
76 | kash_LDFLAGS.win = -DYNAMICBASE:NO
|
---|
77 | endif
|
---|
78 | kash_SOURCES = \
|
---|
79 | main.c \
|
---|
80 | alias.c \
|
---|
81 | cd.c \
|
---|
82 | error.c \
|
---|
83 | eval.c \
|
---|
84 | exec.c \
|
---|
85 | expand.c \
|
---|
86 | histedit.c \
|
---|
87 | input.c \
|
---|
88 | jobs.c \
|
---|
89 | mail.c \
|
---|
90 | memalloc.c \
|
---|
91 | mystring.c \
|
---|
92 | options.c \
|
---|
93 | output.c \
|
---|
94 | parser.c \
|
---|
95 | redir.c \
|
---|
96 | show.c \
|
---|
97 | syntax.c \
|
---|
98 | trap.c \
|
---|
99 | var.c \
|
---|
100 | miscbltin.c \
|
---|
101 | bltin/echo.c \
|
---|
102 | bltin/kill.c \
|
---|
103 | bltin/test.c \
|
---|
104 | \
|
---|
105 | $(kash_0_OUTDIR)/builtins.c \
|
---|
106 | $(kash_0_OUTDIR)/init.c \
|
---|
107 | $(kash_0_OUTDIR)/nodes.c \
|
---|
108 | \
|
---|
109 | setmode.c \
|
---|
110 | shinstance.c \
|
---|
111 | shheap.c \
|
---|
112 | shthread.c \
|
---|
113 | shfile.c
|
---|
114 | kash_SOURCES.gnuhurd = \
|
---|
115 | $(kash_0_OUTDIR)/sys_signame.c \
|
---|
116 | strlcpy.c
|
---|
117 | kash_SOURCES.gnukfbsd = \
|
---|
118 | $(kash_0_OUTDIR)/sys_signame.c \
|
---|
119 | strlcpy.c
|
---|
120 | kash_SOURCES.gnuknbsd = \
|
---|
121 | $(kash_0_OUTDIR)/sys_signame.c \
|
---|
122 | strlcpy.c
|
---|
123 | kash_SOURCES.haiku = \
|
---|
124 | $(kash_0_OUTDIR)/sys_signame.c \
|
---|
125 | strlcpy.c
|
---|
126 | kash_SOURCES.linux = \
|
---|
127 | $(kash_0_OUTDIR)/sys_signame.c \
|
---|
128 | strlcpy.c
|
---|
129 | kash_SOURCES.solaris = \
|
---|
130 | $(kash_0_OUTDIR)/sys_signame.c \
|
---|
131 | strlcpy.c
|
---|
132 | kash_SOURCES.win = \
|
---|
133 | $(kash_0_OUTDIR)/sys_signame.c \
|
---|
134 | strsignal.c \
|
---|
135 | strlcpy.c \
|
---|
136 | ../lib/nt/ntstat.c \
|
---|
137 | ../lib/nt/nthlpcore.c \
|
---|
138 | ../lib/nt/nthlpfs.c \
|
---|
139 | ../lib/nt/nt_child_inject_standard_handles.c
|
---|
140 | ifdef KASH_WIN_FORKED_MODE
|
---|
141 | kash_SOURCES.win += \
|
---|
142 | shfork-win.c \
|
---|
143 | shforkA-win.asm
|
---|
144 | endif
|
---|
145 |
|
---|
146 | kash_INTERMEDIATES = \
|
---|
147 | $(kash_0_OUTDIR)/builtins.h \
|
---|
148 | $(kash_0_OUTDIR)/nodes.h \
|
---|
149 | $(kash_0_OUTDIR)/token.h
|
---|
150 | kash_CLEAN = \
|
---|
151 | $(kash_INTERMEDIATES) \
|
---|
152 | $(kash_0_OUTDIR)/builtins.c \
|
---|
153 | $(kash_0_OUTDIR)/init.c \
|
---|
154 | $(kash_0_OUTDIR)/nodes.c
|
---|
155 |
|
---|
156 | kash_main.c_DEFS = KBUILD_SVN_REV=$(KBUILD_SVN_REV)
|
---|
157 |
|
---|
158 | ##
|
---|
159 | ## The manual page.
|
---|
160 | ##
|
---|
161 | #INSTALLS += kash.man
|
---|
162 | #kash.man_TEMPLATE = usr.bin.man
|
---|
163 | #kash.man_SOURCES = sh.1=>kash.1
|
---|
164 |
|
---|
165 |
|
---|
166 | #
|
---|
167 | # The signal name list:
|
---|
168 | #
|
---|
169 | $$(kash_0_OUTDIR)/sys_signame.c: $$(bld_signames_1_TARGET) | $$(dir $$@)
|
---|
170 | $< $@
|
---|
171 |
|
---|
172 | BLDPROGS += bld_signames
|
---|
173 | bld_signames_TEMPLATE := BLD
|
---|
174 | bld_signames_DEFS := SHELL SMALL
|
---|
175 | bld_signames_SOURCES := bld_signames.c
|
---|
176 |
|
---|
177 |
|
---|
178 | if1of ($(KBUILD_TARGET), win os2)
|
---|
179 | KASH_USE_PREGENERATED_CODE = 1
|
---|
180 | endif
|
---|
181 |
|
---|
182 | ifdef KASH_USE_PREGENERATED_CODE
|
---|
183 |
|
---|
184 | #
|
---|
185 | # Use the pregenerated code.
|
---|
186 | #
|
---|
187 | kash_SOURCES += \
|
---|
188 | $(kash_0_OUTDIR)/arith.c \
|
---|
189 | $(kash_0_OUTDIR)/arith_lex.c
|
---|
190 | kash_INTERMEDIATES += \
|
---|
191 | $(kash_0_OUTDIR)/arith.h
|
---|
192 |
|
---|
193 | define def_copy_generated
|
---|
194 | $$$$(kash_0_OUTDIR)/$(src): $(PATH_SUB_CURRENT)/generated/$(src)
|
---|
195 | $$(RM) -f $$@
|
---|
196 | $$(CP) -f $$^ $$@
|
---|
197 | endef
|
---|
198 |
|
---|
199 | $(foreach src, arith.h arith.c arith_lex.c builtins.h builtins.c nodes.h nodes.c token.h init.c,\
|
---|
200 | $(eval $(def_copy_generated)))
|
---|
201 |
|
---|
202 | else # !KASH_USE_PREGENERATED_CODE
|
---|
203 |
|
---|
204 | #
|
---|
205 | # Generate the code on the fly.
|
---|
206 | #
|
---|
207 |
|
---|
208 | USES += lex yacc
|
---|
209 | kash_USES = lex yacc
|
---|
210 | kash_LEXTOOL = FLEX
|
---|
211 | kash_LEXFLAGS = -8
|
---|
212 | #kash_YACCTOOL = BISON
|
---|
213 | kash_YACCTOOL = YACC
|
---|
214 | kash_YACCFLAGS = -ld
|
---|
215 | kash_SOURCES += \
|
---|
216 | arith.y \
|
---|
217 | arith_lex.l
|
---|
218 |
|
---|
219 | #
|
---|
220 | # ATTENTION! ATTENTION! ATTENTION!
|
---|
221 | #
|
---|
222 | # Older ash versions has trouble with some of these scripts, great.
|
---|
223 | # Kudos to the NetBSD guys for this clever move. ;)
|
---|
224 | #
|
---|
225 | # So, when building for the frist time, setting BOOSTRAP_SHELL=/bin/bash is good idea.
|
---|
226 | #
|
---|
227 | BOOTSTRAP_SHELL ?= $(SHELL)
|
---|
228 |
|
---|
229 | $$(kash_0_OUTDIR)/builtins.h + $$(kash_0_OUTDIR)/builtins.c: \
|
---|
230 | $$(kash_DEFPATH)/mkbuiltins \
|
---|
231 | $$(kash_DEFPATH)/shell.h \
|
---|
232 | $$(kash_DEFPATH)/builtins.def \
|
---|
233 | | $$(dir $$@)
|
---|
234 | $(BOOTSTRAP_SHELL) $+ $(dir $@)
|
---|
235 | [ -f $(kash_0_OUTDIR)/builtins.h ]
|
---|
236 |
|
---|
237 | $$(kash_0_OUTDIR)/nodes.h + $$(kash_0_OUTDIR)/nodes.c: \
|
---|
238 | $$(kash_DEFPATH)/mknodes.sh \
|
---|
239 | $$(kash_DEFPATH)/nodetypes \
|
---|
240 | $$(kash_DEFPATH)/nodes.c.pat \
|
---|
241 | | $$(dir $$@)
|
---|
242 | $(BOOTSTRAP_SHELL) $+ $(dir $@)
|
---|
243 | [ -f $(dir $@)/nodes.h ]
|
---|
244 |
|
---|
245 | $$(kash_0_OUTDIR)/token.h: $$(kash_DEFPATH)/mktokens | $$(dir $$@)
|
---|
246 | $(BOOTSTRAP_SHELL) $+
|
---|
247 | $(MV) token.h $@
|
---|
248 |
|
---|
249 | $$(kash_0_OUTDIR)/init.c: \
|
---|
250 | $$(kash_DEFPATH)/mkinit.sh \
|
---|
251 | $$(abspathex $$(filter-out $$(kash_0_OUTDIR)/%,$$(kash_SOURCES)), $$(kash_DEFPATH)) \
|
---|
252 | | $$(dir $$@)
|
---|
253 | $(BOOTSTRAP_SHELL) $+
|
---|
254 | $(MV) init.c $@
|
---|
255 |
|
---|
256 | endif # !KASH_USE_PREGENERATED_CODE
|
---|
257 |
|
---|
258 | #
|
---|
259 | # For debugging file handle inheritance on Windows.
|
---|
260 | #
|
---|
261 | if "$(KBUILD_TARGET)" == win && 0
|
---|
262 | PROGRAMS += tstDump
|
---|
263 | tstDump_TEMPLATE = BIN
|
---|
264 | tstDump_SOURCES = tstDump.c
|
---|
265 | endif
|
---|
266 |
|
---|
267 | # Include the sub-makefile.
|
---|
268 | include $(PATH_SUB_CURRENT)/tests/Makefile.kmk
|
---|
269 |
|
---|
270 | include $(FILE_KBUILD_SUB_FOOTER)
|
---|
271 |
|
---|
272 |
|
---|