1 #ifndef _MK_DEFS_H
   2 #define _MK_DEFS_H
   3 /*
   4  * CDDL HEADER START
   5  *
   6  * The contents of this file are subject to the terms of the
   7  * Common Development and Distribution License (the "License").
   8  * You may not use this file except in compliance with the License.
   9  *
  10  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  11  * or http://www.opensolaris.org/os/licensing.
  12  * See the License for the specific language governing permissions
  13  * and limitations under the License.
  14  *
  15  * When distributing Covered Code, include this CDDL HEADER in each
  16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  17  * If applicable, add the following below this CDDL HEADER, with the
  18  * fields enclosed by brackets "[]" replaced with your own identifying
  19  * information: Portions Copyright [yyyy] [name of copyright owner]
  20  *
  21  * CDDL HEADER END
  22  */
  23 /*
  24  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 /*
  29  * Included files
  30  */
  31 
  32 #include <mksh/defs.h>
  33 
  34 
  35 
  36 /*
  37  * Defined macros
  38  */
  39 
  40 #define SKIPSPACE(x)    while (*x &&                            \
  41                                ((*x == (int) space_char) ||     \
  42                                 (*x == (int) tab_char) ||       \
  43                                 (*x == (int) comma_char))) {    \
  44                                         x++;                    \
  45                         }
  46 
  47 #define SKIPWORD(x)     while (*x &&                            \
  48                                (*x != (int) space_char) &&      \
  49                                (*x != (int) tab_char) &&        \
  50                                (*x != (int) newline_char) &&    \
  51                                (*x != (int) comma_char) &&      \
  52                                (*x != (int) equal_char)) {      \
  53                                         x++;                    \
  54                         }
  55 
  56 #define SKIPTOEND(x)    while (*x &&                            \
  57                                (*x != (int) newline_char)) {    \
  58                                         x++;                    \
  59                         }
  60 
  61 #define PMAKE_DEF_MAX_JOBS      2       /* Default number of parallel jobs. */
  62 
  63 #define OUT_OF_DATE(a,b) \
  64         (((a) < (b)) || (((a) == file_doesnt_exist) && ((b) == file_doesnt_exist)))
  65 
  66 #define OUT_OF_DATE_SEC(a,b) \
  67         (((a).tv_sec < (b).tv_sec) || (((a).tv_sec == file_doesnt_exist.tv_sec) && ((b).tv_sec == file_doesnt_exist.tv_sec)))
  68 
  69 #define SETVAR(name, value, append) \
  70                                 setvar_daemon(name, value, append, no_daemon, \
  71                                               true, debug_level)
  72 #define MAX(a,b)                (((a)>(b))?(a):(b))
  73 /*
  74  * New feature added to SUN5_0 make,  invoke the vanilla svr4 make when
  75  * the USE_SVR4_MAKE environment variable is set.
  76  */
  77 #define SVR4_MAKE               "/usr/ccs/lib/svr4.make"
  78 #define USE_SVR4_MAKE           "USE_SVR4_MAKE"
  79 /*
  80  * The standard MAXHOSTNAMELEN is 64. We want 32.
  81  */
  82 #define MAX_HOSTNAMELEN         32
  83 
  84 
  85 /*
  86  * typedefs & structs
  87  */
  88 typedef enum {
  89         no_state,
  90         scan_name_state,
  91         scan_command_state,
  92         enter_dependencies_state,
  93         enter_conditional_state,
  94         enter_equal_state,
  95         illegal_bytes_state,
  96         illegal_eoln_state,
  97         poorly_formed_macro_state,
  98         exit_state
  99 }                       Reader_state;
 100 
 101 struct _Name_vector {
 102         struct _Name            *names[64];
 103         struct _Chain           *target_group[64];
 104         short                   used;
 105         struct _Name_vector     *next;
 106 };
 107 
 108 struct _Running {
 109         struct _Running         *next;
 110         Doname                  state;
 111         struct _Name            *target;
 112         struct _Name            *true_target;
 113         struct _Property        *command;
 114         struct _Name            *sprodep_value;
 115         char                    *sprodep_env;
 116         int                     recursion_level;
 117         Boolean                 do_get;
 118         Boolean                 implicit;
 119         Boolean                 redo;
 120         int                     auto_count;
 121         struct _Name            **automatics;
 122         pid_t                   pid;
 123         int                     job_msg_id;
 124         char                    *stdout_file;
 125         char                    *stderr_file;
 126         struct _Name            *temp_file;
 127         int                     conditional_cnt;
 128         struct _Name            **conditional_targets;
 129         Boolean                 make_refd;
 130 };
 131 
 132 typedef enum {
 133         serial_mode,
 134         parallel_mode,
 135         distributed_mode
 136 } DMake_mode;
 137 
 138 typedef enum {
 139         txt1_mode,
 140         txt2_mode,
 141         html1_mode
 142 } DMake_output_mode;
 143 
 144 struct _Recursive_make {
 145         struct _Recursive_make  *next;  /* Linked list */
 146         wchar_t                 *target;/* Name of target */
 147         wchar_t                 *oldline;/* Original line in .nse_depinfo */
 148         wchar_t                 *newline;/* New line in .nse_depinfo */
 149         wchar_t                 *cond_macrostring;
 150                                         /* string built from value of
 151                                          * conditional macros used by
 152                                          * this target
 153                                          */
 154         Boolean                 removed;/* This target is no longer recursive*/
 155 };
 156 
 157 struct _Dyntarget {
 158         struct _Dyntarget       *next;
 159         struct _Name            *name;
 160 };
 161 
 162 
 163 /*
 164  * Typedefs for all structs
 165  */
 166 typedef struct _Cmd_line        *Cmd_line, Cmd_line_rec;
 167 typedef struct _Dependency      *Dependency, Dependency_rec;
 168 typedef struct _Macro           *Macro, Macro_rec;
 169 typedef struct _Name_vector     *Name_vector, Name_vector_rec;
 170 typedef struct _Percent         *Percent, Percent_rec;
 171 typedef struct _Dyntarget       *Dyntarget;
 172 typedef struct _Recursive_make  *Recursive_make, Recursive_make_rec;
 173 typedef struct _Running         *Running, Running_rec;
 174 
 175 
 176 /*
 177  *      extern declarations for all global variables.
 178  *      The actual declarations are in globals.cc
 179  */
 180 extern  Boolean         allrules_read;
 181 extern  Name            posix_name;
 182 extern  Name            svr4_name;
 183 extern  Boolean         sdot_target;
 184 extern  Boolean         all_parallel;
 185 extern  Boolean         assign_done;
 186 extern  Boolean         build_failed_seen;
 187 extern  Name            built_last_make_run;
 188 extern  Name            c_at;
 189 extern  Boolean         command_changed;
 190 extern  Boolean         commands_done;
 191 extern  Chain           conditional_targets;
 192 extern  Name            conditionals;
 193 extern  Boolean         continue_after_error;
 194 extern  Property        current_line;
 195 extern  Name            current_make_version;
 196 extern  Name            current_target;
 197 extern  short           debug_level;
 198 extern  Cmd_line        default_rule;
 199 extern  Name            default_rule_name;
 200 extern  Name            default_target_to_build;
 201 extern  Boolean         depinfo_already_read;
 202 extern  Name            dmake_group;
 203 extern  Name            dmake_max_jobs;
 204 extern  Name            dmake_mode;
 205 extern  DMake_mode      dmake_mode_type;
 206 extern  Name            dmake_output_mode;
 207 extern  DMake_output_mode       output_mode;
 208 extern  Name            dmake_odir;
 209 extern  Name            dmake_rcfile;
 210 extern  Name            done;
 211 extern  Name            dot;
 212 extern  Name            dot_keep_state;
 213 extern  Name            dot_keep_state_file;
 214 extern  Name            empty_name;
 215 extern  Boolean         fatal_in_progress;
 216 extern  int             file_number;
 217 extern  Name            force;
 218 extern  Name            ignore_name;
 219 extern  Boolean         ignore_errors;
 220 extern  Boolean         ignore_errors_all;
 221 extern  Name            init;
 222 extern  int             job_msg_id;
 223 extern  Boolean         keep_state;
 224 extern  Name            make_state;
 225 extern  timestruc_t     make_state_before;
 226 extern  Boolean         make_state_locked;
 227 extern  Dependency      makefiles_used;
 228 extern  Name            makeflags;
 229 extern  Name            make_version;
 230 extern  char            mbs_buffer2[];
 231 extern  char            *mbs_ptr;
 232 extern  char            *mbs_ptr2;
 233 extern  Boolean         no_action_was_taken;
 234 extern  int             mtool_msgs_fd;
 235 extern  Boolean         no_parallel;
 236 extern  Name            no_parallel_name;
 237 extern  Name            not_auto;
 238 extern  Boolean         only_parallel;
 239 extern  Boolean         parallel;
 240 extern  Name            parallel_name;
 241 extern  Name            localhost_name;
 242 extern  int             parallel_process_cnt;
 243 extern  Percent         percent_list;
 244 extern  Dyntarget       dyntarget_list;
 245 extern  Name            plus;
 246 extern  Name            pmake_machinesfile;
 247 extern  Name            precious;
 248 extern  Name            primary_makefile;
 249 extern  Boolean         quest;
 250 extern  short           read_trace_level;
 251 extern  Boolean         reading_dependencies;
 252 extern  int             recursion_level;
 253 extern  Name            recursive_name;
 254 extern  short           report_dependencies_level;
 255 extern  Boolean         report_pwd;
 256 extern  Boolean         rewrite_statefile;
 257 extern  Running         running_list;
 258 extern  char            *sccs_dir_path;
 259 extern  Name            sccs_get_name;
 260 extern  Name            sccs_get_posix_name;
 261 extern  Cmd_line        sccs_get_rule;
 262 extern  Cmd_line        sccs_get_org_rule;
 263 extern  Cmd_line        sccs_get_posix_rule;
 264 extern  Name            get_name;
 265 extern  Name            get_posix_name;
 266 extern  Cmd_line        get_rule;
 267 extern  Cmd_line        get_posix_rule;
 268 extern  Boolean         send_mtool_msgs;
 269 extern  Boolean         all_precious;
 270 extern  Boolean         report_cwd;
 271 extern  Boolean         silent_all;
 272 extern  Boolean         silent;
 273 extern  Name            silent_name;
 274 extern  char            *stderr_file;
 275 extern  char            *stdout_file;
 276 extern  Boolean         stdout_stderr_same;
 277 extern  Dependency      suffixes;
 278 extern  Name            suffixes_name;
 279 extern  Name            sunpro_dependencies;
 280 extern  Boolean         target_variants;
 281 extern  const char      *tmpdir;
 282 extern  const char      *temp_file_directory;
 283 extern  Name            temp_file_name;
 284 extern  short           temp_file_number;
 285 extern  wchar_t         *top_level_target;
 286 extern  Boolean         touch;
 287 extern  Boolean         trace_reader;
 288 extern  Boolean         build_unconditional;
 289 extern  pathpt          vroot_path;
 290 extern  Name            wait_name;
 291 extern  wchar_t         wcs_buffer2[];
 292 extern  wchar_t         *wcs_ptr;
 293 extern  wchar_t         *wcs_ptr2;
 294 extern  nl_catd         catd;
 295 extern  long int        hostid;
 296 
 297 /*
 298  * Declarations of system defined variables
 299  */
 300 /* On linux this variable is defined in 'signal.h' */
 301 extern  char            *sys_siglist[];
 302 
 303 /*
 304  * Declarations of system supplied functions
 305  */
 306 extern  int             file_lock(char *, char *, int *, int);
 307 
 308 /*
 309  * Declarations of functions declared and used by make
 310  */
 311 extern  void            add_pending(Name target, int recursion_level, Boolean do_get, Boolean implicit, Boolean redo);
 312 extern  void            add_running(Name target, Name true_target, Property command, int recursion_level, int auto_count, Name *automatics, Boolean do_get, Boolean implicit);
 313 extern  void            add_serial(Name target, int recursion_level, Boolean do_get, Boolean implicit);
 314 extern  void            add_subtree(Name target, int recursion_level, Boolean do_get, Boolean implicit);
 315 extern  void            append_or_replace_macro_in_dyn_array(ASCII_Dyn_Array *Ar, char *macro);
 316 extern  void            await_parallel(Boolean waitflg);
 317 extern  void            build_suffix_list(Name target_suffix);
 318 extern  Boolean         check_auto_dependencies(Name target, int auto_count, Name *automatics);
 319 extern  void            check_state(Name temp_file_name);
 320 extern  void            cond_macros_into_string(Name np, String_rec *buffer);
 321 extern  void            construct_target_string();
 322 extern  void            create_xdrs_ptr(void);
 323 extern  void            depvar_add_to_list (Name name, Boolean cmdline);
 324 extern  Doname          doname(register Name target, register Boolean do_get, register Boolean implicit, register Boolean automatic = false);
 325 extern  Doname          doname_check(register Name target, register Boolean do_get, register Boolean implicit, register Boolean automatic);
 326 extern  Doname          doname_parallel(Name target, Boolean do_get, Boolean implicit);
 327 extern  Doname          dosys(register Name command, register Boolean ignore_error, register Boolean call_make, Boolean silent_error, Boolean always_exec, Name target, Boolean redirect_out_err);
 328 extern  void            dump_make_state(void);
 329 extern  void            dump_target_list(void);
 330 extern  void            enter_conditional(register Name target, Name name, Name value, register Boolean append);
 331 extern  void            enter_dependencies(register Name target, Chain target_group, register Name_vector depes, register Cmd_line command, register Separator separator);
 332 extern  void            enter_dependency(Property line, register Name depe, Boolean automatic);
 333 extern  void            enter_equal(Name name, Name value, register Boolean append);
 334 extern  Percent         enter_percent(register Name target, Chain target_group, register Name_vector depes, Cmd_line command);
 335 extern  Dyntarget       enter_dyntarget(register Name target);
 336 extern  Name_vector     enter_name(String string, Boolean tail_present, register wchar_t *string_start, register wchar_t *string_end, Name_vector current_names, Name_vector *extra_names, Boolean *target_group_seen);
 337 extern  Boolean         exec_vp(register char *name, register char **argv, char **envp, register Boolean ignore_error);
 338 extern  Doname          execute_parallel(Property line, Boolean waitflg, Boolean local = false);
 339 extern  Doname          execute_serial(Property line);
 340 extern  timestruc_t&        exists(register Name target);
 341 extern  void            fatal(const char *, ...);
 342 extern  void            fatal_reader(char *, ...);
 343 extern  Doname          find_ar_suffix_rule(register Name target, Name true_target, Property *command, Boolean rechecking);
 344 extern  Doname          find_double_suffix_rule(register Name target, Property *command, Boolean rechecking);
 345 extern  Doname          find_percent_rule(register Name target, Property *command, Boolean rechecking);
 346 extern  int             find_run_directory (char *cmd, char *cwd, char *dir, char **pgm, char **run, char *path);
 347 extern  Doname          find_suffix_rule(Name target, Name target_body, Name target_suffix, Property *command, Boolean rechecking);
 348 extern  Chain           find_target_groups(register Name_vector target_list, register int i, Boolean reset);
 349 extern  void            finish_children(Boolean docheck);
 350 extern  void            finish_running(void);
 351 extern  void            free_chain(Name_vector ptr);
 352 extern  void            gather_recursive_deps(void);
 353 extern  char            *get_current_path(void);
 354 extern  int             get_job_msg_id(void);
 355 extern  FILE            *get_mtool_msgs_fp(void);
 356 extern  wchar_t         *getmem_wc(register int size);
 357 /* On linux getwd(char *) is defined in 'unistd.h' */
 358 #ifdef __cplusplus
 359 extern "C" {
 360 #endif
 361 extern  char            *getwd(char *);
 362 #ifdef __cplusplus
 363 }
 364 #endif
 365 extern  void            handle_interrupt(int);
 366 extern  Boolean         is_running(Name target);
 367 extern  void            load_cached_names(void);
 368 extern  Boolean         parallel_ok(Name target, Boolean line_prop_must_exists);
 369 extern  void            print_dependencies(register Name target, register Property line);
 370 extern  void            send_job_start_msg(Property line);
 371 extern  void            send_rsrc_info_msg(int max_jobs, char *hostname, char *username);
 372 extern  void            print_value(register Name value, Daemon daemon);
 373 extern  timestruc_t&        read_archive(register Name target);
 374 extern  int             read_dir(Name dir, wchar_t *pattern, Property line, wchar_t *library);
 375 extern  void            read_directory_of_file(register Name file);
 376 extern  int             read_make_machines(Name make_machines_name);
 377 extern  Boolean         read_simple_file(register Name makefile_name, register Boolean chase_path, register Boolean doname_it, Boolean complain, Boolean must_exist, Boolean report_file, Boolean lock_makefile);
 378 extern  void            remove_recursive_dep(Name target);
 379 extern  void            report_recursive_dep(Name target, char *line);
 380 extern  void            report_recursive_done(void);
 381 extern  void            report_recursive_init(void);
 382 extern  Recursive_make  find_recursive_target(Name target);
 383 extern  void            reset_locals(register Name target, register Property old_locals, register Property conditional, register int index);
 384 extern  void            set_locals(register Name target, register Property old_locals);
 385 extern  void            setvar_append(register Name name, register Name value);
 386 extern  void            setvar_envvar(void);
 387 extern  void            special_reader(Name target, register Name_vector depes, Cmd_line command);
 388 extern  void            startup_rxm();
 389 extern  Doname          target_can_be_built(register Name target);
 390 extern  char            *time_to_string(const timestruc_t &time);
 391 extern  void            update_target(Property line, Doname result);
 392 extern  void            warning(char *, ...);
 393 extern  void            write_state_file(int report_recursive, Boolean exiting);
 394 extern  Name            vpath_translation(register Name cmd);
 395 
 396 #define DEPINFO_FMT_VERSION "VERS2$"
 397 #define VER_LEN strlen(DEPINFO_FMT_VERSION)
 398 
 399 
 400 #endif