1 /*
2  *      cook - file construction tool
3  *      Copyright (C) 1993-1997, 1999, 2001, 2003, 2006, 2007 Peter Miller;
4  *      All rights reserved.
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 3 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program. If not, see
18  *      <http://www.gnu.org/licenses/>.
19  *
20  *
21  * If you are going to add a new recipe flag (set by the "set" statement,
22  * or the "set" clause of a recipe) you need to change all of the
23  * following places:
24  *
25  * cook/option.h
26  *     to define the OPTION_ value
27  * cook/option.c
28  *     option_tidyup()
29  *         if the option defaults to true
30  *     option_set_errors()
31  *         if the option should be turned off once cookbook errors
32  *         are encountered.
33  *     option_number_name()
34  *         for the name of the option
35  * cook/flag.h
36  *     to define the RF_ values (RF stands for Recipe Flag)
37  * cook/flag.c
38  *     to define the RF_ names
39  * langu.flags.so
40  *     to document the recipe flag
41  *
42  * If you choose to make it a command line option,
43  * you must also update these files:
44  *
45  * cook/main.c
46  *     to define the new command line option and process it
47  *     (only if it should also be a command line option)
48  * cook/builtin/options.c
49  *     to access the option from within the cookbook (typically used
50  *     for recursive cook invokations)
51  * lib/en/man1/cook.1
52  *     to document it, if you added a new command line option
53  */
54 
55 #ifndef OPTION_H
56 #define OPTION_H
57 
58 #include <common/main.h>
59 
60 #include <common/str.h>
61 #include <common/str_list.h>
62 
63 /*
64  * option levels, highest to lowest
65  * (room for 16 levels in a 32 bit unsigned)
66  */
67 enum option_level_ty
68 {
69         OPTION_LEVEL_ERROR,
70         OPTION_LEVEL_AUTO,
71         OPTION_LEVEL_COMMAND_LINE,
72         OPTION_LEVEL_EXECUTE,
73         OPTION_LEVEL_RECIPE,
74         OPTION_LEVEL_COOKBOOK,
75         OPTION_LEVEL_ENVIRONMENT,
76         OPTION_LEVEL_DEFAULT
77 };
78 typedef enum option_level_ty option_level_ty;
79 
80 enum option_number_ty
81 {
82         OPTION_ACTION,          /* do not execute the command */
83         OPTION_BOOK,
84         OPTION_CASCADE,         /* do (not) cascade ingredients */
85         OPTION_CMDFILE,         /* generate a command file */
86         OPTION_DISASSEMBLE,     /* undocumented: disassemble opcode lists after
87                                    compilation */
88         OPTION_ERROK,           /* ignore error returns from commands */
89         OPTION_FINGERPRINT,     /* remember file fingerprints */
90         OPTION_FINGERPRINT_WRITE, /* preserve fingerprints if taken */
91         OPTION_FORCE,           /* always execute the commands */
92         OPTION_GATEFIRST,       /* check the gate conditions on a recipe before
93                                    evaluating the ingredients */
94         OPTION_IMPLICIT_ALLOWED, /* implicit recipes may be used */
95         OPTION_INCLUDE_COOKED,  /* cook the include-cooked include files */
96         OPTION_INCLUDE_COOKED_WARNING,  /* warn of include-cooked problems */
97         OPTION_INGREDIENTS_FINGERPRINT, /* use ingredients fingerprints */
98         OPTION_INVALIDATE_STAT_CACHE,
99         OPTION_LOGGING,
100         OPTION_METER,           /* meter each command */
101         OPTION_MKDIR,           /* make directories of targets */
102         OPTION_PERSEVERE,       /* keep trying if have errors */
103         OPTION_PRECIOUS,        /* do not delete failed targets */
104         OPTION_REASON,          /* emit inference debugging commentary */
105         OPTION_RECURSE,         /* allow target recursion loops */
106         OPTION_SHALLOW,         /* recipe targets are to be shallow on
107                                    search_list */
108         OPTION_SILENT,          /* do not echo any command */
109         OPTION_STAR,            /* emit progress stars */
110         OPTION_STRIP_DOT,       /* strip leading ./ from paths */
111         OPTION_SYMLINK_INGREDIENTS, /* make symlink for non-top-level ingredi */
112         OPTION_TERMINAL,        /* enable tty output when logging */
113         OPTION_TOUCH,           /* do not execute the command, just touch */
114         OPTION_UNLINK,          /* remove targets before running rule body */
115         OPTION_UPDATE,          /* update utime for consistency */
116         OPTION_UPDATE_MAX,      /* update utime for consistency - backwards! */
117         OPTION_MATCH_MODE_REGEX, /* regex pattern matching (as opp native) */
118         OPTION_TELL_POSITION,   /* add file and line when echoing commands */
119 
120         /*
121          * If you add to this list, make sure you also add the option to
122          * the list in cook/builtin/options.c
123          */
124         OPTION_max
125 };
126 typedef enum option_number_ty option_number_ty;
127 
128 typedef struct option_ty option_ty;
129 struct option_ty
130 {
131         string_list_ty  o_target;
132         string_ty       *o_book;
133         string_ty       *o_logfile;
134         string_list_ty  o_search_path;
135         string_list_ty  o_vardef;
136         int             pairs;
137         int             script;
138         int             web;
139         int             fingerprint_update;
140 };
141 
142 extern  option_ty       option;
143 
144 int option_already(option_number_ty, option_level_ty);
145 int option_test(option_number_ty);
146 void option_set(option_number_ty, option_level_ty, int);
147 void option_undo(option_number_ty, option_level_ty);
148 void option_undo_level(option_level_ty);
149 void option_set_errors(void);
150 void option_tidy_up(void);
151 
152 void *option_flag_state_get(void);
153 void option_flag_state_set(void *);
154 
155 const char *option_number_name(option_number_ty);
156 const char *option_level_name(option_level_ty);
157 
158 #endif /* OPTION_H */
159