make.h revision 50477
11590Srgrimes/* 21590Srgrimes * Copyright (c) 1988, 1989, 1990, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * Copyright (c) 1989 by Berkeley Softworks 51590Srgrimes * All rights reserved. 61590Srgrimes * 71590Srgrimes * This code is derived from software contributed to Berkeley by 81590Srgrimes * Adam de Boor. 91590Srgrimes * 101590Srgrimes * Redistribution and use in source and binary forms, with or without 111590Srgrimes * modification, are permitted provided that the following conditions 121590Srgrimes * are met: 131590Srgrimes * 1. Redistributions of source code must retain the above copyright 141590Srgrimes * notice, this list of conditions and the following disclaimer. 151590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161590Srgrimes * notice, this list of conditions and the following disclaimer in the 171590Srgrimes * documentation and/or other materials provided with the distribution. 181590Srgrimes * 3. All advertising materials mentioning features or use of this software 191590Srgrimes * must display the following acknowledgement: 201590Srgrimes * This product includes software developed by the University of 211590Srgrimes * California, Berkeley and its contributors. 221590Srgrimes * 4. Neither the name of the University nor the names of its contributors 231590Srgrimes * may be used to endorse or promote products derived from this software 241590Srgrimes * without specific prior written permission. 251590Srgrimes * 261590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 271590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 301590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361590Srgrimes * SUCH DAMAGE. 371590Srgrimes * 3818730Ssteve * from: @(#)make.h 8.3 (Berkeley) 6/13/95 3950477Speter * $FreeBSD: head/usr.bin/make/make.h 50477 1999-08-28 01:08:13Z peter $ 401590Srgrimes */ 411590Srgrimes 421590Srgrimes/*- 431590Srgrimes * make.h -- 441590Srgrimes * The global definitions for pmake 451590Srgrimes */ 461590Srgrimes 471590Srgrimes#ifndef _MAKE_H_ 481590Srgrimes#define _MAKE_H_ 491590Srgrimes 501590Srgrimes#include <sys/types.h> 5149938Shoek#include <sys/param.h> 521590Srgrimes#include <stdio.h> 531590Srgrimes#include <string.h> 541590Srgrimes#include <ctype.h> 5549938Shoek 5649938Shoek#if !defined(MAKE_BOOTSTRAP) && defined(BSD4_4) 5749938Shoek# include <sys/cdefs.h> 585814Sjkh#else 5949938Shoek# ifndef __P 6049938Shoek# if defined(__STDC__) || defined(__cplusplus) 6149938Shoek# define __P(protos) protos /* full-blown ANSI C */ 6249938Shoek# else 6349938Shoek# define __P(protos) () /* traditional C preprocessor */ 6449938Shoek# endif 6549938Shoek# endif 6649938Shoek# ifndef __STDC__ 6749938Shoek# ifndef const 6849938Shoek# define const 6949938Shoek# endif 7049938Shoek# ifndef volatile 7149938Shoek# define volatile 7249938Shoek# endif 7349938Shoek# endif 745814Sjkh#endif 7549938Shoek 7649938Shoek#ifdef __STDC__ 771590Srgrimes#include <stdlib.h> 781590Srgrimes#include <unistd.h> 791590Srgrimes#endif 801590Srgrimes#include "sprite.h" 811590Srgrimes#include "lst.h" 821590Srgrimes#include "config.h" 831590Srgrimes#include "buf.h" 841590Srgrimes 851590Srgrimes/*- 861590Srgrimes * The structure for an individual graph node. Each node has several 871590Srgrimes * pieces of data associated with it. 881590Srgrimes * 1) the name of the target it describes 891590Srgrimes * 2) the location of the target file in the file system. 901590Srgrimes * 3) the type of operator used to define its sources (qv. parse.c) 911590Srgrimes * 4) whether it is involved in this invocation of make 921590Srgrimes * 5) whether the target has been remade 931590Srgrimes * 6) whether any of its children has been remade 941590Srgrimes * 7) the number of its children that are, as yet, unmade 951590Srgrimes * 8) its modification time 961590Srgrimes * 9) the modification time of its youngest child (qv. make.c) 971590Srgrimes * 10) a list of nodes for which this is a source 981590Srgrimes * 11) a list of nodes on which this depends 991590Srgrimes * 12) a list of nodes that depend on this, as gleaned from the 1001590Srgrimes * transformation rules. 1011590Srgrimes * 13) a list of nodes of the same name created by the :: operator 1021590Srgrimes * 14) a list of nodes that must be made (if they're made) before 1031590Srgrimes * this node can be, but that do no enter into the datedness of 1041590Srgrimes * this node. 1051590Srgrimes * 15) a list of nodes that must be made (if they're made) after 1061590Srgrimes * this node is, but that do not depend on this node, in the 1071590Srgrimes * normal sense. 1081590Srgrimes * 16) a Lst of ``local'' variables that are specific to this target 1091590Srgrimes * and this target only (qv. var.c [$@ $< $?, etc.]) 1101590Srgrimes * 17) a Lst of strings that are commands to be given to a shell 1118874Srgrimes * to create this target. 1121590Srgrimes */ 1131590Srgrimestypedef struct GNode { 1141590Srgrimes char *name; /* The target's name */ 1151590Srgrimes char *path; /* The full pathname of the file */ 1161590Srgrimes int type; /* Its type (see the OP flags, below) */ 11718730Ssteve int order; /* Its wait weight */ 1181590Srgrimes 1191590Srgrimes Boolean make; /* TRUE if this target needs to be remade */ 1201590Srgrimes enum { 1211590Srgrimes UNMADE, BEINGMADE, MADE, UPTODATE, ERROR, ABORTED, 12249938Shoek CYCLE, ENDCYCLE 1231590Srgrimes } made; /* Set to reflect the state of processing 1241590Srgrimes * on this node: 1251590Srgrimes * UNMADE - Not examined yet 1261590Srgrimes * BEINGMADE - Target is already being made. 1271590Srgrimes * Indicates a cycle in the graph. (compat 1281590Srgrimes * mode only) 1291590Srgrimes * MADE - Was out-of-date and has been made 1301590Srgrimes * UPTODATE - Was already up-to-date 1311590Srgrimes * ERROR - An error occured while it was being 1321590Srgrimes * made (used only in compat mode) 1331590Srgrimes * ABORTED - The target was aborted due to 1341590Srgrimes * an error making an inferior (compat). 1351590Srgrimes * CYCLE - Marked as potentially being part of 1361590Srgrimes * a graph cycle. If we come back to a 1371590Srgrimes * node marked this way, it is printed 1381590Srgrimes * and 'made' is changed to ENDCYCLE. 1391590Srgrimes * ENDCYCLE - the cycle has been completely 1401590Srgrimes * printed. Go back and unmark all its 1411590Srgrimes * members. 1421590Srgrimes */ 1431590Srgrimes Boolean childMade; /* TRUE if one of this target's children was 1441590Srgrimes * made */ 1451590Srgrimes int unmade; /* The number of unmade children */ 1461590Srgrimes 1471590Srgrimes int mtime; /* Its modification time */ 1481590Srgrimes int cmtime; /* The modification time of its youngest 1491590Srgrimes * child */ 1501590Srgrimes 1511590Srgrimes Lst iParents; /* Links to parents for which this is an 1521590Srgrimes * implied source, if any */ 1531590Srgrimes Lst cohorts; /* Other nodes for the :: operator */ 1541590Srgrimes Lst parents; /* Nodes that depend on this one */ 1551590Srgrimes Lst children; /* Nodes on which this one depends */ 1561590Srgrimes Lst successors; /* Nodes that must be made after this one */ 1571590Srgrimes Lst preds; /* Nodes that must be made before this one */ 1581590Srgrimes 1591590Srgrimes Lst context; /* The local variables */ 1601590Srgrimes Lst commands; /* Creation commands */ 1611590Srgrimes 1621590Srgrimes struct _Suff *suffix; /* Suffix for the node (determined by 1631590Srgrimes * Suff_FindDeps and opaque to everyone 1641590Srgrimes * but the Suff module) */ 1651590Srgrimes} GNode; 1661590Srgrimes 1671590Srgrimes/* 1688874Srgrimes * Manifest constants 1691590Srgrimes */ 1701590Srgrimes#define NILGNODE ((GNode *) NIL) 1711590Srgrimes 1721590Srgrimes/* 1731590Srgrimes * The OP_ constants are used when parsing a dependency line as a way of 1741590Srgrimes * communicating to other parts of the program the way in which a target 1751590Srgrimes * should be made. These constants are bitwise-OR'ed together and 1761590Srgrimes * placed in the 'type' field of each node. Any node that has 1771590Srgrimes * a 'type' field which satisfies the OP_NOP function was never never on 1781590Srgrimes * the lefthand side of an operator, though it may have been on the 1798874Srgrimes * righthand side... 1801590Srgrimes */ 1811590Srgrimes#define OP_DEPENDS 0x00000001 /* Execution of commands depends on 1821590Srgrimes * kids (:) */ 1831590Srgrimes#define OP_FORCE 0x00000002 /* Always execute commands (!) */ 1841590Srgrimes#define OP_DOUBLEDEP 0x00000004 /* Execution of commands depends on kids 1851590Srgrimes * per line (::) */ 1861590Srgrimes#define OP_OPMASK (OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP) 1871590Srgrimes 1881590Srgrimes#define OP_OPTIONAL 0x00000008 /* Don't care if the target doesn't 1891590Srgrimes * exist and can't be created */ 1901590Srgrimes#define OP_USE 0x00000010 /* Use associated commands for parents */ 1911590Srgrimes#define OP_EXEC 0x00000020 /* Target is never out of date, but always 1921590Srgrimes * execute commands anyway. Its time 1931590Srgrimes * doesn't matter, so it has none...sort 1941590Srgrimes * of */ 1951590Srgrimes#define OP_IGNORE 0x00000040 /* Ignore errors when creating the node */ 1961590Srgrimes#define OP_PRECIOUS 0x00000080 /* Don't remove the target when 1971590Srgrimes * interrupted */ 1981590Srgrimes#define OP_SILENT 0x00000100 /* Don't echo commands when executed */ 1991590Srgrimes#define OP_MAKE 0x00000200 /* Target is a recurrsive make so its 2001590Srgrimes * commands should always be executed when 2011590Srgrimes * it is out of date, regardless of the 2021590Srgrimes * state of the -n or -t flags */ 2031590Srgrimes#define OP_JOIN 0x00000400 /* Target is out-of-date only if any of its 2041590Srgrimes * children was out-of-date */ 2051590Srgrimes#define OP_INVISIBLE 0x00004000 /* The node is invisible to its parents. 2061590Srgrimes * I.e. it doesn't show up in the parents's 2071590Srgrimes * local variables. */ 2081590Srgrimes#define OP_NOTMAIN 0x00008000 /* The node is exempt from normal 'main 2091590Srgrimes * target' processing in parse.c */ 21018730Ssteve#define OP_PHONY 0x00010000 /* Not a file target; run always */ 2111590Srgrimes/* Attributes applied by PMake */ 2121590Srgrimes#define OP_TRANSFORM 0x80000000 /* The node is a transformation rule */ 2131590Srgrimes#define OP_MEMBER 0x40000000 /* Target is a member of an archive */ 2141590Srgrimes#define OP_LIB 0x20000000 /* Target is a library */ 2151590Srgrimes#define OP_ARCHV 0x10000000 /* Target is an archive construct */ 2161590Srgrimes#define OP_HAS_COMMANDS 0x08000000 /* Target has all the commands it should. 2171590Srgrimes * Used when parsing to catch multiple 2181590Srgrimes * commands for a target */ 2191590Srgrimes#define OP_SAVE_CMDS 0x04000000 /* Saving commands on .END (Compat) */ 2201590Srgrimes#define OP_DEPS_FOUND 0x02000000 /* Already processed by Suff_FindDeps */ 2211590Srgrimes 2221590Srgrimes/* 2231590Srgrimes * OP_NOP will return TRUE if the node with the given type was not the 2241590Srgrimes * object of a dependency operator 2251590Srgrimes */ 2261590Srgrimes#define OP_NOP(t) (((t) & OP_OPMASK) == 0x00000000) 2271590Srgrimes 2281590Srgrimes/* 2291590Srgrimes * The TARG_ constants are used when calling the Targ_FindNode and 2301590Srgrimes * Targ_FindList functions in targ.c. They simply tell the functions what to 2311590Srgrimes * do if the desired node(s) is (are) not found. If the TARG_CREATE constant 2321590Srgrimes * is given, a new, empty node will be created for the target, placed in the 2331590Srgrimes * table of all targets and its address returned. If TARG_NOCREATE is given, 2348874Srgrimes * a NIL pointer will be returned. 2351590Srgrimes */ 2361590Srgrimes#define TARG_CREATE 0x01 /* create node if not found */ 2371590Srgrimes#define TARG_NOCREATE 0x00 /* don't create it */ 2381590Srgrimes 2391590Srgrimes/* 2401590Srgrimes * There are several places where expandable buffers are used (parse.c and 2411590Srgrimes * var.c). This constant is merely the starting point for those buffers. If 2421590Srgrimes * lines tend to be much shorter than this, it would be best to reduce BSIZE. 2431590Srgrimes * If longer, it should be increased. Reducing it will cause more copying to 2441590Srgrimes * be done for longer lines, but will save space for shorter ones. In any 2451590Srgrimes * case, it ought to be a power of two simply because most storage allocation 2468874Srgrimes * schemes allocate in powers of two. 2471590Srgrimes */ 2481590Srgrimes#define MAKE_BSIZE 256 /* starting size for expandable buffers */ 2491590Srgrimes 2501590Srgrimes/* 2511590Srgrimes * These constants are all used by the Str_Concat function to decide how the 2521590Srgrimes * final string should look. If STR_ADDSPACE is given, a space will be 2531590Srgrimes * placed between the two strings. If STR_ADDSLASH is given, a '/' will 2541590Srgrimes * be used instead of a space. If neither is given, no intervening characters 2551590Srgrimes * will be placed between the two strings in the final output. If the 2561590Srgrimes * STR_DOFREE bit is set, the two input strings will be freed before 2578874Srgrimes * Str_Concat returns. 2581590Srgrimes */ 2591590Srgrimes#define STR_ADDSPACE 0x01 /* add a space when Str_Concat'ing */ 2601590Srgrimes#define STR_DOFREE 0x02 /* free source strings after concatenation */ 2611590Srgrimes#define STR_ADDSLASH 0x04 /* add a slash when Str_Concat'ing */ 2621590Srgrimes 2631590Srgrimes/* 2641590Srgrimes * Error levels for parsing. PARSE_FATAL means the process cannot continue 2651590Srgrimes * once the makefile has been parsed. PARSE_WARNING means it can. Passed 2661590Srgrimes * as the first argument to Parse_Error. 2671590Srgrimes */ 2681590Srgrimes#define PARSE_WARNING 2 2691590Srgrimes#define PARSE_FATAL 1 2701590Srgrimes 2711590Srgrimes/* 2721590Srgrimes * Values returned by Cond_Eval. 2731590Srgrimes */ 2741590Srgrimes#define COND_PARSE 0 /* Parse the next lines */ 2751590Srgrimes#define COND_SKIP 1 /* Skip the next lines */ 2761590Srgrimes#define COND_INVALID 2 /* Not a conditional statement */ 2771590Srgrimes 2781590Srgrimes/* 2791590Srgrimes * Definitions for the "local" variables. Used only for clarity. 2801590Srgrimes */ 2811590Srgrimes#define TARGET "@" /* Target of dependency */ 2821590Srgrimes#define OODATE "?" /* All out-of-date sources */ 2831590Srgrimes#define ALLSRC ">" /* All sources */ 2841590Srgrimes#define IMPSRC "<" /* Source implied by transformation */ 2851590Srgrimes#define PREFIX "*" /* Common prefix */ 2861590Srgrimes#define ARCHIVE "!" /* Archive in "archive(member)" syntax */ 2871590Srgrimes#define MEMBER "%" /* Member in "archive(member)" syntax */ 2881590Srgrimes 2891590Srgrimes#define FTARGET "@F" /* file part of TARGET */ 2901590Srgrimes#define DTARGET "@D" /* directory part of TARGET */ 2911590Srgrimes#define FIMPSRC "<F" /* file part of IMPSRC */ 2921590Srgrimes#define DIMPSRC "<D" /* directory part of IMPSRC */ 2931590Srgrimes#define FPREFIX "*F" /* file part of PREFIX */ 2941590Srgrimes#define DPREFIX "*D" /* directory part of PREFIX */ 2951590Srgrimes 2961590Srgrimes/* 2978874Srgrimes * Global Variables 2981590Srgrimes */ 2991590Srgrimesextern Lst create; /* The list of target names specified on the 3001590Srgrimes * command line. used to resolve #if 3011590Srgrimes * make(...) statements */ 3021590Srgrimesextern Lst dirSearchPath; /* The list of directories to search when 3031590Srgrimes * looking for targets */ 3041590Srgrimes 3051590Srgrimesextern Boolean compatMake; /* True if we are make compatible */ 3061590Srgrimesextern Boolean ignoreErrors; /* True if should ignore all errors */ 3071590Srgrimesextern Boolean beSilent; /* True if should print no commands */ 30841151Sdgextern Boolean beVerbose; /* True if should print extra cruft */ 3091590Srgrimesextern Boolean noExecute; /* True if should execute nothing */ 3101590Srgrimesextern Boolean allPrecious; /* True if every target is precious */ 3111590Srgrimesextern Boolean keepgoing; /* True if should continue on unaffected 3121590Srgrimes * portions of the graph when have an error 3131590Srgrimes * in one portion */ 3141590Srgrimesextern Boolean touchFlag; /* TRUE if targets should just be 'touched' 3151590Srgrimes * if out of date. Set by the -t flag */ 3161590Srgrimesextern Boolean usePipes; /* TRUE if should capture the output of 3171590Srgrimes * subshells by means of pipes. Otherwise it 3181590Srgrimes * is routed to temporary files from which it 3191590Srgrimes * is retrieved when the shell exits */ 3201590Srgrimesextern Boolean queryFlag; /* TRUE if we aren't supposed to really make 3211590Srgrimes * anything, just see if the targets are out- 3221590Srgrimes * of-date */ 3231590Srgrimes 3241590Srgrimesextern Boolean checkEnvFirst; /* TRUE if environment should be searched for 32549332Shoek * all variables before the global context */ 32649332Shoekextern Lst envFirstVars; /* List of specific variables for which the 32749332Shoek * environment should be searched before the 32849332Shoek * global context */ 3291590Srgrimes 3301590Srgrimesextern GNode *DEFAULT; /* .DEFAULT rule */ 3311590Srgrimes 3321590Srgrimesextern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g 3331590Srgrimes * in the Makefile itself */ 3341590Srgrimesextern GNode *VAR_CMD; /* Variables defined on the command line */ 3351590Srgrimesextern char var_Error[]; /* Value returned by Var_Parse when an error 3361590Srgrimes * is encountered. It actually points to 3371590Srgrimes * an empty string, so naive callers needn't 3381590Srgrimes * worry about it. */ 3391590Srgrimes 3401590Srgrimesextern time_t now; /* The time at the start of this whole 3411590Srgrimes * process */ 3421590Srgrimes 3431590Srgrimesextern Boolean oldVars; /* Do old-style variable substitution */ 3441590Srgrimes 34518730Ssteveextern Lst sysIncPath; /* The system include path. */ 34618730Ssteve 3471590Srgrimes/* 3481590Srgrimes * debug control: 3491590Srgrimes * There is one bit per module. It is up to the module what debug 3501590Srgrimes * information to print. 3511590Srgrimes */ 3521590Srgrimesextern int debug; 3531590Srgrimes#define DEBUG_ARCH 0x0001 3541590Srgrimes#define DEBUG_COND 0x0002 3551590Srgrimes#define DEBUG_DIR 0x0004 3561590Srgrimes#define DEBUG_GRAPH1 0x0008 3571590Srgrimes#define DEBUG_GRAPH2 0x0010 3581590Srgrimes#define DEBUG_JOB 0x0020 3591590Srgrimes#define DEBUG_MAKE 0x0040 3601590Srgrimes#define DEBUG_SUFF 0x0080 3611590Srgrimes#define DEBUG_TARG 0x0100 3621590Srgrimes#define DEBUG_VAR 0x0200 3631590Srgrimes#define DEBUG_FOR 0x0400 3641590Srgrimes 3651590Srgrimes#ifdef __STDC__ 3661590Srgrimes#define CONCAT(a,b) a##b 3671590Srgrimes#else 3681590Srgrimes#define I(a) a 3691590Srgrimes#define CONCAT(a,b) I(a)b 3701590Srgrimes#endif /* __STDC__ */ 3711590Srgrimes 3721590Srgrimes#define DEBUG(module) (debug & CONCAT(DEBUG_,module)) 3731590Srgrimes 3741590Srgrimes/* 3751590Srgrimes * Since there are so many, all functions that return non-integer values are 3761590Srgrimes * extracted by means of a sed script or two and stuck in the file "nonints.h" 3771590Srgrimes */ 3781590Srgrimes#include "nonints.h" 3791590Srgrimes 3805814Sjkhint Make_TimeStamp __P((GNode *, GNode *)); 3815814SjkhBoolean Make_OODate __P((GNode *)); 3825814Sjkhint Make_HandleUse __P((GNode *, GNode *)); 3835814Sjkhvoid Make_Update __P((GNode *)); 3845814Sjkhvoid Make_DoAllVar __P((GNode *)); 3855814SjkhBoolean Make_Run __P((Lst)); 3861590Srgrimes 3871590Srgrimes#endif /* _MAKE_H_ */ 388