3 * kMk Builtin command handling.
7 * Copyright (c) 2005-2016 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
9 * This file is part of kBuild.
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.
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.
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/>
26 #ifndef ___kmk_kmkbuiltin_h___
27 #define ___kmk_kmkbuiltin_h___
30 # ifndef pid_t /* see config.h.win */
31 # define pid_t intptr_t /* Note! sub_proc.c needs it to be pointer sized. */
34 # include <sys/types.h>
41 /* For the GNU/hurd weirdo. */
44 # define PATH_MAX MAXPATHLEN
46 # define PATH_MAX 4096
50 # define MAXPATHLEN PATH_MAX
53 /** This is for telling fopen() to get a close-on-exec handle.
54 * @todo glibc 2.7+ and recent cygwin supports 'e' for doing this. */
55 #ifndef KMK_FOPEN_NO_INHERIT_MODE
57 # define KMK_FOPEN_NO_INHERIT_MODE "N"
59 # define KMK_FOPEN_NO_INHERIT_MODE ""
63 /** This is for telling open() to open to return a close-on-exec descriptor. */
65 # define KMK_OPEN_NO_INHERIT _O_NOINHERIT
66 #elif defined(O_NOINHERIT)
67 # define KMK_OPEN_NO_INHERIT O_NOINHERIT
68 #elif defined(O_CLOEXEC)
69 # define KMK_OPEN_NO_INHERIT O_CLOEXEC
71 # define KMK_OPEN_NO_INHERIT 0
75 #include "kbuild_version.h"
76 #if !defined(KMK_BUILTIN_STANDALONE) && !defined(KWORKER)
81 int kmk_builtin_command(const char *pszCmd
, struct child
*pChild
, char ***ppapszArgvToSpawn
, pid_t
*pPidSpawned
);
82 int kmk_builtin_command_parsed(int argc
, char **argv
, struct child
*pChild
, char ***ppapszArgvToSpawn
, pid_t
*pPidSpawned
);
86 * KMK built-in command execution context.
88 typedef struct KMKBUILTINCTX
90 /** The program name to use in error messages. */
91 const char *pszProgName
;
92 /** The KMK output synchronizer. */
94 #if defined(KBUILD_OS_WINDOWS) && !defined(KMK_BUILTIN_STANDALONE)
95 /** Pointer to the worker thread, if we're on one. */
99 /** Pointer to kmk built-in command execution context. */
100 typedef KMKBUILTINCTX
*PKMKBUILTINCTX
;
103 * kmk built-in command entry.
105 typedef struct KMKBUILTINENTRY
119 #define FN_SIG_MAIN 0
120 int (* pfnMain
)(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
121 #define FN_SIG_MAIN_SPAWNS 1
122 int (* pfnMainSpawns
)(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
, struct child
*pChild
, pid_t
*pPid
);
123 #define FN_SIG_MAIN_TO_SPAWN 2
124 int (* pfnMainToSpawn
)(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
, char ***ppapszArgvToSpawn
);
126 size_t uFnSignature
: 8;
127 size_t fMtSafe
: 1; /**< Safe for multi threaded execution. */
128 size_t fNeedEnv
: 1; /**< Needs the (target) environment. */
130 /** Pointer to kmk built-in command entry. */
131 typedef KMKBUILTINENTRY
const *PCKMKBUILTINENTRY
;
133 extern int kmk_builtin_append(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
, struct child
*pChild
, pid_t
*pPidSpawned
);
134 extern int kmk_builtin_cp(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
135 extern int kmk_builtin_cat(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
136 extern int kmk_builtin_chmod(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
137 extern int kmk_builtin_cmp(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
138 extern int kmk_builtin_dircache(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
139 extern int kmk_builtin_echo(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
140 extern int kmk_builtin_expr(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
141 extern int kmk_builtin_install(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
142 extern int kmk_builtin_ln(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
143 extern int kmk_builtin_md5sum(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
144 extern int kmk_builtin_mkdir(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
145 extern int kmk_builtin_mv(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
146 extern int kmk_builtin_printf(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
147 extern int kmk_builtin_redirect(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
, struct child
*pChild
, pid_t
*pPidSpawned
);
148 extern int kmk_builtin_rm(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
149 extern int kmk_builtin_rmdir(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
150 extern int kmk_builtin_sleep(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
151 extern int kmk_builtin_test(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
, char ***ppapszArgvSpawn
);
152 extern int kmk_builtin_touch(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
153 #ifdef KBUILD_OS_WINDOWS
154 extern int kmk_builtin_kSubmit(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
, struct child
*pChild
, pid_t
*pPidSpawned
);
155 extern int kSubmitSubProcGetResult(intptr_t pvUser
, int fBlock
, int *prcExit
, int *piSigNo
);
156 extern int kSubmitSubProcKill(intptr_t pvUser
, int iSignal
);
157 extern void kSubmitSubProcCleanup(intptr_t pvUser
);
158 extern int kmk_builtin_kill(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
160 extern int kmk_builtin_kDepIDB(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
161 extern int kmk_builtin_kDepObj(int argc
, char **argv
, char **envp
, PKMKBUILTINCTX pCtx
);
163 extern char *kmk_builtin_func_printf(char *o
, char **argv
, const char *funcname
);
165 /* common-env-and-cwd-opt.c: */
166 extern int kBuiltinOptEnvSet(PKMKBUILTINCTX pCtx
, char ***ppapszEnv
, unsigned *pcEnvVars
, unsigned *pcAllocatedEnvVars
,
167 int cVerbosity
, const char *pszValue
);
168 extern int kBuiltinOptEnvAppend(PKMKBUILTINCTX pCtx
, char ***ppapszEnv
, unsigned *pcEnvVars
, unsigned *pcAllocatedEnvVars
,
169 int cVerbosity
, const char *pszValue
);
170 extern int kBuiltinOptEnvPrepend(PKMKBUILTINCTX pCtx
, char ***ppapszEnv
, unsigned *pcEnvVars
, unsigned *pcAllocatedEnvVars
,
171 int cVerbosity
, const char *pszValue
);
172 extern int kBuiltinOptEnvUnset(PKMKBUILTINCTX pCtx
, char ***ppapszEnv
, unsigned *pcEnvVars
, unsigned *pcAllocatedEnvVars
,
173 int cVerbosity
, const char *pszVarToRemove
);
174 extern int kBuiltinOptEnvZap(PKMKBUILTINCTX pCtx
, char ***ppapszEnv
, unsigned *pcEnvVars
, unsigned *pcAllocatedEnvVars
,
176 extern void kBuiltinOptEnvCleanup(char ***ppapszEnv
, unsigned cEnvVars
, unsigned *pcAllocatedEnvVars
);
177 extern int kBuiltinOptChDir(PKMKBUILTINCTX pCtx
, char *pszCwd
, size_t cbCwdBuf
, const char *pszValue
);
179 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS
180 extern void kmk_builtin_print_stats(FILE *pOutput
, const char *pszPrefix
);