Print this page
make: use the more modern wchar routines, not widec.h


1813                         default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1814                 } else {
1815                         MBSTOWCS(wcs_buffer, "make.rules");
1816                         default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1817                 }
1818                 default_makefile->stat.is_file = true;
1819 
1820                 (void) read_makefile(default_makefile,
1821                                      true,
1822                                      false,
1823                                      true);
1824         }
1825 
1826         /*
1827          * If the user did not redefine the MAKE macro in the
1828          * default makefile (make.rules), then we'd like to
1829          * change the macro value of MAKE to be some form
1830          * of argv[0] for recursive MAKE builds.
1831          */
1832         MBSTOWCS(wcs_buffer, "MAKE");
1833         def_make_name = GETNAME(wcs_buffer, wslen(wcs_buffer));
1834         def_make_macro = get_prop(def_make_name->prop, macro_prop);
1835         if ((def_make_macro != NULL) &&
1836             (IS_EQUAL(def_make_macro->body.macro.value->string_mb,
1837                       "make"))) {
1838                 MBSTOWCS(wcs_buffer, argv_zero_string);
1839                 new_make_value = GETNAME(wcs_buffer, wslen(wcs_buffer));
1840                 (void) SETVAR(def_make_name,
1841                               new_make_value,
1842                               false);
1843         }
1844 
1845         default_target_to_build = NULL;
1846         trace_reader = false;
1847 
1848 /*
1849  *      Read environment args. Let file args which follow override unless
1850  *      -e option seen. If -e option is not mentioned.
1851  */
1852         read_environment(env_wins);
1853         if (getvar(virtual_root)->hash.length == 0) {
1854                 maybe_append_prop(virtual_root, macro_prop)
1855                   ->body.macro.exported = true;
1856                 MBSTOWCS(wcs_buffer, "/");
1857                 (void) SETVAR(virtual_root,
1858                               GETNAME(wcs_buffer, FIND_LENGTH),
1859                               false);


2268                 }
2269         }
2270 
2271         if (makeflags_string.free_after_use) {
2272                 retmem(makeflags_string.buffer.start);
2273         }
2274         if (makeflags_string_posix.free_after_use) {
2275                 retmem(makeflags_string_posix.buffer.start);
2276         }
2277         makeflags_string.buffer.start = NULL;
2278         makeflags_string_posix.buffer.start = NULL;
2279 
2280         if (posix) {
2281                 /*
2282                  * If the user did not redefine the ARFLAGS macro in the
2283                  * default makefile (make.rules), then we'd like to
2284                  * change the macro value of ARFLAGS to be in accordance
2285                  * with "POSIX" requirements.
2286                  */
2287                 MBSTOWCS(wcs_buffer, "ARFLAGS");
2288                 name = GETNAME(wcs_buffer, wslen(wcs_buffer));
2289                 macro = get_prop(name->prop, macro_prop);
2290                 if ((macro != NULL) && /* Maybe (macro == NULL) || ? */
2291                     (IS_EQUAL(macro->body.macro.value->string_mb,
2292                               "rv"))) {
2293                         MBSTOWCS(wcs_buffer, "-rv");
2294                         value = GETNAME(wcs_buffer, wslen(wcs_buffer));
2295                         (void) SETVAR(name,
2296                                       value,
2297                                       false);
2298                 }
2299         }
2300 
2301         if (!posix && !svr4) {
2302                 set_sgs_support();
2303         }
2304 
2305 
2306 /*
2307  *      Make sure KEEP_STATE is in the environment if KEEP_STATE is on.
2308  */
2309         macro = get_prop(keep_state_name->prop, macro_prop);
2310         if ((macro != NULL) &&
2311             macro->body.macro.exported) {
2312                 keep_state = true;
2313         }
2314         if (keep_state) {


2530 /* 
2531  * Combine all macro in dynamic array
2532  */
2533                         if(*(cp-1) == (int) plus_char)
2534                         {
2535                                 if(isspace(*(cp-2))) {
2536                                         append = true;
2537                                         cp--;
2538                                 }
2539                         }
2540                         if(!append)
2541                                 append_or_replace_macro_in_dyn_array(makeflags_and_macro, argv[i]);
2542 
2543                         while (isspace(*(cp-1))) {
2544                                 cp--;
2545                         }
2546                         tmp_char = *cp;
2547                         *cp = (int) nul_char;
2548                         MBSTOWCS(wcs_buffer, argv[i]);
2549                         *cp = tmp_char;
2550                         name = GETNAME(wcs_buffer, wslen(wcs_buffer));
2551                         while (*cp != (int) equal_char) {
2552                                 cp++;
2553                         }
2554                         cp++;
2555                         while (isspace(*cp) && (*cp != (int) nul_char)) {
2556                                 cp++;
2557                         }
2558                         if ((length = strlen(cp)) >= MAXPATHLEN) {
2559                                 tmp_wcs_buffer = ALLOC_WC(length + 1);
2560                                 (void) mbstowcs(tmp_wcs_buffer, cp, length + 1);
2561                                 value = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2562                                 retmem(tmp_wcs_buffer);
2563                         } else {
2564                                 MBSTOWCS(wcs_buffer, cp);
2565                                 value = GETNAME(wcs_buffer, FIND_LENGTH);
2566                         }
2567                         argv[i] = NULL;
2568                 } else {
2569                         /* Illegal MAKEFLAGS argument */
2570                         continue;


2640         Boolean                 alloced_tmp_wcs_buffer = false;
2641         register wchar_t        *name;
2642         register wchar_t        *value;
2643         register Name           macro;
2644         Property                val;
2645         Boolean                 read_only_saved;
2646 
2647         reading_environment = true;
2648         environment = environ;
2649         for (; *environment; environment++) {
2650                 read_only_saved = read_only;
2651                 if ((length = strlen(*environment)) >= MAXPATHLEN) {
2652                         tmp_wcs_buffer = ALLOC_WC(length + 1);
2653                         alloced_tmp_wcs_buffer = true;
2654                         (void) mbstowcs(tmp_wcs_buffer, *environment, length + 1);
2655                         name = tmp_wcs_buffer;
2656                 } else {
2657                         MBSTOWCS(wcs_buffer, *environment);
2658                         name = wcs_buffer;
2659                 }
2660                 value = (wchar_t *) wschr(name, (int) equal_char);
2661 
2662                 /*
2663                  * Looks like there's a bug in the system, but sometimes
2664                  * you can get blank lines in *environment.
2665                  */
2666                 if (!value) {
2667                         continue;
2668                 }
2669                 MBSTOWCS(wcs_buffer2, "SHELL=");
2670                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2671                         continue;
2672                 }
2673                 MBSTOWCS(wcs_buffer2, "MAKEFLAGS=");
2674                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2675                         report_pwd = true;
2676                         /*
2677                          * In POSIX mode we do not want MAKEFLAGS to be readonly.
2678                          * If the MAKEFLAGS macro is subsequently set by the makefile,
2679                          * it replaces the MAKEFLAGS variable currently found in the
2680                          * environment.
2681                          * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
2682                          */
2683                         if(posix) {
2684                                 read_only_saved = false;
2685                         }
2686                 }
2687 
2688                 /*
2689                  * We ignore SUNPRO_DEPENDENCIES. This environment variable is
2690                  * set by make and read by cpp which then writes info to
2691                  * .make.dependency.xxx.  When make is invoked by another make
2692                  * (recursive make), we don't want to read this because then
2693                  * the child make will end up writing to the parent
2694                  * directory's .make.state and clobbering them.
2695                  */
2696                 MBSTOWCS(wcs_buffer2, "SUNPRO_DEPENDENCIES");
2697                 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2698                         continue;
2699                 }
2700 
2701                 macro = GETNAME(name, value - name);
2702                 maybe_append_prop(macro, macro_prop)->body.macro.exported =
2703                   true;
2704                 if ((value == NULL) || ((value + 1)[0] == (int) nul_char)) {
2705                         val = setvar_daemon(macro,
2706                                             (Name) NULL,
2707                                             false, no_daemon, false, debug_level);
2708                 } else {
2709                         val = setvar_daemon(macro,
2710                                             GETNAME(value + 1, FIND_LENGTH),
2711                                             false, no_daemon, false, debug_level);
2712                 }
2713                 val->body.macro.read_only = read_only_saved;
2714                 if (alloced_tmp_wcs_buffer) {
2715                         retmem(tmp_wcs_buffer);
2716                         alloced_tmp_wcs_buffer = false;
2717                 }


2794                  * remaining args to build in parallel.
2795                  */
2796                 for (i = 1; i < argc; i++) {
2797                         if ((cp = argv[i]) != NULL) {
2798                                 commands_done = false;
2799                                 if ((cp[0] == (int) period_char) &&
2800                                     (cp[1] == (int) slash_char)) {
2801                                         cp += 2;
2802                                 }
2803                                  if((cp[0] == (int) ' ') &&
2804                                     (cp[1] == (int) '-') &&
2805                                     (cp[2] == (int) ' ') &&
2806                                     (cp[3] == (int) '-')) {
2807                                     argv[i] = NULL;
2808                                         continue;
2809                                 }
2810                                 MBSTOWCS(wcs_buffer, cp);
2811                                 //default_target_to_build = GETNAME(wcs_buffer,
2812                                 //                                FIND_LENGTH);
2813                                 default_target_to_build = normalize_name(wcs_buffer,
2814                                                                   wslen(wcs_buffer));
2815                                 if (default_target_to_build == wait_name) {
2816                                         if (parallel_process_cnt > 0) {
2817                                                 finish_running();
2818                                         }
2819                                         continue;
2820                                 }
2821                                 top_level_target = get_wstring(default_target_to_build->string_mb);
2822                                 /*
2823                                  * If we can't execute the current target in
2824                                  * parallel, hold off the target processing
2825                                  * to preserve the order of the targets as they appeared
2826                                  * in command line.
2827                                  */
2828                                 if (!parallel_ok(default_target_to_build, false)
2829                                                 && parallel_process_cnt > 0) {
2830                                         finish_running();
2831                                 }
2832                                 result = doname_check(default_target_to_build,
2833                                                       true,
2834                                                       false,


2863                 /* Now wait for all of the targets to finish running */
2864                 finish_running();
2865                 //              setjmp(jmpbuffer);
2866                 
2867         }
2868         for (i = 1; i < argc; i++) {
2869                 if ((cp = argv[i]) != NULL) {
2870                         target_to_make_found = true;
2871                         if ((cp[0] == (int) period_char) &&
2872                             (cp[1] == (int) slash_char)) {
2873                                 cp += 2;
2874                         }
2875                                  if((cp[0] == (int) ' ') &&
2876                                     (cp[1] == (int) '-') &&
2877                                     (cp[2] == (int) ' ') &&
2878                                     (cp[3] == (int) '-')) {
2879                                     argv[i] = NULL;
2880                                         continue;
2881                                 }
2882                         MBSTOWCS(wcs_buffer, cp);
2883                         default_target_to_build = normalize_name(wcs_buffer, wslen(wcs_buffer));
2884                         top_level_target = get_wstring(default_target_to_build->string_mb);
2885                         report_recursion(default_target_to_build);
2886                         commands_done = false;
2887                         if (parallel) {
2888                                 result = (Doname) default_target_to_build->state;
2889                         } else {
2890                                 result = doname_check(default_target_to_build,
2891                                                       true,
2892                                                       false,
2893                                                       false);
2894                         }
2895                         gather_recursive_deps();
2896                         if (build_failed_seen) {
2897                                 build_failed_ever_seen = true;
2898                                 warning(gettext("Target `%s' not remade because of errors"),
2899                                         default_target_to_build->string_mb);
2900                         }
2901                         build_failed_seen = false;
2902                         if (report_dependencies_level > 0) {
2903                                 print_dependencies(default_target_to_build,




1813                         default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1814                 } else {
1815                         MBSTOWCS(wcs_buffer, "make.rules");
1816                         default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1817                 }
1818                 default_makefile->stat.is_file = true;
1819 
1820                 (void) read_makefile(default_makefile,
1821                                      true,
1822                                      false,
1823                                      true);
1824         }
1825 
1826         /*
1827          * If the user did not redefine the MAKE macro in the
1828          * default makefile (make.rules), then we'd like to
1829          * change the macro value of MAKE to be some form
1830          * of argv[0] for recursive MAKE builds.
1831          */
1832         MBSTOWCS(wcs_buffer, "MAKE");
1833         def_make_name = GETNAME(wcs_buffer, wcslen(wcs_buffer));
1834         def_make_macro = get_prop(def_make_name->prop, macro_prop);
1835         if ((def_make_macro != NULL) &&
1836             (IS_EQUAL(def_make_macro->body.macro.value->string_mb,
1837                       "make"))) {
1838                 MBSTOWCS(wcs_buffer, argv_zero_string);
1839                 new_make_value = GETNAME(wcs_buffer, wcslen(wcs_buffer));
1840                 (void) SETVAR(def_make_name,
1841                               new_make_value,
1842                               false);
1843         }
1844 
1845         default_target_to_build = NULL;
1846         trace_reader = false;
1847 
1848 /*
1849  *      Read environment args. Let file args which follow override unless
1850  *      -e option seen. If -e option is not mentioned.
1851  */
1852         read_environment(env_wins);
1853         if (getvar(virtual_root)->hash.length == 0) {
1854                 maybe_append_prop(virtual_root, macro_prop)
1855                   ->body.macro.exported = true;
1856                 MBSTOWCS(wcs_buffer, "/");
1857                 (void) SETVAR(virtual_root,
1858                               GETNAME(wcs_buffer, FIND_LENGTH),
1859                               false);


2268                 }
2269         }
2270 
2271         if (makeflags_string.free_after_use) {
2272                 retmem(makeflags_string.buffer.start);
2273         }
2274         if (makeflags_string_posix.free_after_use) {
2275                 retmem(makeflags_string_posix.buffer.start);
2276         }
2277         makeflags_string.buffer.start = NULL;
2278         makeflags_string_posix.buffer.start = NULL;
2279 
2280         if (posix) {
2281                 /*
2282                  * If the user did not redefine the ARFLAGS macro in the
2283                  * default makefile (make.rules), then we'd like to
2284                  * change the macro value of ARFLAGS to be in accordance
2285                  * with "POSIX" requirements.
2286                  */
2287                 MBSTOWCS(wcs_buffer, "ARFLAGS");
2288                 name = GETNAME(wcs_buffer, wcslen(wcs_buffer));
2289                 macro = get_prop(name->prop, macro_prop);
2290                 if ((macro != NULL) && /* Maybe (macro == NULL) || ? */
2291                     (IS_EQUAL(macro->body.macro.value->string_mb,
2292                               "rv"))) {
2293                         MBSTOWCS(wcs_buffer, "-rv");
2294                         value = GETNAME(wcs_buffer, wcslen(wcs_buffer));
2295                         (void) SETVAR(name,
2296                                       value,
2297                                       false);
2298                 }
2299         }
2300 
2301         if (!posix && !svr4) {
2302                 set_sgs_support();
2303         }
2304 
2305 
2306 /*
2307  *      Make sure KEEP_STATE is in the environment if KEEP_STATE is on.
2308  */
2309         macro = get_prop(keep_state_name->prop, macro_prop);
2310         if ((macro != NULL) &&
2311             macro->body.macro.exported) {
2312                 keep_state = true;
2313         }
2314         if (keep_state) {


2530 /* 
2531  * Combine all macro in dynamic array
2532  */
2533                         if(*(cp-1) == (int) plus_char)
2534                         {
2535                                 if(isspace(*(cp-2))) {
2536                                         append = true;
2537                                         cp--;
2538                                 }
2539                         }
2540                         if(!append)
2541                                 append_or_replace_macro_in_dyn_array(makeflags_and_macro, argv[i]);
2542 
2543                         while (isspace(*(cp-1))) {
2544                                 cp--;
2545                         }
2546                         tmp_char = *cp;
2547                         *cp = (int) nul_char;
2548                         MBSTOWCS(wcs_buffer, argv[i]);
2549                         *cp = tmp_char;
2550                         name = GETNAME(wcs_buffer, wcslen(wcs_buffer));
2551                         while (*cp != (int) equal_char) {
2552                                 cp++;
2553                         }
2554                         cp++;
2555                         while (isspace(*cp) && (*cp != (int) nul_char)) {
2556                                 cp++;
2557                         }
2558                         if ((length = strlen(cp)) >= MAXPATHLEN) {
2559                                 tmp_wcs_buffer = ALLOC_WC(length + 1);
2560                                 (void) mbstowcs(tmp_wcs_buffer, cp, length + 1);
2561                                 value = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2562                                 retmem(tmp_wcs_buffer);
2563                         } else {
2564                                 MBSTOWCS(wcs_buffer, cp);
2565                                 value = GETNAME(wcs_buffer, FIND_LENGTH);
2566                         }
2567                         argv[i] = NULL;
2568                 } else {
2569                         /* Illegal MAKEFLAGS argument */
2570                         continue;


2640         Boolean                 alloced_tmp_wcs_buffer = false;
2641         register wchar_t        *name;
2642         register wchar_t        *value;
2643         register Name           macro;
2644         Property                val;
2645         Boolean                 read_only_saved;
2646 
2647         reading_environment = true;
2648         environment = environ;
2649         for (; *environment; environment++) {
2650                 read_only_saved = read_only;
2651                 if ((length = strlen(*environment)) >= MAXPATHLEN) {
2652                         tmp_wcs_buffer = ALLOC_WC(length + 1);
2653                         alloced_tmp_wcs_buffer = true;
2654                         (void) mbstowcs(tmp_wcs_buffer, *environment, length + 1);
2655                         name = tmp_wcs_buffer;
2656                 } else {
2657                         MBSTOWCS(wcs_buffer, *environment);
2658                         name = wcs_buffer;
2659                 }
2660                 value = (wchar_t *) wcschr(name, (int) equal_char);
2661 
2662                 /*
2663                  * Looks like there's a bug in the system, but sometimes
2664                  * you can get blank lines in *environment.
2665                  */
2666                 if (!value) {
2667                         continue;
2668                 }
2669                 MBSTOWCS(wcs_buffer2, "SHELL=");
2670                 if (IS_WEQUALN(name, wcs_buffer2, wcslen(wcs_buffer2))) {
2671                         continue;
2672                 }
2673                 MBSTOWCS(wcs_buffer2, "MAKEFLAGS=");
2674                 if (IS_WEQUALN(name, wcs_buffer2, wcslen(wcs_buffer2))) {
2675                         report_pwd = true;
2676                         /*
2677                          * In POSIX mode we do not want MAKEFLAGS to be readonly.
2678                          * If the MAKEFLAGS macro is subsequently set by the makefile,
2679                          * it replaces the MAKEFLAGS variable currently found in the
2680                          * environment.
2681                          * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
2682                          */
2683                         if(posix) {
2684                                 read_only_saved = false;
2685                         }
2686                 }
2687 
2688                 /*
2689                  * We ignore SUNPRO_DEPENDENCIES. This environment variable is
2690                  * set by make and read by cpp which then writes info to
2691                  * .make.dependency.xxx.  When make is invoked by another make
2692                  * (recursive make), we don't want to read this because then
2693                  * the child make will end up writing to the parent
2694                  * directory's .make.state and clobbering them.
2695                  */
2696                 MBSTOWCS(wcs_buffer2, "SUNPRO_DEPENDENCIES");
2697                 if (IS_WEQUALN(name, wcs_buffer2, wcslen(wcs_buffer2))) {
2698                         continue;
2699                 }
2700 
2701                 macro = GETNAME(name, value - name);
2702                 maybe_append_prop(macro, macro_prop)->body.macro.exported =
2703                   true;
2704                 if ((value == NULL) || ((value + 1)[0] == (int) nul_char)) {
2705                         val = setvar_daemon(macro,
2706                                             (Name) NULL,
2707                                             false, no_daemon, false, debug_level);
2708                 } else {
2709                         val = setvar_daemon(macro,
2710                                             GETNAME(value + 1, FIND_LENGTH),
2711                                             false, no_daemon, false, debug_level);
2712                 }
2713                 val->body.macro.read_only = read_only_saved;
2714                 if (alloced_tmp_wcs_buffer) {
2715                         retmem(tmp_wcs_buffer);
2716                         alloced_tmp_wcs_buffer = false;
2717                 }


2794                  * remaining args to build in parallel.
2795                  */
2796                 for (i = 1; i < argc; i++) {
2797                         if ((cp = argv[i]) != NULL) {
2798                                 commands_done = false;
2799                                 if ((cp[0] == (int) period_char) &&
2800                                     (cp[1] == (int) slash_char)) {
2801                                         cp += 2;
2802                                 }
2803                                  if((cp[0] == (int) ' ') &&
2804                                     (cp[1] == (int) '-') &&
2805                                     (cp[2] == (int) ' ') &&
2806                                     (cp[3] == (int) '-')) {
2807                                     argv[i] = NULL;
2808                                         continue;
2809                                 }
2810                                 MBSTOWCS(wcs_buffer, cp);
2811                                 //default_target_to_build = GETNAME(wcs_buffer,
2812                                 //                                FIND_LENGTH);
2813                                 default_target_to_build = normalize_name(wcs_buffer,
2814                                                                   wcslen(wcs_buffer));
2815                                 if (default_target_to_build == wait_name) {
2816                                         if (parallel_process_cnt > 0) {
2817                                                 finish_running();
2818                                         }
2819                                         continue;
2820                                 }
2821                                 top_level_target = get_wstring(default_target_to_build->string_mb);
2822                                 /*
2823                                  * If we can't execute the current target in
2824                                  * parallel, hold off the target processing
2825                                  * to preserve the order of the targets as they appeared
2826                                  * in command line.
2827                                  */
2828                                 if (!parallel_ok(default_target_to_build, false)
2829                                                 && parallel_process_cnt > 0) {
2830                                         finish_running();
2831                                 }
2832                                 result = doname_check(default_target_to_build,
2833                                                       true,
2834                                                       false,


2863                 /* Now wait for all of the targets to finish running */
2864                 finish_running();
2865                 //              setjmp(jmpbuffer);
2866                 
2867         }
2868         for (i = 1; i < argc; i++) {
2869                 if ((cp = argv[i]) != NULL) {
2870                         target_to_make_found = true;
2871                         if ((cp[0] == (int) period_char) &&
2872                             (cp[1] == (int) slash_char)) {
2873                                 cp += 2;
2874                         }
2875                                  if((cp[0] == (int) ' ') &&
2876                                     (cp[1] == (int) '-') &&
2877                                     (cp[2] == (int) ' ') &&
2878                                     (cp[3] == (int) '-')) {
2879                                     argv[i] = NULL;
2880                                         continue;
2881                                 }
2882                         MBSTOWCS(wcs_buffer, cp);
2883                         default_target_to_build = normalize_name(wcs_buffer, wcslen(wcs_buffer));
2884                         top_level_target = get_wstring(default_target_to_build->string_mb);
2885                         report_recursion(default_target_to_build);
2886                         commands_done = false;
2887                         if (parallel) {
2888                                 result = (Doname) default_target_to_build->state;
2889                         } else {
2890                                 result = doname_check(default_target_to_build,
2891                                                       true,
2892                                                       false,
2893                                                       false);
2894                         }
2895                         gather_recursive_deps();
2896                         if (build_failed_seen) {
2897                                 build_failed_ever_seen = true;
2898                                 warning(gettext("Target `%s' not remade because of errors"),
2899                                         default_target_to_build->string_mb);
2900                         }
2901                         build_failed_seen = false;
2902                         if (report_dependencies_level > 0) {
2903                                 print_dependencies(default_target_to_build,