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  * @(#)defs.h 1.61 06/12/12
  29  */
  30 
  31 #pragma ident   "@(#)defs.h     1.61    06/12/12"
  32 
  33 /*
  34  * Included files
  35  */
  36 #ifdef DISTRIBUTED
  37 #       include <dm/Avo_AcknowledgeMsg.h>
  38 #       include <dm/Avo_DoJobMsg.h>
  39 #       include <dm/Avo_JobResultMsg.h>
  40 #endif
  41 
  42 #include <mksh/defs.h>
  43 
  44 #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
  45 #       include <rw/xdrstrea.h>
  46 #endif
  47 
  48 
  49 /*
  50  * Defined macros
  51  */
  52 
  53 #define SKIPSPACE(x)    while (*x &&                            \
  54                                ((*x == (int) space_char) ||     \
  55                                 (*x == (int) tab_char) ||       \
  56                                 (*x == (int) comma_char))) {    \
  57                                         x++;                    \
  58                         }
  59 
  60 #define SKIPWORD(x)     while (*x &&                            \
  61                                (*x != (int) space_char) &&      \
  62                                (*x != (int) tab_char) &&        \
  63                                (*x != (int) newline_char) &&    \
  64                                (*x != (int) comma_char) &&      \
  65                                (*x != (int) equal_char)) {      \
  66                                         x++;                    \
  67                         }
  68 
  69 #define SKIPTOEND(x)    while (*x &&                            \
  70                                (*x != (int) newline_char)) {    \
  71                                         x++;                    \
  72                         }
  73 
  74 #define PMAKE_DEF_MAX_JOBS      2       /* Default number of parallel jobs. */
  75 
  76 #define OUT_OF_DATE(a,b) \
  77         (((a) < (b)) || (((a) == file_doesnt_exist) && ((b) == file_doesnt_exist)))
  78 
  79 #define OUT_OF_DATE_SEC(a,b) \
  80         (((a).tv_sec < (b).tv_sec) || (((a).tv_sec == file_doesnt_exist.tv_sec) && ((b).tv_sec == file_doesnt_exist.tv_sec)))
  81         
  82 #define SETVAR(name, value, append) \
  83                                 setvar_daemon(name, value, append, no_daemon, \
  84                                               true, debug_level)
  85 #ifdef SUN5_0
  86 #define MAX(a,b)                (((a)>(b))?(a):(b))
  87 /*
  88  * New feature added to SUN5_0 make,  invoke the vanilla svr4 make when
  89  * the USE_SVR4_MAKE environment variable is set.
  90  */
  91 #define SVR4_MAKE               "/usr/ccs/lib/svr4.make"
  92 #define USE_SVR4_MAKE           "USE_SVR4_MAKE"
  93 #endif
  94 /*
  95  * The standard MAXHOSTNAMELEN is 64. We want 32.
  96  */
  97 #define MAX_HOSTNAMELEN         32
  98 
  99 
 100 /*
 101  * typedefs & structs
 102  */
 103 typedef enum {
 104         no_state,
 105         scan_name_state,
 106         scan_command_state,
 107         enter_dependencies_state,
 108         enter_conditional_state,
 109         enter_equal_state,
 110         illegal_bytes_state,
 111         illegal_eoln_state,
 112         poorly_formed_macro_state,
 113         exit_state
 114 }                       Reader_state;
 115 
 116 struct _Name_vector {
 117         struct _Name            *names[64];
 118         struct _Chain           *target_group[64];
 119         short                   used;
 120         struct _Name_vector     *next;
 121 };
 122 
 123 struct _Running {
 124         struct _Running         *next;
 125         Doname                  state;
 126         struct _Name            *target;
 127         struct _Name            *true_target;
 128         struct _Property        *command;
 129         struct _Name            *sprodep_value;
 130         char                    *sprodep_env;
 131         int                     recursion_level;
 132         Boolean                 do_get;
 133         Boolean                 implicit;
 134         Boolean                 redo;
 135         int                     auto_count;
 136         struct _Name            **automatics;
 137         pid_t                   pid;
 138 #ifdef TEAMWARE_MAKE_CMN
 139         int                     job_msg_id;
 140 #else
 141         int                     host;
 142 #endif
 143         char                    *stdout_file;
 144         char                    *stderr_file;
 145         struct _Name            *temp_file;
 146         int                     conditional_cnt;
 147         struct _Name            **conditional_targets;
 148 #ifdef TEAMWARE_MAKE_CMN
 149         Boolean                 make_refd;
 150 #endif
 151 };
 152 
 153 typedef enum {
 154         serial_mode,
 155         parallel_mode,
 156         distributed_mode
 157 } DMake_mode;
 158 
 159 typedef enum {
 160         txt1_mode,
 161         txt2_mode,
 162         html1_mode
 163 } DMake_output_mode;
 164 
 165 struct _Recursive_make {
 166         struct _Recursive_make  *next;  /* Linked list */
 167         wchar_t                 *target;/* Name of target */
 168         wchar_t                 *oldline;/* Original line in .nse_depinfo */
 169         wchar_t                 *newline;/* New line in .nse_depinfo */
 170         wchar_t                 *cond_macrostring; 
 171                                         /* string built from value of 
 172                                          * conditional macros used by 
 173                                          * this target
 174                                          */
 175         Boolean                 removed;/* This target is no longer recursive*/
 176 };
 177 
 178 struct _Dyntarget {
 179         struct _Dyntarget       *next;
 180         struct _Name            *name;
 181 };
 182 
 183 
 184 /*
 185  * Typedefs for all structs
 186  */
 187 typedef struct _Cmd_line        *Cmd_line, Cmd_line_rec;
 188 typedef struct _Dependency      *Dependency, Dependency_rec;
 189 typedef struct _Macro           *Macro, Macro_rec;
 190 typedef struct _Name_vector     *Name_vector, Name_vector_rec;
 191 typedef struct _Percent         *Percent, Percent_rec;
 192 typedef struct _Dyntarget       *Dyntarget;
 193 typedef struct _Recursive_make  *Recursive_make, Recursive_make_rec;
 194 typedef struct _Running         *Running, Running_rec;
 195 
 196 
 197 /*
 198  *      extern declarations for all global variables.
 199  *      The actual declarations are in globals.cc
 200  */
 201 extern  Boolean         allrules_read;
 202 extern  Name            posix_name;
 203 extern  Name            svr4_name;
 204 extern  Boolean         sdot_target;
 205 extern  Boolean         all_parallel;
 206 extern  Boolean         assign_done;
 207 extern  Boolean         build_failed_seen;
 208 #ifdef DISTRIBUTED
 209 extern  Boolean         building_serial;
 210 #endif
 211 extern  Name            built_last_make_run;
 212 extern  Name            c_at;
 213 #ifdef DISTRIBUTED
 214 extern  Boolean         called_make;
 215 #endif
 216 extern  Boolean         command_changed;
 217 extern  Boolean         commands_done;
 218 extern  Chain           conditional_targets;
 219 extern  Name            conditionals;
 220 extern  Boolean         continue_after_error;
 221 extern  Property        current_line;
 222 extern  Name            current_make_version;
 223 extern  Name            current_target;
 224 extern  short           debug_level;
 225 extern  Cmd_line        default_rule;
 226 extern  Name            default_rule_name;
 227 extern  Name            default_target_to_build;
 228 extern  Boolean         depinfo_already_read;
 229 extern  Name            dmake_group;
 230 extern  Name            dmake_max_jobs;
 231 extern  Name            dmake_mode;
 232 extern  DMake_mode      dmake_mode_type;
 233 extern  Name            dmake_output_mode;
 234 extern  DMake_output_mode       output_mode;
 235 extern  Name            dmake_odir;
 236 extern  Name            dmake_rcfile;
 237 extern  Name            done;
 238 extern  Name            dot;
 239 extern  Name            dot_keep_state;
 240 extern  Name            dot_keep_state_file;
 241 extern  Name            empty_name;
 242 extern  Boolean         fatal_in_progress;
 243 extern  int             file_number;
 244 extern  Name            force;
 245 extern  Name            ignore_name;
 246 extern  Boolean         ignore_errors;
 247 extern  Boolean         ignore_errors_all;
 248 extern  Name            init;
 249 extern  int             job_msg_id;
 250 extern  Boolean         keep_state;
 251 extern  Name            make_state;
 252 #ifdef TEAMWARE_MAKE_CMN
 253 extern  timestruc_t     make_state_before;
 254 #endif
 255 extern  Boolean         make_state_locked;
 256 extern  Dependency      makefiles_used;
 257 extern  Name            makeflags;
 258 extern  Name            make_version;
 259 extern  char            mbs_buffer2[];
 260 extern  char            *mbs_ptr;
 261 extern  char            *mbs_ptr2;
 262 extern  Boolean         no_action_was_taken;
 263 extern  int             mtool_msgs_fd;
 264 extern  Boolean         no_parallel;
 265 #ifdef SGE_SUPPORT
 266 extern  Boolean         grid;
 267 #endif
 268 extern  Name            no_parallel_name;
 269 extern  Name            not_auto;
 270 extern  Boolean         only_parallel;
 271 extern  Boolean         parallel;
 272 extern  Name            parallel_name;
 273 extern  Name            localhost_name;
 274 extern  int             parallel_process_cnt;
 275 extern  Percent         percent_list;
 276 extern  Dyntarget       dyntarget_list;
 277 extern  Name            plus;
 278 extern  Name            pmake_machinesfile;
 279 extern  Name            precious;
 280 extern  Name            primary_makefile;
 281 extern  Boolean         quest;
 282 extern  short           read_trace_level;
 283 extern  Boolean         reading_dependencies;
 284 extern  int             recursion_level;
 285 extern  Name            recursive_name;
 286 extern  short           report_dependencies_level;
 287 extern  Boolean         report_pwd;
 288 extern  Boolean         rewrite_statefile;
 289 extern  Running         running_list;
 290 extern  char            *sccs_dir_path;
 291 extern  Name            sccs_get_name;
 292 extern  Name            sccs_get_posix_name;
 293 extern  Cmd_line        sccs_get_rule;
 294 extern  Cmd_line        sccs_get_org_rule;
 295 extern  Cmd_line        sccs_get_posix_rule;
 296 extern  Name            get_name;
 297 extern  Name            get_posix_name;
 298 extern  Cmd_line        get_rule;
 299 extern  Cmd_line        get_posix_rule;
 300 extern  Boolean         send_mtool_msgs;
 301 extern  Boolean         all_precious;
 302 extern  Boolean         report_cwd;
 303 extern  Boolean         silent_all;
 304 extern  Boolean         silent;
 305 extern  Name            silent_name;
 306 extern  char            *stderr_file;
 307 extern  char            *stdout_file;
 308 #ifdef SGE_SUPPORT
 309 extern  char            script_file[];
 310 #endif
 311 extern  Boolean         stdout_stderr_same;
 312 extern  Dependency      suffixes;
 313 extern  Name            suffixes_name;
 314 extern  Name            sunpro_dependencies;
 315 extern  Boolean         target_variants;
 316 extern  char            *tmpdir;
 317 extern  char            *temp_file_directory;
 318 extern  Name            temp_file_name;
 319 extern  short           temp_file_number;
 320 extern  wchar_t         *top_level_target;
 321 extern  Boolean         touch;
 322 extern  Boolean         trace_reader;
 323 extern  Boolean         build_unconditional;
 324 extern  pathpt          vroot_path;
 325 extern  Name            wait_name;
 326 extern  wchar_t         wcs_buffer2[];
 327 extern  wchar_t         *wcs_ptr;
 328 extern  wchar_t         *wcs_ptr2;
 329 extern  nl_catd         catd;
 330 extern  long int        hostid;
 331 
 332 /*
 333  * Declarations of system defined variables
 334  */
 335 #if !defined(linux)
 336 /* On linux this variable is defined in 'signal.h' */
 337 extern  char            *sys_siglist[];
 338 #endif
 339 
 340 /*
 341  * Declarations of system supplied functions
 342  */
 343 extern  int             file_lock(char *, char *, int *, int);
 344 
 345 /*
 346  * Declarations of functions declared and used by make
 347  */
 348 extern  void            add_pending(Name target, int recursion_level, Boolean do_get, Boolean implicit, Boolean redo);
 349 extern  void            add_running(Name target, Name true_target, Property command, int recursion_level, int auto_count, Name *automatics, Boolean do_get, Boolean implicit);
 350 extern  void            add_serial(Name target, int recursion_level, Boolean do_get, Boolean implicit);
 351 extern  void            add_subtree(Name target, int recursion_level, Boolean do_get, Boolean implicit);
 352 extern  void            append_or_replace_macro_in_dyn_array(ASCII_Dyn_Array *Ar, char *macro);
 353 #ifdef DISTRIBUTED
 354 extern  Doname          await_dist(Boolean waitflg);
 355 #endif
 356 #ifdef TEAMWARE_MAKE_CMN
 357 extern  void            await_parallel(Boolean waitflg);
 358 #endif
 359 extern  void            build_suffix_list(Name target_suffix);
 360 extern  Boolean         check_auto_dependencies(Name target, int auto_count, Name *automatics);
 361 extern  void            check_state(Name temp_file_name);
 362 extern  void            cond_macros_into_string(Name np, String_rec *buffer);
 363 extern  void            construct_target_string();
 364 extern  void            create_xdrs_ptr(void);
 365 extern  void            depvar_add_to_list (Name name, Boolean cmdline);
 366 #ifdef DISTRIBUTED
 367 extern  void            distribute_rxm(Avo_DoJobMsg *dmake_job_msg);
 368 extern  int             getRxmMessage(void);
 369 extern  Avo_JobResultMsg* getJobResultMsg(void);
 370 extern  Avo_AcknowledgeMsg* getAcknowledgeMsg(void);
 371 #endif
 372 extern  Doname          doname(register Name target, register Boolean do_get, register Boolean implicit, register Boolean automatic = false);
 373 extern  Doname          doname_check(register Name target, register Boolean do_get, register Boolean implicit, register Boolean automatic);
 374 extern  Doname          doname_parallel(Name target, Boolean do_get, Boolean implicit);
 375 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);
 376 extern  void            dump_make_state(void);
 377 extern  void            dump_target_list(void);
 378 extern  void            enter_conditional(register Name target, Name name, Name value, register Boolean append);
 379 extern  void            enter_dependencies(register Name target, Chain target_group, register Name_vector depes, register Cmd_line command, register Separator separator);
 380 extern  void            enter_dependency(Property line, register Name depe, Boolean automatic);
 381 extern  void            enter_equal(Name name, Name value, register Boolean append);
 382 extern  Percent         enter_percent(register Name target, Chain target_group, register Name_vector depes, Cmd_line command);
 383 extern  Dyntarget       enter_dyntarget(register Name target);
 384 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);
 385 extern  Boolean         exec_vp(register char *name, register char **argv, char **envp, register Boolean ignore_error);
 386 extern  Doname          execute_parallel(Property line, Boolean waitflg, Boolean local = false);
 387 extern  Doname          execute_serial(Property line);
 388 extern  timestruc_t&        exists(register Name target);
 389 extern  void            fatal(char *, ...);
 390 extern  void            fatal_reader(char *, ...);
 391 extern  Doname          find_ar_suffix_rule(register Name target, Name true_target, Property *command, Boolean rechecking);
 392 extern  Doname          find_double_suffix_rule(register Name target, Property *command, Boolean rechecking);
 393 extern  Doname          find_percent_rule(register Name target, Property *command, Boolean rechecking);
 394 extern  int             find_run_directory (char *cmd, char *cwd, char *dir, char **pgm, char **run, char *path);
 395 extern  Doname          find_suffix_rule(Name target, Name target_body, Name target_suffix, Property *command, Boolean rechecking);
 396 extern  Chain           find_target_groups(register Name_vector target_list, register int i, Boolean reset);
 397 extern  void            finish_children(Boolean docheck);
 398 extern  void            finish_running(void);
 399 extern  void            free_chain(Name_vector ptr);
 400 extern  void            gather_recursive_deps(void);
 401 extern  char            *get_current_path(void);
 402 extern  int             get_job_msg_id(void);
 403 extern  FILE            *get_mtool_msgs_fp(void);
 404 #ifdef DISTRIBUTED
 405 extern  Boolean         get_dmake_group_specified(void);
 406 extern  Boolean         get_dmake_max_jobs_specified(void);
 407 extern  Boolean         get_dmake_mode_specified(void);
 408 extern  Boolean         get_dmake_odir_specified(void);
 409 extern  Boolean         get_dmake_rcfile_specified(void);
 410 extern  Boolean         get_pmake_machinesfile_specified(void);
 411 #endif
 412 #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
 413 extern  XDR             *get_xdrs_ptr(void);
 414 #endif
 415 extern  wchar_t         *getmem_wc(register int size);
 416 #if !defined(linux)
 417 /* On linux getwd(char *) is defined in 'unistd.h' */
 418 #ifdef __cplusplus
 419 extern "C" {
 420 #endif
 421 extern  char            *getwd(char *);
 422 #ifdef __cplusplus
 423 }
 424 #endif
 425 #endif
 426 extern  void            handle_interrupt(int);
 427 extern  Boolean         is_running(Name target);
 428 extern  void            load_cached_names(void);
 429 extern  Boolean         parallel_ok(Name target, Boolean line_prop_must_exists);
 430 extern  void            print_dependencies(register Name target, register Property line);
 431 extern  void            send_job_start_msg(Property line);
 432 extern  void            send_rsrc_info_msg(int max_jobs, char *hostname, char *username);
 433 extern  void            print_value(register Name value, Daemon daemon);
 434 extern  timestruc_t&        read_archive(register Name target);
 435 extern  int             read_dir(Name dir, wchar_t *pattern, Property line, wchar_t *library);
 436 extern  void            read_directory_of_file(register Name file);
 437 extern  int             read_make_machines(Name make_machines_name);
 438 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);
 439 extern  void            remove_recursive_dep(Name target);
 440 extern  void            report_recursive_dep(Name target, char *line);
 441 extern  void            report_recursive_done(void);
 442 extern  void            report_recursive_init(void);
 443 extern  Recursive_make  find_recursive_target(Name target);
 444 extern  void            reset_locals(register Name target, register Property old_locals, register Property conditional, register int index);
 445 extern  void            set_locals(register Name target, register Property old_locals);
 446 extern  void            setvar_append(register Name name, register Name value);
 447 #ifdef DISTRIBUTED
 448 extern  void            setvar_envvar(Avo_DoJobMsg *dmake_job_msg);
 449 #else
 450 extern  void            setvar_envvar(void);
 451 #endif
 452 extern  void            special_reader(Name target, register Name_vector depes, Cmd_line command);
 453 extern  void            startup_rxm();
 454 extern  Doname          target_can_be_built(register Name target);
 455 extern  char            *time_to_string(const timestruc_t &time);
 456 extern  void            update_target(Property line, Doname result);
 457 extern  void            warning(char *, ...);
 458 extern  void            write_state_file(int report_recursive, Boolean exiting);
 459 extern  Name            vpath_translation(register Name cmd);
 460 
 461 #define DEPINFO_FMT_VERSION "VERS2$"
 462 #define VER_LEN strlen(DEPINFO_FMT_VERSION)
 463 
 464 #ifdef NSE
 465 
 466 /* 
 467  *  NSE version for depinfo format
 468  */
 469 extern Boolean          nse;
 470 extern Name             nse_backquote_seen;
 471 extern Boolean          nse_did_recursion;
 472 extern Name             nse_shell_var_used;
 473 extern Boolean          nse_watch_vars;
 474 extern wchar_t          current_makefile[MAXPATHLEN];
 475 extern Boolean          nse_depinfo_locked;
 476 extern char             nse_depinfo_lockfile[MAXPATHLEN];
 477 extern Name             derived_src;
 478 
 479 extern void             depvar_dep_macro_used(Name);
 480 extern void             depvar_rule_macro_used(Name);
 481 extern Boolean          nse_backquotes(wchar_t *);
 482 extern void             nse_check_cd(Property);
 483 extern void             nse_check_derived_src(Name, wchar_t *, Cmd_line);
 484 extern void             nse_check_file_backquotes(wchar_t *);
 485 extern void             nse_check_no_deps_no_rule(Name, Property, Property);
 486 extern void             nse_check_sccs(wchar_t *, wchar_t *);
 487 extern void             nse_dep_cmdmacro(wchar_t *);
 488 extern int              nse_exit_status(void);
 489 extern void             nse_init_source_suffixes(void);
 490 extern void             nse_no_makefile(Name);
 491 extern void             nse_rule_cmdmacro(wchar_t *);
 492 extern void             nse_wildcard(wchar_t *, wchar_t *);
 493 #endif
 494 
 495 #endif