xref: /openbsd/usr.bin/make/engine.h (revision 7a7b8f33)
1a6f1883eSespie #ifndef ENGINE_H
2a6f1883eSespie #define ENGINE_H
3*7a7b8f33Sespie /*	$OpenBSD: engine.h,v 1.17 2020/01/13 15:12:58 espie Exp $	*/
4a6f1883eSespie 
5a6f1883eSespie /*
6a6f1883eSespie  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
7a6f1883eSespie  * Copyright (c) 1988, 1989 by Adam de Boor
8a6f1883eSespie  * Copyright (c) 1989 by Berkeley Softworks
9a6f1883eSespie  * All rights reserved.
10a6f1883eSespie  *
11a6f1883eSespie  * This code is derived from software contributed to Berkeley by
12a6f1883eSespie  * Adam de Boor.
13a6f1883eSespie  *
14a6f1883eSespie  * Redistribution and use in source and binary forms, with or without
15a6f1883eSespie  * modification, are permitted provided that the following conditions
16a6f1883eSespie  * are met:
17a6f1883eSespie  * 1. Redistributions of source code must retain the above copyright
18a6f1883eSespie  *    notice, this list of conditions and the following disclaimer.
19a6f1883eSespie  * 2. Redistributions in binary form must reproduce the above copyright
20a6f1883eSespie  *    notice, this list of conditions and the following disclaimer in the
21a6f1883eSespie  *    documentation and/or other materials provided with the distribution.
22a6f1883eSespie  * 3. Neither the name of the University nor the names of its contributors
23a6f1883eSespie  *    may be used to endorse or promote products derived from this software
24a6f1883eSespie  *    without specific prior written permission.
25a6f1883eSespie  *
26a6f1883eSespie  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27a6f1883eSespie  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28a6f1883eSespie  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29a6f1883eSespie  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30a6f1883eSespie  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31a6f1883eSespie  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32a6f1883eSespie  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33a6f1883eSespie  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34a6f1883eSespie  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35a6f1883eSespie  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36a6f1883eSespie  * SUCH DAMAGE.
37a6f1883eSespie  *
38a6f1883eSespie  *	from: @(#)job.h 8.1 (Berkeley) 6/6/93
39a6f1883eSespie  */
40a6f1883eSespie 
41a6b963c8Sespie /* ok = node_find_valid_commands(node);
42a6f1883eSespie  *	verify the integrity of a node's commands, pulling stuff off
43a6f1883eSespie  * 	.DEFAULT and other places if necessary.
44a6f1883eSespie  */
45a6b963c8Sespie extern bool node_find_valid_commands(GNode *);
46e34c3a80Sespie 
47e34c3a80Sespie /* node_failure(gn);
48e34c3a80Sespie  *	indicate we don't know how to make gn.
49e34c3a80Sespie  *	may continue with -k or if node was optional.
50e34c3a80Sespie  */
51a6b963c8Sespie extern void node_failure(GNode *);
52e34c3a80Sespie 
53cae88e06Sespie /* Job_Touch(node);
54a6f1883eSespie  *	touch the path corresponding to a node or update the corresponding
55a6f1883eSespie  *	archive object.
56a6f1883eSespie  */
57cae88e06Sespie extern void Job_Touch(GNode *);
58e34c3a80Sespie 
59a6f1883eSespie /* Make_TimeStamp(parent, child);
60a6f1883eSespie  *	ensure parent is at least as recent as child.
61a6f1883eSespie  */
62a6f1883eSespie extern void Make_TimeStamp(GNode *, GNode *);
63e34c3a80Sespie 
64a6f1883eSespie /* Make_HandleUse(user_node, usee_node);
65a6f1883eSespie  *	let user_node inherit the commands from usee_node
66a6f1883eSespie  */
67a6f1883eSespie extern void Make_HandleUse(GNode *, GNode *);
68a6f1883eSespie 
69a6f1883eSespie /* old = Make_OODate(node);
70a6f1883eSespie  *	check if a given node is out-of-date.
71a6f1883eSespie  */
72a6f1883eSespie extern bool Make_OODate(GNode *);
73e34c3a80Sespie 
74a6f1883eSespie /* Make_DoAllVar(node);
75a6f1883eSespie  *	fill all dynamic variables for a node.
76a6f1883eSespie  */
77a6f1883eSespie extern void Make_DoAllVar(GNode *);
7832e144d7Sespie 
79e34c3a80Sespie /* status = run_gnode(gn):
80e34c3a80Sespie  *	fully run all commands of a node for compat mode.
81e34c3a80Sespie  */
82f46d747cSespie extern int run_gnode(GNode *);
8332e144d7Sespie 
84a6b963c8Sespie /*-
85a6b963c8Sespie  * Job Table definitions.
86a6b963c8Sespie  *
87a6b963c8Sespie  * Each job has several things associated with it:
88a6b963c8Sespie  *	1) The process id of the child shell
89194f6eccSespie  *	2) The graph node describing the target of this job
90a6b963c8Sespie  *	3) State associated to latest command run
91a6b963c8Sespie  *	5) A word of flags which determine how the module handles errors,
92a6b963c8Sespie  *	   echoing, etc. for the job
93a6b963c8Sespie  *
94a6b963c8Sespie  * The job "table" is kept as a linked Lst in 'jobs', with the number of
95a6b963c8Sespie  * active jobs maintained in the 'nJobs' variable. At no time will this
96a6b963c8Sespie  * exceed the value of 'maxJobs', initialized by the Job_Init function.
97a6b963c8Sespie  *
98a6b963c8Sespie  * When a job is finished, the Make_Update function is called on each of the
99194f6eccSespie  * parents of the node which was just rebuilt. This takes care of the upward
100a6b963c8Sespie  * traversal of the dependency graph.
101a6b963c8Sespie  */
102a6b963c8Sespie struct Job_ {
103a6b963c8Sespie 	struct Job_ 	*next;		/* singly linked list */
104a6b963c8Sespie 	pid_t		pid;		/* Current command process id */
105a6b963c8Sespie 	Location	*location;
10603dc80a6Sespie 	int 		code;		/* exit status or signal code */
10703dc80a6Sespie 	unsigned short	exit_type;	/* last child exit or signal */
108a6b963c8Sespie #define JOB_EXIT_OKAY 	0
109a6b963c8Sespie #define JOB_EXIT_BAD 	1
110a6b963c8Sespie #define JOB_SIGNALED 	2
111a6b963c8Sespie 	unsigned short	flags;
112a6b963c8Sespie #define JOB_SILENT		0x001	/* Command was silent */
113a6b963c8Sespie #define JOB_IS_EXPENSIVE 	0x002
114b12bcd0dSespie #define JOB_LOST		0x004	/* sent signal to non-existing pid ? */
115a6b963c8Sespie #define JOB_ERRCHECK		0x008	/* command wants errcheck */
116*7a7b8f33Sespie #define JOB_KEEPERROR		0x010	/* should place job on error list */
11703dc80a6Sespie 	LstNode		next_cmd;	/* Next command to run */
11803dc80a6Sespie 	char		*cmd;		/* Last command run */
11903dc80a6Sespie 	GNode		*node;	    	/* Target of this job */
120a6b963c8Sespie };
121a6b963c8Sespie 
122e34c3a80Sespie /* Continuation-style running commands for the parallel engine */
123e34c3a80Sespie 
124e34c3a80Sespie /* job_attach_node(job, node):
125e34c3a80Sespie  *	attach a job to an allocated node, to be able to run commands
126e34c3a80Sespie  */
127e34c3a80Sespie extern void job_attach_node(Job *, GNode *);
128e34c3a80Sespie 
129e34c3a80Sespie /* finished = job_run_next(job):
130e34c3a80Sespie  *	run next command for a job attached to a node.
131e34c3a80Sespie  *	return true when job is finished.
132e34c3a80Sespie  */
133a6b963c8Sespie extern bool job_run_next(Job *);
134a6b963c8Sespie 
1353bb9adb9Sespie /* handle_job_status(job, waitstatus):
136e34c3a80Sespie  *	process a wait return value corresponding to a job, display
137e34c3a80Sespie  *	messages and set job status accordingly.
138e34c3a80Sespie  */
1393bb9adb9Sespie extern void handle_job_status(Job *, int);
14032e144d7Sespie 
141a6f1883eSespie #endif
142