xref: /openbsd-src/usr.bin/make/dir.h (revision 1f89b472f1907a5c725c1719663ff8099a518f8c)
1f7923656Sespie #ifndef DIR_H
2f7923656Sespie #define DIR_H
3f7923656Sespie 
4*1f89b472Sespie /*	$OpenBSD: dir.h,v 1.29 2013/04/23 14:32:53 espie Exp $	*/
5789486c7Smillert /*	$NetBSD: dir.h,v 1.4 1996/11/06 17:59:05 christos Exp $ */
6df930be7Sderaadt 
7df930be7Sderaadt /*
8df930be7Sderaadt  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
9df930be7Sderaadt  * Copyright (c) 1988, 1989 by Adam de Boor
10df930be7Sderaadt  * Copyright (c) 1989 by Berkeley Softworks
11df930be7Sderaadt  * All rights reserved.
12df930be7Sderaadt  *
13df930be7Sderaadt  * This code is derived from software contributed to Berkeley by
14df930be7Sderaadt  * Adam de Boor.
15df930be7Sderaadt  *
16df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
17df930be7Sderaadt  * modification, are permitted provided that the following conditions
18df930be7Sderaadt  * are met:
19df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
20df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
21df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
22df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
23df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
24f75387cbSmillert  * 3. Neither the name of the University nor the names of its contributors
25df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
26df930be7Sderaadt  *    without specific prior written permission.
27df930be7Sderaadt  *
28df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38df930be7Sderaadt  * SUCH DAMAGE.
39df930be7Sderaadt  *
40789486c7Smillert  *	from: @(#)dir.h 8.1 (Berkeley) 6/6/93
41df930be7Sderaadt  */
42df930be7Sderaadt 
43*1f89b472Sespie #include <sys/time.h>
44f7923656Sespie 
45f7923656Sespie /* dir --
46f7923656Sespie  *	Directory searching using wildcards and/or normal names...
47f7923656Sespie  *	Used both for source wildcarding in the Makefile and for finding
48f7923656Sespie  *	implicit sources.
49df930be7Sderaadt  */
50df930be7Sderaadt 
51f7923656Sespie /* Dir_Init()
52f7923656Sespie  *	Initialize the module.
53f7923656Sespie  */
5404ed836eSespie extern void Dir_Init(void);
55f7923656Sespie 
56f7923656Sespie /*
57f7923656Sespie  * Manipulating paths. By convention, the empty path always allows for
58f7923656Sespie  * finding files in the current directory.
59f7923656Sespie  */
60f7923656Sespie 
61f7923656Sespie /* Dir_AddDiri(path, name, end);
62f7923656Sespie  *	Add directory (name, end) to a search path.
63f7923656Sespie  */
64f7923656Sespie extern void Dir_AddDiri(Lst, const char *, const char *);
65f7923656Sespie #define Dir_AddDir(l, n)	Dir_AddDiri(l, n, NULL)
66f7923656Sespie 
67f7923656Sespie /* Dir_Concat(p1, p2);
68f7923656Sespie  *	Concatenate two paths, adding dirs in p2 to the end of p1, but
69f7923656Sespie  *	avoiding duplicates.
70f7923656Sespie  */
71f7923656Sespie extern void Dir_Concat(Lst, Lst);
72f7923656Sespie 
73f7923656Sespie /* Dir_Destroy(d);
74f7923656Sespie  *	Destroy a directory in a search path.
75f7923656Sespie  */
76f7923656Sespie extern void Dir_Destroy(void *);
77f7923656Sespie 
78f7923656Sespie /* p2 = Dir_CopyDir(p);
79f7923656Sespie  * 	Return a copy of a directory. Callback to duplicate search paths.
80f7923656Sespie  */
81f7923656Sespie extern void *Dir_CopyDir(void *);
82f7923656Sespie 
83f7923656Sespie /* Dir_PrintPath(p);
84f7923656Sespie  *	Print the directory names along a given path.
85f7923656Sespie  */
86f7923656Sespie extern void Dir_PrintPath(Lst);
87f7923656Sespie 
88f7923656Sespie 
89f7923656Sespie /*
90f7923656Sespie  * Handling file names, and looking them up in paths
91f7923656Sespie  */
92f7923656Sespie 
93018b58ecSespie /* fullname = Dir_FindFileComplexi(name, end, path, checkCurdirFirst)
94f7923656Sespie  *	Searches for a file (name, end) on a given search path.  If it exists,
95f7923656Sespie  *	return the fullname of the file, otherwise NULL.
96f7923656Sespie  *	The fullname is always a copy, and the caller is responsible for
97f7923656Sespie  *	free()ing it.
98018b58ecSespie  *	Looking for a simple name always looks in the current directory,
99018b58ecSespie  *	unless checkCurdirFirst is false.
100f7923656Sespie  *	For complex names, the current directory search only occurs for
101f7923656Sespie  *	paths with dot in them.
102f7923656Sespie  */
103018b58ecSespie extern char *Dir_FindFileComplexi(const char *, const char *, Lst, bool);
104018b58ecSespie #define Dir_FindFilei(n, e, p) Dir_FindFileComplexi(n, e, p, true)
105018b58ecSespie #define Dir_FindFileNoDoti(n, e, p) Dir_FindFileComplexi(n, e, p, false)
106018b58ecSespie #define Dir_FindFile(n, p) Dir_FindFilei(n, strchr(n, '\0'), p)
107018b58ecSespie #define Dir_FindFileNoDot(n, p) Dir_FindFileNoDoti(n, strchr(n, '\0'), p)
108f7923656Sespie 
109f7923656Sespie /* stamp = Dir_MTime(gn);
110f7923656Sespie  *	Return the modification time of node gn, searching along
111f7923656Sespie  *	the default search path.
112f7923656Sespie  *	Side effect: the path and mtime fields of gn are filled in.
113f7923656Sespie  *	Return specific value if file can't be found, to be tested by
114f7923656Sespie  *	is_out_of_date().
115f7923656Sespie  */
116*1f89b472Sespie extern struct timespec Dir_MTime(GNode *);
117f7923656Sespie 
118f7923656Sespie 
119f7923656Sespie 
120f7923656Sespie 
121f7923656Sespie /*
122f7923656Sespie  * Misc
123f7923656Sespie  */
124f7923656Sespie 
125f7923656Sespie /* List of directories to search when looking for targets. */
1262a514a5aSespie extern Lst	defaultPath;
127df930be7Sderaadt 
128267e030aSespie 
129267e030aSespie /* communication between dir.c and direxpand.c */
130ce889962Sespie struct PathEntry;
131ce889962Sespie extern struct PathEntry *dot;
132267e030aSespie /* Handles wildcard expansion on a given directory. */
133ce889962Sespie extern  void Dir_MatchFilesi(const char *, const char *, struct PathEntry *,
134267e030aSespie     Lst);
1356c2dbbdaSespie extern char *PathEntry_name(struct PathEntry *);
13604ed836eSespie #endif /* DIR_H */
137