Print this page
make: unifdef for NSE (undefined)


 354                                     strlen(argv[0]) + 1);
 355                 (void) sprintf(tmp_string,
 356                                "%s/%s",
 357                                tmp_current_path,
 358                                argv[0]);
 359                 argv_zero_string = strdup(tmp_string);
 360                 retmem_mb(tmp_string);
 361         }
 362 
 363         /* 
 364          * The following flags are reset if we don't have the 
 365          * (.nse_depinfo or .make.state) files locked and only set 
 366          * AFTER the file has been locked. This ensures that if the user
 367          * interrupts the program while file_lock() is waiting to lock
 368          * the file, the interrupt handler doesn't remove a lock 
 369          * that doesn't belong to us.
 370          */
 371         make_state_lockfile = NULL;
 372         make_state_locked = false;
 373 
 374 #ifdef NSE
 375         nse_depinfo_lockfile[0] = '\0';
 376         nse_depinfo_locked = false; 
 377 #endif
 378 
 379         /*
 380          * look for last slash char in the path to look at the binary 
 381          * name. This is to resolve the hard link and invoke make
 382          * in svr4 mode.
 383          */
 384 
 385         /* Sun OS make standart */
 386         svr4 = false;  
 387         posix = false;
 388         if(!strcmp(argv_zero_string, NOCATGETS("/usr/xpg4/bin/make"))) {
 389                 svr4 = false;
 390                 posix = true;
 391         } else {
 392                 prognameptr = strrchr(argv[0], '/');
 393                 if(prognameptr) {
 394                         prognameptr++;
 395                 } else {
 396                         prognameptr = argv[0];
 397                 }


 681                 
 682 /*
 683  *      Enable interrupt handler for alarms
 684  */
 685         (void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
 686 
 687 /*
 688  *      Check if make should report
 689  */
 690         if (getenv(sunpro_dependencies->string_mb) != NULL) {
 691                 FILE    *report_file;
 692 
 693                 report_dependency("");
 694                 report_file = get_report_file();
 695                 if ((report_file != NULL) && (report_file != (FILE*)-1)) {
 696                         (void) fprintf(report_file, "\n");
 697                 }
 698         }
 699 
 700 /*
 701  *      Make sure SUNPRO_DEPENDENCIES is exported (or not) properly
 702  *      and NSE_DEP.
 703  */
 704         if (keep_state) {
 705                 maybe_append_prop(sunpro_dependencies, macro_prop)->
 706                   body.macro.exported = true;
 707 #ifdef NSE
 708                 (void) setenv(NOCATGETS("NSE_DEP"), get_current_path());
 709 #endif
 710         } else {
 711                 maybe_append_prop(sunpro_dependencies, macro_prop)->
 712                   body.macro.exported = false;
 713         }
 714 
 715         working_on_targets = true;
 716         if (trace_status) {
 717                 dump_make_state();
 718                 fclose(stdout);
 719                 fclose(stderr);
 720                 exit_status = 0;
 721                 exit(0);
 722         }
 723         if (list_all_targets) {
 724                 dump_target_list();
 725                 fclose(stdout);
 726                 fclose(stderr);
 727                 exit_status = 0;
 728                 exit(0);
 729         }


 752                         char    tmp_current_path2[MAXPATHLEN];
 753  
 754                         (void) sprintf(tmp_current_path2,
 755                                        "%s/%s",
 756                                        get_current_path(),
 757                                        make_state_dir);
 758                         temp_file_directory = strdup(tmp_current_path2);
 759                 }
 760         }
 761 
 762 #ifdef DISTRIBUTED
 763         building_serial = false;
 764 #endif
 765 
 766         report_dir_enter_leave(true);
 767 
 768         make_targets(argc, argv, parallel_flag);
 769 
 770         report_dir_enter_leave(false);
 771 
 772 #ifdef NSE
 773         exit(nse_exit_status());
 774 #else
 775         if (build_failed_ever_seen) {
 776                 if (posix) {
 777                         exit_status = 1;
 778                 }
 779                 exit(1);
 780         }
 781         exit_status = 0;
 782         exit(0);
 783 #endif
 784         /* NOTREACHED */
 785 }
 786 
 787 /*
 788  *      cleanup_after_exit()
 789  *
 790  *      Called from exit(), performs cleanup actions.
 791  *
 792  *      Parameters:
 793  *              status          The argument exit() was called with
 794  *              arg             Address of an argument vector to
 795  *                              cleanup_after_exit()
 796  *
 797  *      Global variables used:
 798  *              command_changed Set if we think .make.state should be rewritten
 799  *              current_line    Is set we set commands_changed
 800  *              do_not_exec_rule
 801  *                              True if -n flag on
 802  *              done            The Name ".DONE", rule we run
 803  *              keep_state      Set if .KEEP_STATE seen
 804  *              parallel        True if building in parallel
 805  *              quest           If -q is on we do not run .DONE
 806  *              report_dependencies
 807  *                              True if -P flag on
 808  *              running_list    List of parallel running processes
 809  *              temp_file_name  The temp file is removed, if any
 810  *              catd    the message catalog file
 811  *              usage_tracking  Should have been constructed in main()
 812  *                              should destroyed just before exiting
 813  */
 814 extern "C" void
 815 cleanup_after_exit(void)
 816 {
 817         Running         rp;
 818 #ifdef NSE
 819         char            push_cmd[NSE_TFS_PUSH_LEN + 3 +
 820                                  (MAXPATHLEN * MB_LEN_MAX) + 12];
 821         char            *active;
 822 #endif
 823 
 824 extern long     getname_bytes_count;
 825 extern long     getname_names_count;
 826 extern long     getname_struct_count;
 827 extern long     freename_bytes_count;
 828 extern long     freename_names_count;
 829 extern long     freename_struct_count;
 830 extern long     other_alloc;
 831 
 832 extern long     env_alloc_num;
 833 extern long     env_alloc_bytes;
 834 
 835 
 836 #ifdef DMAKE_STATISTICS
 837 if(getname_stat) {
 838         printf(NOCATGETS(">>> Getname statistics:\n"));
 839         printf(NOCATGETS("  Allocated:\n"));
 840         printf(NOCATGETS("        Names: %ld\n"), getname_names_count);
 841         printf(NOCATGETS("      Strings: %ld Kb (%ld bytes)\n"), getname_bytes_count/1000, getname_bytes_count);
 842         printf(NOCATGETS("      Structs: %ld Kb (%ld bytes)\n"), getname_struct_count/1000, getname_struct_count);


 943         /* Remove the statefile lock file if the file has been locked */
 944         if ((make_state_lockfile != NULL) && (make_state_locked)) {
 945                 (void) unlink(make_state_lockfile);
 946                 make_state_lockfile = NULL;
 947                 make_state_locked = false;
 948         }
 949         /* Write .make.state */
 950         write_state_file(1, (Boolean) 1);
 951 
 952 #ifdef TEAMWARE_MAKE_CMN
 953         // Deleting the usage tracking object sends the usage mail 
 954 #ifdef USE_DMS_CCR
 955         //usageTracking->setExitStatus(exit_status, NULL);
 956         //delete usageTracking;
 957 #else
 958         cleanup->set_exit_status(exit_status);
 959         delete cleanup;
 960 #endif
 961 #endif
 962 
 963 #ifdef NSE
 964         /* If running inside an activated environment, push the */
 965         /* .nse_depinfo file (if written) */
 966         active = getenv(NSE_VARIANT_ENV);
 967         if (keep_state &&
 968             (active != NULL) &&
 969             !IS_EQUAL(active, NSE_RT_SOURCE_NAME) &&
 970             !do_not_exec_rule &&
 971             (report_dependencies_level == 0)) {
 972                 (void) sprintf(push_cmd,
 973                                "%s %s/%s",
 974                                NSE_TFS_PUSH,
 975                                get_current_path(),
 976                                NSE_DEPINFO);
 977                 (void) system(push_cmd);
 978         }
 979 #endif
 980 
 981 /*
 982 #ifdef DISTRIBUTED
 983     }
 984 #endif
 985  */
 986 
 987 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
 988         job_adjust_fini();
 989 #endif
 990 
 991 #ifdef TEAMWARE_MAKE_CMN
 992         catclose(catd);
 993 #endif
 994 #ifdef DISTRIBUTED
 995         if (rxmPid > 0) {
 996                 // Tell rxm to exit by sending it an Avo_AcknowledgeMsg
 997                 Avo_AcknowledgeMsg acknowledgeMsg;
 998                 RWCollectable *msg = (RWCollectable *)&acknowledgeMsg;
 999 
1000                 int xdrResult = xdr(&xdrs_out, msg);


1145                                                        rp->target->string_mb,
1146                                                        errmsg(errno));
1147                                 }
1148                         }
1149                 }
1150         }
1151 
1152 #ifdef SGE_SUPPORT
1153         /* Remove SGE script file */
1154         if (grid) {
1155                 unlink(script_file);
1156         }
1157 #endif
1158 
1159         /* Have we locked .make.state or .nse_depinfo? */
1160         if ((make_state_lockfile != NULL) && (make_state_locked)) {
1161                 unlink(make_state_lockfile);
1162                 make_state_lockfile = NULL;
1163                 make_state_locked = false;
1164         }
1165 #ifdef NSE
1166         if ((nse_depinfo_lockfile[0] != '\0') && (nse_depinfo_locked)) {
1167                 unlink(nse_depinfo_lockfile);
1168                 nse_depinfo_lockfile[0] = '\0';
1169                 nse_depinfo_locked = false;
1170         }
1171 #endif
1172         /*
1173          * Re-read .make.state file (it might be changed by recursive make)
1174          */
1175         check_state(NULL);
1176 
1177         report_dir_enter_leave(false);
1178 
1179         exit_status = 2;
1180         exit(2);
1181 }
1182 
1183 /*
1184  *      doalarm(sig, ...)
1185  *
1186  *      Handle the alarm interrupt but do nothing.  Side effect is to
1187  *      cause return from wait3.
1188  *
1189  *      Parameters:
1190  *              sig
1191  *


1683                 if (invert_this) {
1684                         dmake_rcfile_specified = false;
1685                 } else {
1686                         dmake_rcfile_specified = true;
1687                 }
1688                 return 2;
1689         case 'D':                        /* Show lines read */
1690                 if (invert_this) {
1691                         read_trace_level--;
1692                 } else {
1693                         read_trace_level++;
1694                 }
1695                 return 0;
1696         case 'd':                        /* Debug flag */
1697                 if (invert_this) {
1698                         debug_level--;
1699                 } else {
1700                         debug_level++;
1701                 }
1702                 return 0;
1703 #ifdef NSE
1704         case 'E':
1705                 if (invert_this) {
1706                         nse = false;
1707                 } else {
1708                         nse = true;
1709                 }
1710                 nse_init_source_suffixes();
1711                 return 0;
1712 #endif
1713         case 'e':                        /* Environment override flag */
1714                 if (invert_this) {
1715                         env_wins = false;
1716                 } else {
1717                         env_wins = true;
1718                 }
1719                 return 0;
1720         case 'f':                        /* Read alternative makefile(s) */
1721                 return 1;
1722         case 'g':                        /* Use alternative DMake group */
1723                 if (invert_this) {
1724                         dmake_group_specified = false;
1725                 } else {
1726                         dmake_group_specified = true;
1727                 }
1728                 return 4;
1729         case 'i':                        /* Ignore errors */
1730                 if (invert_this) {
1731                         ignore_errors_all = false;
1732                 } else {


2043  *
2044  *      Parameters:
2045  *              argc            You know what this is
2046  *              argv            You know what this is
2047  *
2048  *      Static variables used:
2049  *              env_wins        make -e, determines if env vars are RO
2050  *              ignore_default_mk make -r, determines if make.rules is read
2051  *              not_auto_depen  dwight
2052  *
2053  *      Global variables used:
2054  *              default_target_to_build Set to first proper target from file
2055  *              do_not_exec_rule Set to false when makfile is made
2056  *              dot             The Name ".", used to read current dir
2057  *              empty_name      The Name "", use as macro value
2058  *              keep_state      Set if KEEP_STATE is in environment
2059  *              make_state      The Name ".make.state", used to read file
2060  *              makefile_type   Set to type of file being read
2061  *              makeflags       The Name "MAKEFLAGS", used to set macro value
2062  *              not_auto        dwight
2063  *              nse             Set if NSE_ENV is in the environment
2064  *              read_trace_level Checked to se if the reader should trace
2065  *              report_dependencies If -P is on we do not read .make.state
2066  *              trace_reader    Set if reader should trace
2067  *              virtual_root    The Name "VIRTUAL_ROOT", used to check value
2068  */
2069 static void
2070 read_files_and_state(int argc, char **argv)
2071 {
2072         wchar_t                 buffer[1000];
2073         wchar_t                 buffer_posix[1000];
2074         register char           ch;
2075         register char           *cp;
2076         Property                def_make_macro = NULL;
2077         Name                    def_make_name;
2078         Name                    default_makefile;
2079         String_rec              dest;
2080         wchar_t                 destbuffer[STRING_BUFFER_LENGTH];
2081         register int            i;
2082         register int            j;
2083         Name                    keep_state_name;


2110 /*
2111  *      Remember current mode. It may be changed after reading makefile
2112  *      and we will have to correct MAKEFLAGS variable.
2113  */
2114         is_xpg4 = posix;
2115 
2116         MBSTOWCS(wcs_buffer, NOCATGETS("KEEP_STATE"));
2117         keep_state_name = GETNAME(wcs_buffer, FIND_LENGTH);
2118         MBSTOWCS(wcs_buffer, NOCATGETS("Makefile"));
2119         Makefile = GETNAME(wcs_buffer, FIND_LENGTH);
2120         MBSTOWCS(wcs_buffer, NOCATGETS("makefile"));
2121         makefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
2122         MBSTOWCS(wcs_buffer, NOCATGETS("s.makefile"));
2123         sdotmakefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
2124         MBSTOWCS(wcs_buffer, NOCATGETS("s.Makefile"));
2125         sdotMakefile = GETNAME(wcs_buffer, FIND_LENGTH);
2126 
2127 /*
2128  *      Set flag if NSE is active
2129  */
2130 #ifdef NSE
2131         if (getenv(NOCATGETS("NSE_ENV")) != NULL) {
2132                 nse = true;
2133         }
2134 #endif
2135 
2136 /*
2137  *      initialize global dependency entry for .NOT_AUTO
2138  */
2139         not_auto_depen->next = NULL;
2140         not_auto_depen->name = not_auto;
2141         not_auto_depen->automatic = not_auto_depen->stale = false;
2142 
2143 /*
2144  *      Read internal definitions and rules.
2145  */
2146         if (read_trace_level > 1) {
2147                 trace_reader = true;
2148         }
2149         if (!ignore_default_mk) {
2150                 if (svr4) {
2151                         MBSTOWCS(wcs_buffer, NOCATGETS("svr4.make.rules"));
2152                         default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
2153                 } else {
2154                         MBSTOWCS(wcs_buffer, NOCATGETS("make.rules"));


2219         INIT_STRING_FROM_STACK(makeflags_string_posix, buffer_posix);
2220         append_char((int) hyphen_char, &makeflags_string);
2221         append_char((int) hyphen_char, &makeflags_string_posix);
2222 
2223         switch (read_trace_level) {
2224         case 2:
2225                 append_char('D', &makeflags_string);
2226                 append_char('D', &makeflags_string_posix);
2227         case 1:
2228                 append_char('D', &makeflags_string);
2229                 append_char('D', &makeflags_string_posix);
2230         }
2231         switch (debug_level) {
2232         case 2:
2233                 append_char('d', &makeflags_string);
2234                 append_char('d', &makeflags_string_posix);
2235         case 1:
2236                 append_char('d', &makeflags_string);
2237                 append_char('d', &makeflags_string_posix);
2238         }
2239 #ifdef NSE
2240         if (nse) {
2241                 append_char('E', &makeflags_string);
2242         }
2243 #endif
2244         if (env_wins) {
2245                 append_char('e', &makeflags_string);
2246                 append_char('e', &makeflags_string_posix);
2247         }
2248         if (ignore_errors_all) {
2249                 append_char('i', &makeflags_string);
2250                 append_char('i', &makeflags_string_posix);
2251         }
2252         if (continue_after_error) {
2253                 if (stop_after_error_ever_seen) {
2254                         append_char('S', &makeflags_string_posix);
2255                         append_char((int) space_char, &makeflags_string_posix);
2256                         append_char((int) hyphen_char, &makeflags_string_posix);
2257                 }
2258                 append_char('k', &makeflags_string);
2259                 append_char('k', &makeflags_string_posix);
2260         } else {
2261                 if (stop_after_error_ever_seen 
2262                     && continue_after_error_ever_seen) {
2263                         append_char('k', &makeflags_string_posix);


3027                 MBSTOWCS(wcs_buffer2, NOCATGETS("SHELL="));
3028                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
3029                         continue;
3030                 }
3031                 MBSTOWCS(wcs_buffer2, NOCATGETS("MAKEFLAGS="));
3032                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
3033                         report_pwd = true;
3034                         /*
3035                          * In POSIX mode we do not want MAKEFLAGS to be readonly.
3036                          * If the MAKEFLAGS macro is subsequently set by the makefile,
3037                          * it replaces the MAKEFLAGS variable currently found in the
3038                          * environment.
3039                          * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
3040                          */
3041                         if(posix) {
3042                                 read_only_saved = false;
3043                         }
3044                 }
3045 
3046                 /*
3047                  * We ignore SUNPRO_DEPENDENCIES and NSE_DEP. Those
3048                  * environment variables are set by make and read by 
3049                  * cpp which then writes info to .make.dependency.xxx and 
3050                  * .nse_depinfo. When make is invoked by another make 
3051                  * (recursive make), we don't want to read this because 
3052                  * then the child make will end up writing to the parent 
3053                  * directory's .make.state and .nse_depinfo and clobbering
3054                  * them. 
3055                  */
3056                 MBSTOWCS(wcs_buffer2, NOCATGETS("SUNPRO_DEPENDENCIES"));
3057                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
3058                         continue;
3059                 }
3060 #ifdef NSE
3061                 MBSTOWCS(wcs_buffer2, NOCATGETS("NSE_DEP"));
3062                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
3063                         continue;
3064                 }
3065 #endif
3066 
3067                 macro = GETNAME(name, value - name);
3068                 maybe_append_prop(macro, macro_prop)->body.macro.exported =
3069                   true;
3070                 if ((value == NULL) || ((value + 1)[0] == (int) nul_char)) {
3071                         val = setvar_daemon(macro,
3072                                             (Name) NULL,
3073                                             false, no_daemon, false, debug_level);
3074                 } else {
3075                         val = setvar_daemon(macro,
3076                                             GETNAME(value + 1, FIND_LENGTH),
3077                                             false, no_daemon, false, debug_level);
3078                 }
3079 #ifdef NSE
3080                 /*
3081                  * Must be after the call to setvar() as it sets
3082                  * imported to false.
3083                  */
3084                 maybe_append_prop(macro, macro_prop)->body.macro.imported = true;
3085 #endif
3086                 val->body.macro.read_only = read_only_saved;
3087                 if (alloced_tmp_wcs_buffer) {
3088                         retmem(tmp_wcs_buffer);
3089                         alloced_tmp_wcs_buffer = false;
3090                 }
3091         }
3092         reading_environment = false;
3093 }
3094 
3095 /*
3096  *      read_makefile(makefile, complain, must_exist, report_file)
3097  *
3098  *      Read one makefile and check the result
3099  *
3100  *      Return value:
3101  *                              false is the read failed
3102  *
3103  *      Parameters:
3104  *              makefile        The file to read
3105  *              complain        Passed thru to read_simple_file()
3106  *              must_exist      Passed thru to read_simple_file()
3107  *              report_file     Passed thru to read_simple_file()
3108  *
3109  *      Global variables used:
3110  *              makefile_type   Set to indicate we are reading main file
3111  *              recursion_level Initialized
3112  */
3113 static Boolean
3114 read_makefile(register Name makefile, Boolean complain, Boolean must_exist, Boolean report_file)
3115 {
3116         Boolean                 b;
3117         
3118         makefile_type = reading_makefile;
3119         recursion_level = 0;
3120 #ifdef NSE
3121         wscpy(current_makefile, makefile->string);
3122 #endif
3123         reading_dependencies = true;
3124         b = read_simple_file(makefile, true, true, complain,
3125                              must_exist, report_file, false);
3126         reading_dependencies = false;
3127         return b;
3128 }
3129 
3130 /*
3131  *      make_targets(argc, argv, parallel_flag)
3132  *
3133  *      Call doname on the specified targets
3134  *
3135  *      Parameters:
3136  *              argc            You know what this is
3137  *              argv            You know what this is
3138  *              parallel_flag   True if building in parallel
3139  *
3140  *      Global variables used:
3141  *              build_failed_seen Used to generated message after failed -k
3142  *              commands_done   Used to generate message "Up to date"


3393  *              target          Target to report
3394  *
3395  *      Global variables used:
3396  *              makefiles_used          List of makefiles read
3397  *              recursive_name          The Name ".RECURSIVE", printed
3398  *              report_dependency       dwight
3399  */
3400 static void
3401 report_recursion(register Name target)
3402 {
3403         register FILE           *report_file = get_report_file();
3404 
3405         if ((report_file == NULL) || (report_file == (FILE*)-1)) {
3406                 return;
3407         }
3408         if (primary_makefile == NULL) {
3409                 /*
3410                  * This can happen when there is no makefile and
3411                  * only implicit rules are being used.
3412                  */
3413 #ifdef NSE
3414                 nse_no_makefile(target);
3415 #endif
3416                 return;
3417         }
3418         (void) fprintf(report_file,
3419                        "%s: %s ",
3420                        get_target_being_reported_for(),
3421                        recursive_name->string_mb);
3422         report_dependency(get_current_path());
3423         report_dependency(target->string_mb);
3424         report_dependency(primary_makefile->string_mb);
3425         (void) fprintf(report_file, "\n");
3426 }
3427 
3428 /* Next function "append_or_replace_macro_in_dyn_array" must be in "misc.cc". */
3429 /* NIKMOL */
3430 extern void
3431 append_or_replace_macro_in_dyn_array(ASCII_Dyn_Array *Ar, char *macro)
3432 {
3433         register char   *cp0;   /* work pointer in macro */
3434         register char   *cp1;   /* work pointer in array */
3435         register char   *cp2;   /* work pointer in array */




 354                                     strlen(argv[0]) + 1);
 355                 (void) sprintf(tmp_string,
 356                                "%s/%s",
 357                                tmp_current_path,
 358                                argv[0]);
 359                 argv_zero_string = strdup(tmp_string);
 360                 retmem_mb(tmp_string);
 361         }
 362 
 363         /* 
 364          * The following flags are reset if we don't have the 
 365          * (.nse_depinfo or .make.state) files locked and only set 
 366          * AFTER the file has been locked. This ensures that if the user
 367          * interrupts the program while file_lock() is waiting to lock
 368          * the file, the interrupt handler doesn't remove a lock 
 369          * that doesn't belong to us.
 370          */
 371         make_state_lockfile = NULL;
 372         make_state_locked = false;
 373 




 374 
 375         /*
 376          * look for last slash char in the path to look at the binary 
 377          * name. This is to resolve the hard link and invoke make
 378          * in svr4 mode.
 379          */
 380 
 381         /* Sun OS make standart */
 382         svr4 = false;  
 383         posix = false;
 384         if(!strcmp(argv_zero_string, NOCATGETS("/usr/xpg4/bin/make"))) {
 385                 svr4 = false;
 386                 posix = true;
 387         } else {
 388                 prognameptr = strrchr(argv[0], '/');
 389                 if(prognameptr) {
 390                         prognameptr++;
 391                 } else {
 392                         prognameptr = argv[0];
 393                 }


 677                 
 678 /*
 679  *      Enable interrupt handler for alarms
 680  */
 681         (void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
 682 
 683 /*
 684  *      Check if make should report
 685  */
 686         if (getenv(sunpro_dependencies->string_mb) != NULL) {
 687                 FILE    *report_file;
 688 
 689                 report_dependency("");
 690                 report_file = get_report_file();
 691                 if ((report_file != NULL) && (report_file != (FILE*)-1)) {
 692                         (void) fprintf(report_file, "\n");
 693                 }
 694         }
 695 
 696 /*
 697  *      Make sure SUNPRO_DEPENDENCIES is exported (or not) properly.

 698  */
 699         if (keep_state) {
 700                 maybe_append_prop(sunpro_dependencies, macro_prop)->
 701                   body.macro.exported = true;



 702         } else {
 703                 maybe_append_prop(sunpro_dependencies, macro_prop)->
 704                   body.macro.exported = false;
 705         }
 706 
 707         working_on_targets = true;
 708         if (trace_status) {
 709                 dump_make_state();
 710                 fclose(stdout);
 711                 fclose(stderr);
 712                 exit_status = 0;
 713                 exit(0);
 714         }
 715         if (list_all_targets) {
 716                 dump_target_list();
 717                 fclose(stdout);
 718                 fclose(stderr);
 719                 exit_status = 0;
 720                 exit(0);
 721         }


 744                         char    tmp_current_path2[MAXPATHLEN];
 745  
 746                         (void) sprintf(tmp_current_path2,
 747                                        "%s/%s",
 748                                        get_current_path(),
 749                                        make_state_dir);
 750                         temp_file_directory = strdup(tmp_current_path2);
 751                 }
 752         }
 753 
 754 #ifdef DISTRIBUTED
 755         building_serial = false;
 756 #endif
 757 
 758         report_dir_enter_leave(true);
 759 
 760         make_targets(argc, argv, parallel_flag);
 761 
 762         report_dir_enter_leave(false);
 763 



 764         if (build_failed_ever_seen) {
 765                 if (posix) {
 766                         exit_status = 1;
 767                 }
 768                 exit(1);
 769         }
 770         exit_status = 0;
 771         exit(0);

 772         /* NOTREACHED */
 773 }
 774 
 775 /*
 776  *      cleanup_after_exit()
 777  *
 778  *      Called from exit(), performs cleanup actions.
 779  *
 780  *      Parameters:
 781  *              status          The argument exit() was called with
 782  *              arg             Address of an argument vector to
 783  *                              cleanup_after_exit()
 784  *
 785  *      Global variables used:
 786  *              command_changed Set if we think .make.state should be rewritten
 787  *              current_line    Is set we set commands_changed
 788  *              do_not_exec_rule
 789  *                              True if -n flag on
 790  *              done            The Name ".DONE", rule we run
 791  *              keep_state      Set if .KEEP_STATE seen
 792  *              parallel        True if building in parallel
 793  *              quest           If -q is on we do not run .DONE
 794  *              report_dependencies
 795  *                              True if -P flag on
 796  *              running_list    List of parallel running processes
 797  *              temp_file_name  The temp file is removed, if any
 798  *              catd    the message catalog file
 799  *              usage_tracking  Should have been constructed in main()
 800  *                              should destroyed just before exiting
 801  */
 802 extern "C" void
 803 cleanup_after_exit(void)
 804 {
 805         Running         rp;





 806 
 807 extern long     getname_bytes_count;
 808 extern long     getname_names_count;
 809 extern long     getname_struct_count;
 810 extern long     freename_bytes_count;
 811 extern long     freename_names_count;
 812 extern long     freename_struct_count;
 813 extern long     other_alloc;
 814 
 815 extern long     env_alloc_num;
 816 extern long     env_alloc_bytes;
 817 
 818 
 819 #ifdef DMAKE_STATISTICS
 820 if(getname_stat) {
 821         printf(NOCATGETS(">>> Getname statistics:\n"));
 822         printf(NOCATGETS("  Allocated:\n"));
 823         printf(NOCATGETS("        Names: %ld\n"), getname_names_count);
 824         printf(NOCATGETS("      Strings: %ld Kb (%ld bytes)\n"), getname_bytes_count/1000, getname_bytes_count);
 825         printf(NOCATGETS("      Structs: %ld Kb (%ld bytes)\n"), getname_struct_count/1000, getname_struct_count);


 926         /* Remove the statefile lock file if the file has been locked */
 927         if ((make_state_lockfile != NULL) && (make_state_locked)) {
 928                 (void) unlink(make_state_lockfile);
 929                 make_state_lockfile = NULL;
 930                 make_state_locked = false;
 931         }
 932         /* Write .make.state */
 933         write_state_file(1, (Boolean) 1);
 934 
 935 #ifdef TEAMWARE_MAKE_CMN
 936         // Deleting the usage tracking object sends the usage mail 
 937 #ifdef USE_DMS_CCR
 938         //usageTracking->setExitStatus(exit_status, NULL);
 939         //delete usageTracking;
 940 #else
 941         cleanup->set_exit_status(exit_status);
 942         delete cleanup;
 943 #endif
 944 #endif
 945 


















 946 /*
 947 #ifdef DISTRIBUTED
 948     }
 949 #endif
 950  */
 951 
 952 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
 953         job_adjust_fini();
 954 #endif
 955 
 956 #ifdef TEAMWARE_MAKE_CMN
 957         catclose(catd);
 958 #endif
 959 #ifdef DISTRIBUTED
 960         if (rxmPid > 0) {
 961                 // Tell rxm to exit by sending it an Avo_AcknowledgeMsg
 962                 Avo_AcknowledgeMsg acknowledgeMsg;
 963                 RWCollectable *msg = (RWCollectable *)&acknowledgeMsg;
 964 
 965                 int xdrResult = xdr(&xdrs_out, msg);


1110                                                        rp->target->string_mb,
1111                                                        errmsg(errno));
1112                                 }
1113                         }
1114                 }
1115         }
1116 
1117 #ifdef SGE_SUPPORT
1118         /* Remove SGE script file */
1119         if (grid) {
1120                 unlink(script_file);
1121         }
1122 #endif
1123 
1124         /* Have we locked .make.state or .nse_depinfo? */
1125         if ((make_state_lockfile != NULL) && (make_state_locked)) {
1126                 unlink(make_state_lockfile);
1127                 make_state_lockfile = NULL;
1128                 make_state_locked = false;
1129         }







1130         /*
1131          * Re-read .make.state file (it might be changed by recursive make)
1132          */
1133         check_state(NULL);
1134 
1135         report_dir_enter_leave(false);
1136 
1137         exit_status = 2;
1138         exit(2);
1139 }
1140 
1141 /*
1142  *      doalarm(sig, ...)
1143  *
1144  *      Handle the alarm interrupt but do nothing.  Side effect is to
1145  *      cause return from wait3.
1146  *
1147  *      Parameters:
1148  *              sig
1149  *


1641                 if (invert_this) {
1642                         dmake_rcfile_specified = false;
1643                 } else {
1644                         dmake_rcfile_specified = true;
1645                 }
1646                 return 2;
1647         case 'D':                        /* Show lines read */
1648                 if (invert_this) {
1649                         read_trace_level--;
1650                 } else {
1651                         read_trace_level++;
1652                 }
1653                 return 0;
1654         case 'd':                        /* Debug flag */
1655                 if (invert_this) {
1656                         debug_level--;
1657                 } else {
1658                         debug_level++;
1659                 }
1660                 return 0;










1661         case 'e':                        /* Environment override flag */
1662                 if (invert_this) {
1663                         env_wins = false;
1664                 } else {
1665                         env_wins = true;
1666                 }
1667                 return 0;
1668         case 'f':                        /* Read alternative makefile(s) */
1669                 return 1;
1670         case 'g':                        /* Use alternative DMake group */
1671                 if (invert_this) {
1672                         dmake_group_specified = false;
1673                 } else {
1674                         dmake_group_specified = true;
1675                 }
1676                 return 4;
1677         case 'i':                        /* Ignore errors */
1678                 if (invert_this) {
1679                         ignore_errors_all = false;
1680                 } else {


1991  *
1992  *      Parameters:
1993  *              argc            You know what this is
1994  *              argv            You know what this is
1995  *
1996  *      Static variables used:
1997  *              env_wins        make -e, determines if env vars are RO
1998  *              ignore_default_mk make -r, determines if make.rules is read
1999  *              not_auto_depen  dwight
2000  *
2001  *      Global variables used:
2002  *              default_target_to_build Set to first proper target from file
2003  *              do_not_exec_rule Set to false when makfile is made
2004  *              dot             The Name ".", used to read current dir
2005  *              empty_name      The Name "", use as macro value
2006  *              keep_state      Set if KEEP_STATE is in environment
2007  *              make_state      The Name ".make.state", used to read file
2008  *              makefile_type   Set to type of file being read
2009  *              makeflags       The Name "MAKEFLAGS", used to set macro value
2010  *              not_auto        dwight

2011  *              read_trace_level Checked to se if the reader should trace
2012  *              report_dependencies If -P is on we do not read .make.state
2013  *              trace_reader    Set if reader should trace
2014  *              virtual_root    The Name "VIRTUAL_ROOT", used to check value
2015  */
2016 static void
2017 read_files_and_state(int argc, char **argv)
2018 {
2019         wchar_t                 buffer[1000];
2020         wchar_t                 buffer_posix[1000];
2021         register char           ch;
2022         register char           *cp;
2023         Property                def_make_macro = NULL;
2024         Name                    def_make_name;
2025         Name                    default_makefile;
2026         String_rec              dest;
2027         wchar_t                 destbuffer[STRING_BUFFER_LENGTH];
2028         register int            i;
2029         register int            j;
2030         Name                    keep_state_name;


2057 /*
2058  *      Remember current mode. It may be changed after reading makefile
2059  *      and we will have to correct MAKEFLAGS variable.
2060  */
2061         is_xpg4 = posix;
2062 
2063         MBSTOWCS(wcs_buffer, NOCATGETS("KEEP_STATE"));
2064         keep_state_name = GETNAME(wcs_buffer, FIND_LENGTH);
2065         MBSTOWCS(wcs_buffer, NOCATGETS("Makefile"));
2066         Makefile = GETNAME(wcs_buffer, FIND_LENGTH);
2067         MBSTOWCS(wcs_buffer, NOCATGETS("makefile"));
2068         makefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
2069         MBSTOWCS(wcs_buffer, NOCATGETS("s.makefile"));
2070         sdotmakefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
2071         MBSTOWCS(wcs_buffer, NOCATGETS("s.Makefile"));
2072         sdotMakefile = GETNAME(wcs_buffer, FIND_LENGTH);
2073 
2074 /*
2075  *      Set flag if NSE is active
2076  */





2077 
2078 /*
2079  *      initialize global dependency entry for .NOT_AUTO
2080  */
2081         not_auto_depen->next = NULL;
2082         not_auto_depen->name = not_auto;
2083         not_auto_depen->automatic = not_auto_depen->stale = false;
2084 
2085 /*
2086  *      Read internal definitions and rules.
2087  */
2088         if (read_trace_level > 1) {
2089                 trace_reader = true;
2090         }
2091         if (!ignore_default_mk) {
2092                 if (svr4) {
2093                         MBSTOWCS(wcs_buffer, NOCATGETS("svr4.make.rules"));
2094                         default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
2095                 } else {
2096                         MBSTOWCS(wcs_buffer, NOCATGETS("make.rules"));


2161         INIT_STRING_FROM_STACK(makeflags_string_posix, buffer_posix);
2162         append_char((int) hyphen_char, &makeflags_string);
2163         append_char((int) hyphen_char, &makeflags_string_posix);
2164 
2165         switch (read_trace_level) {
2166         case 2:
2167                 append_char('D', &makeflags_string);
2168                 append_char('D', &makeflags_string_posix);
2169         case 1:
2170                 append_char('D', &makeflags_string);
2171                 append_char('D', &makeflags_string_posix);
2172         }
2173         switch (debug_level) {
2174         case 2:
2175                 append_char('d', &makeflags_string);
2176                 append_char('d', &makeflags_string_posix);
2177         case 1:
2178                 append_char('d', &makeflags_string);
2179                 append_char('d', &makeflags_string_posix);
2180         }





2181         if (env_wins) {
2182                 append_char('e', &makeflags_string);
2183                 append_char('e', &makeflags_string_posix);
2184         }
2185         if (ignore_errors_all) {
2186                 append_char('i', &makeflags_string);
2187                 append_char('i', &makeflags_string_posix);
2188         }
2189         if (continue_after_error) {
2190                 if (stop_after_error_ever_seen) {
2191                         append_char('S', &makeflags_string_posix);
2192                         append_char((int) space_char, &makeflags_string_posix);
2193                         append_char((int) hyphen_char, &makeflags_string_posix);
2194                 }
2195                 append_char('k', &makeflags_string);
2196                 append_char('k', &makeflags_string_posix);
2197         } else {
2198                 if (stop_after_error_ever_seen 
2199                     && continue_after_error_ever_seen) {
2200                         append_char('k', &makeflags_string_posix);


2964                 MBSTOWCS(wcs_buffer2, NOCATGETS("SHELL="));
2965                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2966                         continue;
2967                 }
2968                 MBSTOWCS(wcs_buffer2, NOCATGETS("MAKEFLAGS="));
2969                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2970                         report_pwd = true;
2971                         /*
2972                          * In POSIX mode we do not want MAKEFLAGS to be readonly.
2973                          * If the MAKEFLAGS macro is subsequently set by the makefile,
2974                          * it replaces the MAKEFLAGS variable currently found in the
2975                          * environment.
2976                          * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
2977                          */
2978                         if(posix) {
2979                                 read_only_saved = false;
2980                         }
2981                 }
2982 
2983                 /*
2984                  * We ignore SUNPRO_DEPENDENCIES. This environment variable is
2985                  * set by make and read by cpp which then writes info to
2986                  * .make.dependency.xxx.  When make is invoked by another make
2987                  * (recursive make), we don't want to read this because then
2988                  * the child make will end up writing to the parent
2989                  * directory's .make.state and clobbering them.


2990                  */
2991                 MBSTOWCS(wcs_buffer2, NOCATGETS("SUNPRO_DEPENDENCIES"));
2992                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2993                         continue;
2994                 }






2995 
2996                 macro = GETNAME(name, value - name);
2997                 maybe_append_prop(macro, macro_prop)->body.macro.exported =
2998                   true;
2999                 if ((value == NULL) || ((value + 1)[0] == (int) nul_char)) {
3000                         val = setvar_daemon(macro,
3001                                             (Name) NULL,
3002                                             false, no_daemon, false, debug_level);
3003                 } else {
3004                         val = setvar_daemon(macro,
3005                                             GETNAME(value + 1, FIND_LENGTH),
3006                                             false, no_daemon, false, debug_level);
3007                 }







3008                 val->body.macro.read_only = read_only_saved;
3009                 if (alloced_tmp_wcs_buffer) {
3010                         retmem(tmp_wcs_buffer);
3011                         alloced_tmp_wcs_buffer = false;
3012                 }
3013         }
3014         reading_environment = false;
3015 }
3016 
3017 /*
3018  *      read_makefile(makefile, complain, must_exist, report_file)
3019  *
3020  *      Read one makefile and check the result
3021  *
3022  *      Return value:
3023  *                              false is the read failed
3024  *
3025  *      Parameters:
3026  *              makefile        The file to read
3027  *              complain        Passed thru to read_simple_file()
3028  *              must_exist      Passed thru to read_simple_file()
3029  *              report_file     Passed thru to read_simple_file()
3030  *
3031  *      Global variables used:
3032  *              makefile_type   Set to indicate we are reading main file
3033  *              recursion_level Initialized
3034  */
3035 static Boolean
3036 read_makefile(register Name makefile, Boolean complain, Boolean must_exist, Boolean report_file)
3037 {
3038         Boolean                 b;
3039         
3040         makefile_type = reading_makefile;
3041         recursion_level = 0;



3042         reading_dependencies = true;
3043         b = read_simple_file(makefile, true, true, complain,
3044                              must_exist, report_file, false);
3045         reading_dependencies = false;
3046         return b;
3047 }
3048 
3049 /*
3050  *      make_targets(argc, argv, parallel_flag)
3051  *
3052  *      Call doname on the specified targets
3053  *
3054  *      Parameters:
3055  *              argc            You know what this is
3056  *              argv            You know what this is
3057  *              parallel_flag   True if building in parallel
3058  *
3059  *      Global variables used:
3060  *              build_failed_seen Used to generated message after failed -k
3061  *              commands_done   Used to generate message "Up to date"


3312  *              target          Target to report
3313  *
3314  *      Global variables used:
3315  *              makefiles_used          List of makefiles read
3316  *              recursive_name          The Name ".RECURSIVE", printed
3317  *              report_dependency       dwight
3318  */
3319 static void
3320 report_recursion(register Name target)
3321 {
3322         register FILE           *report_file = get_report_file();
3323 
3324         if ((report_file == NULL) || (report_file == (FILE*)-1)) {
3325                 return;
3326         }
3327         if (primary_makefile == NULL) {
3328                 /*
3329                  * This can happen when there is no makefile and
3330                  * only implicit rules are being used.
3331                  */



3332                 return;
3333         }
3334         (void) fprintf(report_file,
3335                        "%s: %s ",
3336                        get_target_being_reported_for(),
3337                        recursive_name->string_mb);
3338         report_dependency(get_current_path());
3339         report_dependency(target->string_mb);
3340         report_dependency(primary_makefile->string_mb);
3341         (void) fprintf(report_file, "\n");
3342 }
3343 
3344 /* Next function "append_or_replace_macro_in_dyn_array" must be in "misc.cc". */
3345 /* NIKMOL */
3346 extern void
3347 append_or_replace_macro_in_dyn_array(ASCII_Dyn_Array *Ar, char *macro)
3348 {
3349         register char   *cp0;   /* work pointer in macro */
3350         register char   *cp1;   /* work pointer in array */
3351         register char   *cp2;   /* work pointer in array */