10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER START
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The contents of this file are subject to the terms of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Common Development and Distribution License (the "License").
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You may not use this file except in compliance with the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * See the License for the specific language governing permissions
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and limitations under the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * When distributing Covered Code, include this CDDL HEADER in each
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If applicable, add the following below this CDDL HEADER, with the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER END
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * A type and some utilities for boolean values
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef enum {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Some random constants (in an enum so dbx knows their values)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe update_delay = 30, /* time between rstat checks */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Symbols that defines all the different char constants make uses
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For make i18n. Codeset independent.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Setup character semantics by identifying all the special characters
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * of make, and assigning each an entry in the char_semantics[] vector.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CHAR_SEMANTICS_ENTRIES should be the number of entries above.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The last entry in char_semantics[] should be blank.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define CHAR_SEMANTICS_STRING "&*@`\\|[]:$=!>-\n#()%+?;^<'\""
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Some utility macros
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define ALLOC(x) ((struct _##x *)getmem(sizeof (struct _##x)))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define ALLOC_WC(x) ((wchar_t *)getmem((x) * SIZEOFWCHAR_T))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define GETNAME(a,b) getname_fn((a), (b), false)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define IS_EQUALN(a,b,n) (!strncmp((a), (b), (n)))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define IS_WEQUALN(a,b,n) (!wcsncmp((a), (b), (n)))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define MBSTOWCS(a,b) (void) mbstowcs_with_check((a), (b), MAXPATHLEN)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define MBTOWC(a,b) mbtowc((a), (b), MB_LEN_MAX)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define VSIZEOF(v) (sizeof (v) / sizeof ((v)[0]))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define WCSTOMBS(a,b) (void) wcstombs((a), (b), (MAXPATHLEN * MB_LEN_MAX))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define HASH(v, c) (v = (v)*31 + (unsigned int)(c))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern void mbstowcs_with_check(wchar_t *pwcs, const char *s, size_t n);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Bits stored in funny vector to classify chars
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Type returned from doname class functions
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef enum {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The String struct defines a string with the following layout
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * "xxxxxxxxxxxxxxxCxxxxxxxxxxxxxxx________"
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * buffer.start text.p text.end buffer.end
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * text.p points to the next char to read/write.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *start; /* Points to start of buffer */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define APPEND_NAME(np, dest, len) append_string((np)->string_mb, (dest), (len));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe void append_to_str(struct _String * str, unsigned off, unsigned length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean equaln(wchar_t * str, unsigned length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean equal(wchar_t * str, unsigned off, unsigned length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean equaln(Wstring * str, unsigned length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean equal(Wstring * str, unsigned off, unsigned length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Used for storing the $? list and also for the "target + target:"
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * construct.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Stores one command line for a rule
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Remember any command line prefixes given
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Linked list of targets/files
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The specials are markers for targets that the reader should special case
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef enum {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef enum {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Magic values for the timestamp stored with each name object
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Each Name has a list of properties
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The properties are used to store information that only
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a subset of the Names need
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef enum {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef enum {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For "ABC = xyz" constructs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Name "ABC" get one macro prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This macro is defined conditionally
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The list for $? is stored as a structured list that
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is translated into a string iff it is referenced.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This is why some macro values need a daemon.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe struct _Property *prop; /* List of properties */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Count instances of :: definitions for this target
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We only clear the automatic depes once per target per report
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Count how many conditional macros this target has defined
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * A conditional macro was used when building this target
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Pointer to list of conditional macros which were used to build
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * this target
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This target is a directory that has been read
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This name is a macro that is now being expanded
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This name is a magic name that the reader must know about
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This target has been built during this make run
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean without_squiggle:1; /* for .SUFFIXES */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean has_read_suffixes:1; /* Suffix list cached*/
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean dependency_printed:1; /* For dump_make_state() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * allowed to run in parallel
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * not allowed to run in parallel
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * used in dependency_conflict
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * rechecking target for possible rebuild
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * build this target in silent mode
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * build this target in ignore error mode
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * allowed to run serially on local host
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Stores the % matched default rules
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For "foo := ABC [+]= xyz" constructs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Name "foo" gets one conditional prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For "target : dependencies" constructs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Name "target" gets one line prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Values for the dynamic macros
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Names that reference makefiles gets one prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For "lib(member)" and "lib((entry))" constructs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Name "lib(member)" gets one member prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Name "lib((entry))" gets one member prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The member field is filled in when the prop is refd
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For "target: .RECURSIVE dir makefiles" constructs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Used to keep track of recursive calls to make
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Name "target" gets one recursive prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Each file that has a SCCS s. file gets one prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Cached list of suffixes that can build this target
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * suffix is built from .SUFFIXES
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For "target:: dependencies" constructs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The "::" construct is handled by converting it to
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * "foo: 1@foo" + "1@foo: dependecies"
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * "1@foo" gets one target prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This target prop cause $@ to be bound to "foo"
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * not "1@foo" when the rule is evaluated
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Save the original time for :: targets
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If a file was found using the VPATH it gets
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a vpath_alias prop
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Targets with a truncated member name carries
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the full lib(member) name for the state file
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define PROPERTY_HEAD_SIZE (sizeof (struct _Property)-sizeof (union Body))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Structure for dynamic "ascii" arrays */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Macros for the reader
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define SET_STATE(new_state) state = (new_state)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define UNCACHE_SOURCE() if (source != NULL) { \
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define CACHE_SOURCE(comp) if (source != NULL) { \
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define GET_NEXT_BLOCK_NOCHK(source) { UNCACHE_SOURCE(); \
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define GET_NEXT_BLOCK(source) { GET_NEXT_BLOCK_NOCHK(source); \
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (source != NULL && source->error_converting) { \
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef enum {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Typedefs for all structs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef struct _Macro_list *Macro_list, Macro_list_rec;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef struct _Property *Property, Property_rec;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * name records hash table.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // single node in a tree
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe unsigned rdepth = (right != 0) ? right->depth : 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe unsigned ldepth = (left != 0) ? left->depth : 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depth = 1 + ((ldepth > rdepth) ? ldepth : rdepth);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // make iterator a friend of Name_set to have access to struct entry
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // iterator over tree nodes
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // constructors
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // dereference operator
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // conversion operator
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // assignment operator
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe iterator& operator=(const iterator &o) { node = o.node; return *this; }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int operator==(const iterator &o) const { return (node == o.node); }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int operator!=(const iterator &o) const { return (node != o.node); }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // pre/post increment operators
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe iterator operator++(int) { iterator it = *this; ++*this; return it; }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // the node iterator points to
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // constructor
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // lookup, insert and remove operations
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // begin/end iterators
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // rebalance given node
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // tree root
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * extern declarations for all global variables.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The actual declarations are in globals.cc
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern char **environ;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Variable gnu_style=true if env. var. SUN_MAKE_COMPAT_MODE=GNU (RFE 4866328) */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * RFE 1257407: make does not use fine granularity time info available from stat.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * High resolution time comparison.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweoperator==(const timestruc_t &t1, const timestruc_t &t2) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return ((t1.tv_sec == t2.tv_sec) && (t1.tv_nsec == t2.tv_nsec));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweoperator!=(const timestruc_t &t1, const timestruc_t &t2) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return ((t1.tv_sec != t2.tv_sec) || (t1.tv_nsec != t2.tv_nsec));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweoperator>(const timestruc_t &t1, const timestruc_t &t2) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweoperator>=(const timestruc_t &t1, const timestruc_t &t2) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweoperator<(const timestruc_t &t1, const timestruc_t &t2) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweoperator<=(const timestruc_t &t1, const timestruc_t &t2) {