Change make license
[platform/upstream/make.git] / src / dep.h
1 /* Definitions of dependency data structures for GNU Make.
2 Copyright (C) 1988-2020 Free Software Foundation, Inc.
3 This file is part of GNU Make.
4
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
8 version.
9
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17
18 /* Structure used in chains of names, for parsing and globbing.  */
19
20 #define NAMESEQ(_t)     \
21     _t *next;           \
22     const char *name
23
24 struct nameseq
25   {
26     NAMESEQ (struct nameseq);
27   };
28
29 /* Flag bits for the second argument to 'read_makefile'.
30    These flags are saved in the 'flags' field of each
31    'struct goaldep' in the chain returned by 'read_all_makefiles'.  */
32
33 #define RM_NO_DEFAULT_GOAL      (1 << 0) /* Do not set default goal.  */
34 #define RM_INCLUDED             (1 << 1) /* Search makefile search path.  */
35 #define RM_DONTCARE             (1 << 2) /* No error if it doesn't exist.  */
36 #define RM_NO_TILDE             (1 << 3) /* Don't expand ~ in file name.  */
37 #define RM_NOFLAG               0
38
39 /* Structure representing one dependency of a file.
40    Each struct file's 'deps' points to a chain of these, through 'next'.
41    'stem' is the stem for this dep line of static pattern rule or NULL.  */
42
43 #define DEP(_t)                                 \
44     NAMESEQ (_t);                               \
45     struct file *file;                          \
46     const char *stem;                           \
47     unsigned int flags : 8;                     \
48     unsigned int changed : 1;                   \
49     unsigned int ignore_mtime : 1;              \
50     unsigned int staticpattern : 1;             \
51     unsigned int need_2nd_expansion : 1;        \
52     unsigned int ignore_automatic_vars : 1
53
54 struct dep
55   {
56     DEP (struct dep);
57   };
58
59 /* Structure representing one goal.
60    The goals to be built constitute a chain of these, chained through 'next'.
61    'stem' is not used, but it's simpler to include and ignore it.  */
62
63 struct goaldep
64   {
65     DEP (struct goaldep);
66     int error;
67     floc floc;
68   };
69
70 /* Options for parsing lists of filenames.  */
71
72 #define PARSEFS_NONE    0x0000
73 #define PARSEFS_NOSTRIP 0x0001
74 #define PARSEFS_NOAR    0x0002
75 #define PARSEFS_NOGLOB  0x0004
76 #define PARSEFS_EXISTS  0x0008
77 #define PARSEFS_NOCACHE 0x0010
78 #define PARSEFS_ONEWORD 0x0020
79
80 #define PARSE_FILE_SEQ(_s,_t,_c,_p,_f) \
81             (_t *)parse_file_seq ((_s),sizeof (_t),(_c),(_p),(_f))
82 #define PARSE_SIMPLE_SEQ(_s,_t) \
83             (_t *)parse_file_seq ((_s),sizeof (_t),MAP_NUL,NULL,PARSEFS_NONE)
84
85 #ifdef VMS
86 void *parse_file_seq ();
87 #else
88 void *parse_file_seq (char **stringp, size_t size,
89                       int stopmap, const char *prefix, int flags);
90 #endif
91
92 char *tilde_expand (const char *name);
93
94 #ifndef NO_ARCHIVES
95 struct nameseq *ar_glob (const char *arname, const char *member_pattern, size_t size);
96 #endif
97
98 #define dep_name(d)        ((d)->name ? (d)->name : (d)->file->name)
99
100 #define alloc_seq_elt(_t)   xcalloc (sizeof (_t))
101 void free_ns_chain (struct nameseq *n);
102
103 #if defined(MAKE_MAINTAINER_MODE) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
104 /* Use inline to get real type-checking.  */
105 #define SI static inline
106 SI struct nameseq *alloc_ns()      { return alloc_seq_elt (struct nameseq); }
107 SI struct dep *alloc_dep()         { return alloc_seq_elt (struct dep); }
108 SI struct goaldep *alloc_goaldep() { return alloc_seq_elt (struct goaldep); }
109
110 SI void free_ns(struct nameseq *n)      { free (n); }
111 SI void free_dep(struct dep *d)         { free_ns ((struct nameseq *)d); }
112 SI void free_goaldep(struct goaldep *g) { free_dep ((struct dep *)g); }
113
114 SI void free_dep_chain(struct dep *d)      { free_ns_chain((struct nameseq *)d); }
115 SI void free_goal_chain(struct goaldep *g) { free_dep_chain((struct dep *)g); }
116 #else
117 # define alloc_ns()          alloc_seq_elt (struct nameseq)
118 # define alloc_dep()         alloc_seq_elt (struct dep)
119 # define alloc_goaldep()     alloc_seq_elt (struct goaldep)
120
121 # define free_ns(_n)         free (_n)
122 # define free_dep(_d)        free_ns (_d)
123 # define free_goaldep(_g)    free_dep (_g)
124
125 # define free_dep_chain(_d)  free_ns_chain ((struct nameseq *)(_d))
126 # define free_goal_chain(_g) free_ns_chain ((struct nameseq *)(_g))
127 #endif
128
129 struct dep *copy_dep_chain (const struct dep *d);
130
131 struct goaldep *read_all_makefiles (const char **makefiles);
132 void eval_buffer (char *buffer, const floc *floc);
133 enum update_status update_goal_chain (struct goaldep *goals);