Print this page
make: unifdef for NSE (undefined)


 101  *      Write a new version of .make.state
 102  *
 103  *      Parameters:
 104  *              report_recursive        Should only be done at end of run
 105  *              exiting                 true if called from the exit handler
 106  *
 107  *      Global variables used:
 108  *              built_last_make_run The Name ".BUILT_LAST_MAKE_RUN", written
 109  *              command_changed If no command changed we do not need to write
 110  *              current_make_version The Name "<current version>", written
 111  *              do_not_exec_rule If -n is on we do not write statefile
 112  *              hashtab         The hashtable that contains all names
 113  *              keep_state      If .KEEP_STATE is no on we do not write file
 114  *              make_state      The Name ".make.state", used for opening file
 115  *              make_version    The Name ".MAKE_VERSION", written
 116  *              recursive_name  The Name ".RECURSIVE", written
 117  *              rewrite_statefile Indicates that something changed
 118  */
 119 
 120 void
 121 #ifdef NSE
 122 write_state_file(int report_recursive, Boolean exiting)
 123 #else
 124 write_state_file(int, Boolean exiting)
 125 #endif
 126 {
 127         register FILE           *fd;
 128         int                     lock_err;
 129         char                    buffer[MAXPATHLEN];
 130         char                    make_state_tempfile[MAXPATHLEN];
 131         jmp_buf                 long_jump;
 132         register int            attempts = 0;
 133         Name_set::iterator      np, e;
 134         register Property       lines;
 135         register int            m;
 136         Dependency              dependency;
 137         register Boolean        name_printed;
 138         Boolean                 built_this_run = false;
 139         char                    *target_name;
 140         int                     line_length;
 141         register Cmd_line       cp;
 142 
 143 
 144         if (!rewrite_statefile ||
 145             !command_changed ||


 181                         report_pwd = true;
 182                         fatal(catgets(catd, 1, 62, "Can't lock .make.state"));
 183                 }
 184         }
 185 
 186         (void) sprintf(make_state_tempfile,
 187                        NOCATGETS("%s.tmp"),
 188                        make_state->string_mb);
 189         /* Delete old temporary statefile (in case it exists) */
 190         (void) unlink(make_state_tempfile);
 191         if ((fd = fopen(make_state_tempfile, "w")) == NULL) {
 192                 lock_err = errno; /* Save it! unlink() can change errno */
 193                 (void) unlink(make_state_lockfile);
 194                 retmem_mb(make_state_lockfile);
 195                 make_state_lockfile = NULL;
 196                 make_state_locked = false;
 197                 fatal(catgets(catd, 1, 59, "Could not open temporary statefile `%s': %s"),
 198                       make_state_tempfile,
 199                       errmsg(lock_err));
 200         }
 201 #ifdef NSE
 202         if (nse) {
 203                 (void) fchmod(fileno(fd), 0666); 
 204         }
 205 #endif
 206         /*
 207          * Set a trap for failed writes. If a write fails, the routine
 208          * will try saving the .make.state file under another name in /tmp.
 209          */
 210         if (setjmp(long_jump)) {
 211                 (void) fclose(fd);
 212                 if (attempts++ > 5) {
 213                         if ((make_state_lockfile != NULL) &&
 214                             make_state_locked) {
 215                                 (void) unlink(make_state_lockfile);
 216                                 retmem_mb(make_state_lockfile);
 217                                 make_state_lockfile = NULL;
 218                                 make_state_locked = false;
 219                         }
 220                         fatal(catgets(catd, 1, 63, "Giving up on writing statefile"));
 221                 }
 222                 sleep(10);
 223                 (void) sprintf(buffer, NOCATGETS("%s/.make.state.%d.XXXXXX"), tmpdir, getpid());
 224                 int fdes = mkstemp(buffer);
 225                 if ((fdes < 0) || (fd = fdopen(fdes, "w")) == NULL) {


 381                 if (rename(make_state_tempfile, make_state->string_mb) != 0) {
 382                         lock_err = errno; /* Save it! unlink() can change errno */
 383                         /* Delete temporary statefile */
 384                         (void) unlink(make_state_tempfile);
 385                         (void) unlink(make_state_lockfile);
 386                         retmem_mb(make_state_lockfile);
 387                         make_state_lockfile = NULL;
 388                         make_state_locked = false;
 389                         fatal(catgets(catd, 1, 357, "Could not rename `%s' to `%s': %s"),
 390                               make_state_tempfile,
 391                               make_state->string_mb,
 392                               errmsg(lock_err));
 393                 }
 394         }
 395         if ((make_state_lockfile != NULL) && make_state_locked) {
 396                 (void) unlink(make_state_lockfile);
 397                 retmem_mb(make_state_lockfile);
 398                 make_state_lockfile = NULL;
 399                 make_state_locked = false;
 400         }
 401 #ifdef NSE
 402         if (report_recursive) {
 403                 report_recursive_done();
 404         }
 405 #endif
 406 }
 407 
 408 /*
 409  *      print_auto_depes(dependency, fd, built_this_run,
 410  *                       line_length, target_name, long_jump)
 411  *
 412  *      Will print a dependency list for automatic entries.
 413  *
 414  *      Parameters:
 415  *              dependency      The dependency to print
 416  *              fd              The file to print it to
 417  *              built_this_run  If on we prefix each line with .BUILT_THIS...
 418  *              line_length     Pointer to line length var that we update
 419  *              target_name     We need this when we restart line
 420  *              long_jump       setjmp/longjmp buffer used for IO error action
 421  *
 422  *      Global variables used:
 423  *              built_last_make_run The Name ".BUILT_LAST_MAKE_RUN", written
 424  *              force           The Name " FORCE", compared against
 425  */




 101  *      Write a new version of .make.state
 102  *
 103  *      Parameters:
 104  *              report_recursive        Should only be done at end of run
 105  *              exiting                 true if called from the exit handler
 106  *
 107  *      Global variables used:
 108  *              built_last_make_run The Name ".BUILT_LAST_MAKE_RUN", written
 109  *              command_changed If no command changed we do not need to write
 110  *              current_make_version The Name "<current version>", written
 111  *              do_not_exec_rule If -n is on we do not write statefile
 112  *              hashtab         The hashtable that contains all names
 113  *              keep_state      If .KEEP_STATE is no on we do not write file
 114  *              make_state      The Name ".make.state", used for opening file
 115  *              make_version    The Name ".MAKE_VERSION", written
 116  *              recursive_name  The Name ".RECURSIVE", written
 117  *              rewrite_statefile Indicates that something changed
 118  */
 119 
 120 void



 121 write_state_file(int, Boolean exiting)

 122 {
 123         register FILE           *fd;
 124         int                     lock_err;
 125         char                    buffer[MAXPATHLEN];
 126         char                    make_state_tempfile[MAXPATHLEN];
 127         jmp_buf                 long_jump;
 128         register int            attempts = 0;
 129         Name_set::iterator      np, e;
 130         register Property       lines;
 131         register int            m;
 132         Dependency              dependency;
 133         register Boolean        name_printed;
 134         Boolean                 built_this_run = false;
 135         char                    *target_name;
 136         int                     line_length;
 137         register Cmd_line       cp;
 138 
 139 
 140         if (!rewrite_statefile ||
 141             !command_changed ||


 177                         report_pwd = true;
 178                         fatal(catgets(catd, 1, 62, "Can't lock .make.state"));
 179                 }
 180         }
 181 
 182         (void) sprintf(make_state_tempfile,
 183                        NOCATGETS("%s.tmp"),
 184                        make_state->string_mb);
 185         /* Delete old temporary statefile (in case it exists) */
 186         (void) unlink(make_state_tempfile);
 187         if ((fd = fopen(make_state_tempfile, "w")) == NULL) {
 188                 lock_err = errno; /* Save it! unlink() can change errno */
 189                 (void) unlink(make_state_lockfile);
 190                 retmem_mb(make_state_lockfile);
 191                 make_state_lockfile = NULL;
 192                 make_state_locked = false;
 193                 fatal(catgets(catd, 1, 59, "Could not open temporary statefile `%s': %s"),
 194                       make_state_tempfile,
 195                       errmsg(lock_err));
 196         }





 197         /*
 198          * Set a trap for failed writes. If a write fails, the routine
 199          * will try saving the .make.state file under another name in /tmp.
 200          */
 201         if (setjmp(long_jump)) {
 202                 (void) fclose(fd);
 203                 if (attempts++ > 5) {
 204                         if ((make_state_lockfile != NULL) &&
 205                             make_state_locked) {
 206                                 (void) unlink(make_state_lockfile);
 207                                 retmem_mb(make_state_lockfile);
 208                                 make_state_lockfile = NULL;
 209                                 make_state_locked = false;
 210                         }
 211                         fatal(catgets(catd, 1, 63, "Giving up on writing statefile"));
 212                 }
 213                 sleep(10);
 214                 (void) sprintf(buffer, NOCATGETS("%s/.make.state.%d.XXXXXX"), tmpdir, getpid());
 215                 int fdes = mkstemp(buffer);
 216                 if ((fdes < 0) || (fd = fdopen(fdes, "w")) == NULL) {


 372                 if (rename(make_state_tempfile, make_state->string_mb) != 0) {
 373                         lock_err = errno; /* Save it! unlink() can change errno */
 374                         /* Delete temporary statefile */
 375                         (void) unlink(make_state_tempfile);
 376                         (void) unlink(make_state_lockfile);
 377                         retmem_mb(make_state_lockfile);
 378                         make_state_lockfile = NULL;
 379                         make_state_locked = false;
 380                         fatal(catgets(catd, 1, 357, "Could not rename `%s' to `%s': %s"),
 381                               make_state_tempfile,
 382                               make_state->string_mb,
 383                               errmsg(lock_err));
 384                 }
 385         }
 386         if ((make_state_lockfile != NULL) && make_state_locked) {
 387                 (void) unlink(make_state_lockfile);
 388                 retmem_mb(make_state_lockfile);
 389                 make_state_lockfile = NULL;
 390                 make_state_locked = false;
 391         }





 392 }
 393 
 394 /*
 395  *      print_auto_depes(dependency, fd, built_this_run,
 396  *                       line_length, target_name, long_jump)
 397  *
 398  *      Will print a dependency list for automatic entries.
 399  *
 400  *      Parameters:
 401  *              dependency      The dependency to print
 402  *              fd              The file to print it to
 403  *              built_this_run  If on we prefix each line with .BUILT_THIS...
 404  *              line_length     Pointer to line length var that we update
 405  *              target_name     We need this when we restart line
 406  *              long_jump       setjmp/longjmp buffer used for IO error action
 407  *
 408  *      Global variables used:
 409  *              built_last_make_run The Name ".BUILT_LAST_MAKE_RUN", written
 410  *              force           The Name " FORCE", compared against
 411  */