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