util.h revision 143278
1100966Siwasaki/*-
2100966Siwasaki * Copyright (c) 1988, 1989, 1990, 1993
3100966Siwasaki *	The Regents of the University of California.  All rights reserved.
4100966Siwasaki * Copyright (c) 1989 by Berkeley Softworks
5100966Siwasaki * All rights reserved.
6100966Siwasaki *
7217365Sjkim * This code is derived from software contributed to Berkeley by
8217365Sjkim * Adam de Boor.
9100966Siwasaki *
10100966Siwasaki * Redistribution and use in source and binary forms, with or without
11217365Sjkim * modification, are permitted provided that the following conditions
12217365Sjkim * are met:
13217365Sjkim * 1. Redistributions of source code must retain the above copyright
14217365Sjkim *    notice, this list of conditions and the following disclaimer.
15217365Sjkim * 2. Redistributions in binary form must reproduce the above copyright
16217365Sjkim *    notice, this list of conditions and the following disclaimer in the
17217365Sjkim *    documentation and/or other materials provided with the distribution.
18217365Sjkim * 3. All advertising materials mentioning features or use of this software
19217365Sjkim *    must display the following acknowledgement:
20217365Sjkim *	This product includes software developed by the University of
21217365Sjkim *	California, Berkeley and its contributors.
22217365Sjkim * 4. Neither the name of the University nor the names of its contributors
23217365Sjkim *    may be used to endorse or promote products derived from this software
24217365Sjkim *    without specific prior written permission.
25100966Siwasaki *
26217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27217365Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28217365Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29100966Siwasaki * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30217365Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34217365Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35217365Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36217365Sjkim * SUCH DAMAGE.
37217365Sjkim *
38217365Sjkim * $FreeBSD: head/usr.bin/make/util.h 143278 2005-03-08 07:47:14Z harti $
39217365Sjkim */
40217365Sjkim
41217365Sjkim#ifndef util_h_b7020fdb
42217365Sjkim#define	util_h_b7020fdb
43100966Siwasaki
44100966Siwasaki#include <sys/types.h>
45193341Sjkim
46193341Sjkim#define	CONCAT(a,b)	a##b
47193341Sjkim
48193341Sjkim/*
49151937Sjkim * debug control:
50151937Sjkim *	There is one bit per module.  It is up to the module what debug
51193341Sjkim *	information to print.
52151937Sjkim */
53100966Siwasaki#define	DEBUG_ARCH	0x0001
54100966Siwasaki#define	DEBUG_COND	0x0002
55100966Siwasaki#define	DEBUG_DIR	0x0004
56102550Siwasaki#define	DEBUG_GRAPH1	0x0008
57100966Siwasaki#define	DEBUG_GRAPH2	0x0010
58100966Siwasaki#define	DEBUG_JOB	0x0020
59100966Siwasaki#define	DEBUG_MAKE	0x0040
60100966Siwasaki#define	DEBUG_SUFF	0x0080
61100966Siwasaki#define	DEBUG_TARG	0x0100
62167802Sjkim#define	DEBUG_VAR	0x0200
63100966Siwasaki#define	DEBUG_FOR	0x0400
64100966Siwasaki#define	DEBUG_LOUD	0x0800
65100966Siwasaki
66100966Siwasaki#define	DEBUG(module)	(debug & CONCAT(DEBUG_,module))
67100966Siwasaki#define	DEBUGF(module,args)		\
68100966Siwasakido {						\
69167802Sjkim	if (DEBUG(module)) {			\
70100966Siwasaki		Debug args ;			\
71167802Sjkim	}					\
72100966Siwasaki} while (0)
73100966Siwasaki#define	DEBUGM(module, args) do {		\
74100966Siwasaki	if (DEBUG(module)) {			\
75100966Siwasaki		DebugM args;			\
76100966Siwasaki	}					\
77100966Siwasaki    } while (0)
78100966Siwasaki
79100966Siwasaki#define	ISDOT(c) ((c)[0] == '.' && (((c)[1] == '\0') || ((c)[1] == '/')))
80100966Siwasaki#define	ISDOTDOT(c) ((c)[0] == '.' && ISDOT(&((c)[1])))
81100966Siwasaki
82100966Siwasakivoid Debug(const char *, ...);
83167802Sjkimvoid DebugM(const char *, ...);
84100966Siwasakivoid Error(const char *, ...);
85100966Siwasakivoid Fatal(const char *, ...) __dead2;
86100966Siwasakivoid Punt(const char *, ...) __dead2;
87100966Siwasakivoid DieHorribly(void) __dead2;
88100966Siwasakivoid Finish(int) __dead2;
89100966Siwasakichar *estrdup(const char *);
90100966Siwasakivoid *emalloc(size_t);
91167802Sjkimvoid *erealloc(void *, size_t);
92167802Sjkimint eunlink(const char *);
93100966Siwasaki
94100966Siwasaki#endif /* util_h_b7020fdb */
95100966Siwasaki