xref: /illumos-gate/usr/src/cmd/make/include/mk/defs.h (revision a99cb9618990662acbd3bab1b4a5b05a6ca62556)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23  * Use is subject to license terms.
24  *
25  * Copyright 2019, Joyent, Inc.
26  */
27 
28 #ifndef _MK_DEFS_H
29 #define	_MK_DEFS_H
30 
31 /*
32  * Included files
33  */
34 
35 #include <mksh/defs.h>
36 
37 /*
38  * Defined macros
39  */
40 
41 #define	SKIPSPACE(x)	while (*x &&				\
42 				((*x == (int)space_char) ||	\
43 				(*x == (int)tab_char) ||	\
44 				(*x == (int)comma_char))) {	\
45 					x++;			\
46 			}
47 
48 #define	SKIPWORD(x)	while (*x &&				\
49 				(*x != (int)space_char) &&	\
50 				(*x != (int)tab_char) &&	\
51 				(*x != (int)newline_char) &&	\
52 				(*x != (int)comma_char) &&	\
53 				(*x != (int)equal_char)) {	\
54 					x++;			\
55 			}
56 
57 #define	SKIPTOEND(x)	while (*x &&				\
58 				(*x != (int)newline_char)) {	\
59 					x++;			\
60 			}
61 
62 #define	PMAKE_DEF_MAX_JOBS	2	/* Default number of parallel jobs. */
63 
64 #define	OUT_OF_DATE(a, b) \
65 	(((a) < (b)) || (((a) == file_doesnt_exist) && \
66 	((b) == file_doesnt_exist)))
67 
68 #define	OUT_OF_DATE_SEC(a, b) \
69 	(((a).tv_sec < (b).tv_sec) || \
70 	(((a).tv_sec == file_doesnt_exist.tv_sec) && \
71 	((b).tv_sec == file_doesnt_exist.tv_sec)))
72 
73 #define	SETVAR(name, value, append) \
74 				setvar_daemon(name, value, append, no_daemon, \
75 				true, debug_level)
76 #define	MAX(a, b)		(((a) > (b))?(a):(b))
77 /*
78  * New feature added to SUN5_0 make,  invoke the vanilla svr4 make when
79  * the USE_SVR4_MAKE environment variable is set.
80  */
81 #define	SVR4_MAKE		"/usr/ccs/lib/svr4.make"
82 #define	USE_SVR4_MAKE		"USE_SVR4_MAKE"
83 /*
84  * The standard MAXHOSTNAMELEN is 64. We want 32.
85  */
86 #define	MAX_HOSTNAMELEN		32
87 
88 
89 /*
90  * typedefs & structs
91  */
92 typedef enum {
93 	no_state,
94 	scan_name_state,
95 	scan_command_state,
96 	enter_dependencies_state,
97 	enter_conditional_state,
98 	enter_equal_state,
99 	illegal_bytes_state,
100 	illegal_eoln_state,
101 	poorly_formed_macro_state,
102 	exit_state
103 } Reader_state;
104 
105 struct _Name_vector {
106 	struct _Name		*names[64];
107 	struct _Chain		*target_group[64];
108 	short			used;
109 	struct _Name_vector	*next;
110 };
111 
112 struct _Running {
113 	struct _Running		*next;
114 	Doname			state;
115 	struct _Name		*target;
116 	struct _Name		*true_target;
117 	struct _Property	*command;
118 	struct _Name		*sprodep_value;
119 	char			*sprodep_env;
120 	int			recursion_level;
121 	Boolean			do_get;
122 	Boolean			implicit;
123 	Boolean			redo;
124 	int			auto_count;
125 	struct _Name		**automatics;
126 	pid_t			pid;
127 	int			job_msg_id;
128 	char			*stdout_file;
129 	char			*stderr_file;
130 	struct _Name		*temp_file;
131 	int			conditional_cnt;
132 	struct _Name		**conditional_targets;
133 	Boolean			make_refd;
134 };
135 
136 typedef enum {
137 	serial_mode,
138 	parallel_mode
139 } DMake_mode;
140 
141 typedef enum {
142 	txt1_mode,
143 	txt2_mode,
144 	html1_mode
145 } DMake_output_mode;
146 
147 struct _Recursive_make {
148 	struct _Recursive_make	*next;	  /* Linked list */
149 	wchar_t			*target;  /* Name of target */
150 	wchar_t			*oldline; /* Original line in .nse_depinfo */
151 	wchar_t			*newline; /* New line in .nse_depinfo */
152 	/*
153 	 * string built from value of
154 	 * conditional macros used by
155 	 * this target
156 	 */
157 	wchar_t			*cond_macrostring;
158 	/* This target is no longer recursive */
159 	Boolean			removed;
160 };
161 
162 struct _Dyntarget {
163 	struct _Dyntarget	*next;
164 	struct _Name		*name;
165 };
166 
167 
168 /*
169  * Typedefs for all structs
170  */
171 typedef struct _Cmd_line	*Cmd_line, Cmd_line_rec;
172 typedef struct _Dependency	*Dependency, Dependency_rec;
173 typedef struct _Macro		*Macro, Macro_rec;
174 typedef struct _Name_vector	*Name_vector, Name_vector_rec;
175 typedef struct _Percent		*Percent, Percent_rec;
176 typedef struct _Dyntarget	*Dyntarget;
177 typedef struct _Recursive_make	*Recursive_make, Recursive_make_rec;
178 typedef struct _Running		*Running, Running_rec;
179 
180 
181 /*
182  *	extern declarations for all global variables.
183  *	The actual declarations are in globals.cc
184  */
185 extern	Boolean		allrules_read;
186 extern	Name		posix_name;
187 extern	Name		svr4_name;
188 extern	Boolean		sdot_target;
189 extern	Boolean		all_parallel;
190 extern	Boolean		assign_done;
191 extern	Boolean		build_failed_seen;
192 extern	Name		built_last_make_run;
193 extern	Name		c_at;
194 extern	Boolean		command_changed;
195 extern	Boolean		commands_done;
196 extern	Chain		conditional_targets;
197 extern	Name		conditionals;
198 extern	Boolean		continue_after_error;
199 extern	Property	current_line;
200 extern	Name		current_make_version;
201 extern	Name		current_target;
202 extern	short		debug_level;
203 extern	Cmd_line	default_rule;
204 extern	Name		default_rule_name;
205 extern	Name		default_target_to_build;
206 extern	Boolean		depinfo_already_read;
207 extern	Name		dmake_group;
208 extern	Name		dmake_max_jobs;
209 extern	Name		dmake_mode;
210 extern	DMake_mode	dmake_mode_type;
211 extern	Name		dmake_output_mode;
212 extern	DMake_output_mode	output_mode;
213 extern	Name		dmake_odir;
214 extern	Name		dmake_rcfile;
215 extern	Name		done;
216 extern	Name		dot;
217 extern	Name		dot_keep_state;
218 extern	Name		dot_keep_state_file;
219 extern	Name		empty_name;
220 extern	Boolean		fatal_in_progress;
221 extern	int		file_number;
222 extern	Name		force;
223 extern	Name		ignore_name;
224 extern	Boolean		ignore_errors;
225 extern	Boolean		ignore_errors_all;
226 extern	Name		init;
227 extern	int		job_msg_id;
228 extern	Boolean		keep_state;
229 extern	Name		make_state;
230 extern	timestruc_t	make_state_before;
231 extern	Boolean		make_state_locked;
232 extern	Dependency	makefiles_used;
233 extern	Name		makeflags;
234 extern	Name		make_version;
235 extern	char		mbs_buffer2[];
236 extern	char		*mbs_ptr;
237 extern	char		*mbs_ptr2;
238 extern	Boolean		no_action_was_taken;
239 extern	Boolean		no_parallel;
240 extern	Name		no_parallel_name;
241 extern	Name		not_auto;
242 extern	Boolean		only_parallel;
243 extern	Boolean		parallel;
244 extern	Name		parallel_name;
245 extern	Name		localhost_name;
246 extern	int		parallel_process_cnt;
247 extern	Percent		percent_list;
248 extern	Dyntarget	dyntarget_list;
249 extern	Name		plus;
250 extern	Name		pmake_machinesfile;
251 extern	Name		precious;
252 extern	Name		primary_makefile;
253 extern	Boolean		quest;
254 extern	short		read_trace_level;
255 extern	Boolean		reading_dependencies;
256 extern	int		recursion_level;
257 extern	Name		recursive_name;
258 extern	short		report_dependencies_level;
259 extern	Boolean		report_pwd;
260 extern	Boolean		rewrite_statefile;
261 extern	Running		running_list;
262 extern	char		*sccs_dir_path;
263 extern	Name		sccs_get_name;
264 extern	Name		sccs_get_posix_name;
265 extern	Cmd_line	sccs_get_rule;
266 extern	Cmd_line	sccs_get_org_rule;
267 extern	Cmd_line	sccs_get_posix_rule;
268 extern	Name		get_name;
269 extern	Name		get_posix_name;
270 extern	Cmd_line	get_rule;
271 extern	Cmd_line	get_posix_rule;
272 extern	Boolean		all_precious;
273 extern	Boolean		report_cwd;
274 extern	Boolean		silent_all;
275 extern	Boolean		silent;
276 extern	Name		silent_name;
277 extern	char		*stderr_file;
278 extern	char		*stdout_file;
279 extern	Boolean		stdout_stderr_same;
280 extern	Dependency	suffixes;
281 extern	Name		suffixes_name;
282 extern	Name		sunpro_dependencies;
283 extern	Boolean		target_variants;
284 extern	const char	*tmpdir;
285 extern	const char	*temp_file_directory;
286 extern	Name		temp_file_name;
287 extern	short		temp_file_number;
288 extern  wchar_t		*top_level_target;
289 extern	Boolean		touch;
290 extern	Boolean		trace_reader;
291 extern	Boolean		build_unconditional;
292 extern	pathpt		vroot_path;
293 extern	Name		wait_name;
294 extern	wchar_t		wcs_buffer2[];
295 extern	wchar_t		*wcs_ptr;
296 extern	wchar_t		*wcs_ptr2;
297 extern	long int	hostid;
298 extern	Boolean		path_reset;
299 extern	Boolean		rebuild_arg0;
300 
301 /*
302  * Declarations of system defined variables
303  */
304 /* On linux this variable is defined in 'signal.h' */
305 extern	char		*sys_siglist[];
306 
307 /*
308  * Declarations of system supplied functions
309  */
310 extern	int		file_lock(char *, char *, int *, int);
311 
312 /*
313  * Declarations of functions declared and used by make
314  */
315 extern	void		add_pending(Name target, int recursion_level,
316 	Boolean do_get, Boolean implicit, Boolean redo);
317 extern	void		add_running(Name target, Name true_target,
318 	Property command, int recursion_level, int auto_count,
319 	Name *automatics, Boolean do_get, Boolean implicit);
320 extern	void		add_serial(Name target, int recursion_level,
321 	Boolean do_get, Boolean implicit);
322 extern	void		add_subtree(Name target, int recursion_level,
323 	Boolean do_get, Boolean implicit);
324 extern  void		append_or_replace_macro_in_dyn_array(
325 	ASCII_Dyn_Array *Ar, char *macro);
326 extern	void		await_parallel(Boolean waitflg);
327 extern	void		build_suffix_list(Name target_suffix);
328 extern	Boolean		check_auto_dependencies(Name target, int auto_count,
329 	Name *automatics);
330 extern	void		check_state(Name temp_file_name);
331 extern	void		cond_macros_into_string(Name np, String_rec *buffer);
332 extern	void		construct_target_string();
333 extern	void		create_xdrs_ptr(void);
334 extern	void		depvar_add_to_list(Name name, Boolean cmdline);
335 extern	Doname		doname(Name target, Boolean do_get, Boolean implicit,
336 	Boolean automatic = false);
337 extern	Doname		doname_check(Name target, Boolean do_get,
338 	Boolean implicit, Boolean automatic);
339 extern	Doname		doname_parallel(Name target, Boolean do_get,
340 	Boolean implicit);
341 extern	Doname		dosys(Name command, Boolean ignore_error,
342 	Boolean call_make, Boolean silent_error, Boolean always_exec,
343 	Name target);
344 extern	void		dump_make_state(void);
345 extern	void		dump_target_list(void);
346 extern	void		enter_conditional(Name target, Name name, Name value,
347 	Boolean append);
348 extern	void		enter_dependencies(Name target, Chain target_group,
349 	Name_vector depes, Cmd_line command, Separator separator);
350 extern	void		enter_dependency(Property line, Name depe,
351 	Boolean automatic);
352 extern	void		enter_equal(Name name, Name value, Boolean append);
353 extern  Percent		enter_percent(Name target, Chain target_group,
354 	Name_vector depes, Cmd_line command);
355 extern	Dyntarget	enter_dyntarget(Name target);
356 extern	Name_vector	enter_name(String string, Boolean tail_present,
357 	wchar_t *string_start, wchar_t *string_end, Name_vector current_names,
358 	Name_vector *extra_names, Boolean *target_group_seen);
359 extern	Boolean		exec_vp(char *name, char **argv, char **envp,
360 	Boolean ignore_error);
361 extern	Doname		execute_parallel(Property line, Boolean waitflg,
362 	Boolean local = false);
363 extern	Doname		execute_serial(Property line);
364 extern	timestruc_t&	exists(Name target);
365 extern	void		fatal(const char *, ...) __NORETURN;
366 extern	void		fatal_reader(char *, ...);
367 extern	Doname		find_ar_suffix_rule(Name target, Name true_target,
368 	Property *command, Boolean rechecking);
369 extern	Doname		find_double_suffix_rule(Name target, Property *command,
370 	Boolean rechecking);
371 extern	Doname		find_percent_rule(Name target, Property *command,
372 	Boolean rechecking);
373 extern	int		find_run_directory(char *cmd, char *cwd, char *dir,
374 	char **pgm, char **run, char *path);
375 extern	Doname		find_suffix_rule(Name target, Name target_body,
376 	Name target_suffix, Property *command, Boolean rechecking);
377 extern	Chain		find_target_groups(Name_vector target_list, int i,
378 	Boolean reset);
379 extern	void		finish_children(Boolean docheck);
380 extern	void		finish_running(void);
381 extern	void		free_chain(Name_vector ptr);
382 extern  void		gather_recursive_deps(void);
383 extern	char		*get_current_path(void);
384 extern	int		get_job_msg_id(void);
385 extern	wchar_t		*getmem_wc(int size);
386 extern	void		handle_interrupt(int);
387 extern	Boolean		is_running(Name target);
388 extern	void		load_cached_names(void);
389 extern	Boolean		parallel_ok(Name target, Boolean line_prop_must_exists);
390 extern	void		print_dependencies(Name target, Property line);
391 extern	void		send_job_start_msg(Property line);
392 extern	void		send_rsrc_info_msg(int max_jobs, char *hostname,
393 	char *username);
394 extern	void		print_value(Name value, Daemon daemon);
395 extern	timestruc_t&	read_archive(Name target);
396 extern	int		read_dir(Name dir, wchar_t *pattern, Property line,
397 	wchar_t *library);
398 extern	void		read_directory_of_file(Name file);
399 extern	int		read_make_machines(Name make_machines_name);
400 extern	Boolean		read_simple_file(Name makefile_name, Boolean chase_path,
401 	Boolean doname_it, Boolean complain, Boolean must_exist,
402 	Boolean report_file, Boolean lock_makefile);
403 extern	void		remove_recursive_dep(Name target);
404 extern	void		report_recursive_dep(Name target, char *line);
405 extern	void		report_recursive_done(void);
406 extern	void		report_recursive_init(void);
407 extern	Recursive_make	find_recursive_target(Name target);
408 extern	void		reset_locals(Name target, Property old_locals,
409 	Property conditional, int index);
410 extern	void		set_locals(Name target, Property old_locals);
411 extern	void		setvar_append(Name name, Name value);
412 extern	void		setvar_envvar(void);
413 extern	void		special_reader(Name target, Name_vector depes,
414 	Cmd_line command);
415 extern	void		startup_rxm();
416 extern	Doname		target_can_be_built(Name target);
417 extern	char		*time_to_string(const timestruc_t &time);
418 extern	void		update_target(Property line, Doname result);
419 extern	void		warning(char *, ...);
420 extern	void		write_state_file(int report_recursive, Boolean exiting);
421 extern	Name		vpath_translation(Name cmd);
422 extern	char		*make_install_prefix(void);
423 
424 #define	DEPINFO_FMT_VERSION "VERS2$"
425 #define	VER_LEN strlen(DEPINFO_FMT_VERSION)
426 
427 
428 #endif	/* _MK_DEFS_H */
429