10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER START
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The contents of this file are subject to the terms of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Common Development and Distribution License (the "License").
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You may not use this file except in compliance with the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * See the License for the specific language governing permissions
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and limitations under the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * When distributing Covered Code, include this CDDL HEADER in each
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If applicable, add the following below this CDDL HEADER, with the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER END
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Handle expansion of make macros
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Included files
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mksh/dosys.h> /* sh_command2string() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mksh/i18n.h> /* get_char_semantics_value() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mksh/read.h> /* get_next_block_fn() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * File table of contents
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void add_macro_to_global_list(Name macro_to_add);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void expand_value_with_daemon(Name, register Property macro, register String destination, Boolean cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void init_arch_macros(void);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void init_mach_macros(void);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * getvar(name)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return expanded value of macro.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The expanded value of the macro
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * name The name of the macro we want the value for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((name == host_arch) || (name == target_arch)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((name == host_mach) || (name == target_mach)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(maybe_append_prop(name, macro_prop)->body.macro.value,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = GETNAME(destination.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * expand_value(value, destination, cmd)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Recursively expands all macros in the string value.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * destination is where the expanded value should be appended.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * value The value we are expanding
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * destination Where to deposit the expansion
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * cmd If we are evaluating a command line we
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * turn \ quoting off
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweexpand_value(Name value, register String destination, Boolean cmd)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Make sure to get a string allocated even if it
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * will be empty.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_string(wcs_buffer, destination, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If the value we are expanding does not contain
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * any $, we don't have to parse it.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("Loop detected when expanding macro value `%s'"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Setup the structure we read from */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sourceb.string.text.p = sourceb.string.buffer.start = wcsdup(vals.get_string());
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Lift some pointers from the struct to local register variables */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* We parse the string in segments */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* We read chars until we find a $, then we append what we have read so far */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* (since last $ processing) to the destination. When we find a $ we call */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* expand_macro() and let it expand that particular $ reference into dest */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Quote $ in macro value */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Save the plain string we found since */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* start of string or previous $ */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Go expand the macro reference */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_macro(source, destination, sourceb.string.buffer.start, cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The string ran out. Get some more */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh("Internal error: Invalid byte sequence in expand_value()");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * expand_macro(source, destination, current_string, cmd)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Should be called with source->string.text.p pointing to
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the first char after the $ that starts a macro reference.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * source->string.text.p is returned pointing to the first char after
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the macro name.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * It will read the macro name, expanding any macros in it,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and get the value. The value is then expanded.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * destination is a String that is filled in with the expanded macro.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * It may be passed in referencing a buffer to expand the macro into.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Note that most expansions are done on demand, e.g. right
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * before the command is executed and not while the file is
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * being parsed.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * source The source block that references the string
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * destination Where to put the result
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * current_string The string we are expanding, for error msg
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * cmd If we are evaluating a command line we
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * turn \ quoting off
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * funny Vector of semantic tags for characters
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is_conditional Set if a conditional macro is refd
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * make_word_mentioned Set if the word "MAKE" is mentioned
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * makefile_type We deliver extra msg when reading makefiles
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * query The Name "?", compared against
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * query_mentioned Set if the word "?" is mentioned
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweexpand_macro(register Source source, register String destination, wchar_t *current_string, Boolean cmd)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register wchar_t *source_p = source->string.text.p;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register wchar_t *source_end = source->string.text.end;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *p = (wchar_t*)NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* First copy the (macro-expanded) macro name into string. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check the first char of the macro name to figure out what to do. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("'$' at end of string `%s'"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh("Internal error: Invalid byte sequence in expand_macro()");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Multi char name. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Multi char name. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("'$' at end of line"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Single char macro name. Just suck it up */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Handle multi-char macro names */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("Unmatched `%c' in string `%s'"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh("Internal error: Invalid byte sequence in expand_macro()");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("Unmatched `%c' on line"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Quote dollar in macro value. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Macro names may reference macros.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This expands the value of such macros into the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * macro name string.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_macro(source, &string, current_string, cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Allow nested pairs of () in the macro name. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Allow nested pairs of {} in the macro name. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * End of the name. Save the string in the macro
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * name string.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((*source_p == closer) && (--closer_level <= 0)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We got the macro name. We now inspect it to see if it
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * specifies any translations of the value.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* First check if we have a $(@D) type translation. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((get_char_semantics_value(string.buffer.start[0]) &
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("Illegal macro reference `%s'"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Internalize the macro name using the first char only. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) wcscpy(string.buffer.start, string.buffer.start + 2);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check for other kinds of translations. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((colon = (wchar_t *) wcschr(string.buffer.start,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We have a $(FOO:.c=.o) type translation.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Get the name of the macro proper.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Pickup all the translations. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (IS_WEQUAL(colon, colon_sh) || IS_WEQUAL(colon, colon_shell)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else if ((svr4) ||
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("= missing from replacement macro reference"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("= missing from replacement macro reference"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("%% missing from replacement macro reference"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader_mksh(gettext("%% missing from replacement macro reference"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe right_hand[i] = (wchar_t *) wcsdup(wcs_buffer);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } while ((percent = (wchar_t *) wcschr(eq, (int) percent_char)) != NULL);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * No translations found.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use the whole string as the macro name.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((name == host_arch) || (name == target_arch)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((name == host_mach) || (name == target_mach)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Get the macro value. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((macro != NULL) && macro->body.macro.is_conditional) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Add this conditional macro to the beginning of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * global list.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe warning_mksh(gettext("Conditional macro `%s' referenced in file `%ws', line %d"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe name->string_mb, file_being_read, line_number);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Macro name read and parsed. Expand the value. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((macro == NULL) || (macro->body.macro.value == NULL)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If the value is empty, we just get out of here. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If we should do a :sh transform, we expand the command
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and process it.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Expand the value into a local string buffer and run cmd. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value_with_daemon(name, macro, &string, cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else if ((replacement != no_replace) || (extraction != no_extract)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If there were any transforms specified in the macro
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * name, we deal with them here.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Expand the value into a local string buffer. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value_with_daemon(name, macro, &string, cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Scan the expanded string. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (*p != (int) nul_char) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * First skip over any white space and append
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * that to the destination string.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((*p != (int) nul_char) && iswspace(*p)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Then find the end of the next word. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((*p != (int) nul_char) && !iswspace(*p)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If we cant find another word we are done */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Then apply the transforms to the word */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(extracted, extracted_string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * $(@D) type transform. Extract the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * path from the word. Deliver "." if
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * none is found.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe eq = (wchar_t *) wcsrchr(block_start, (int) slash_char);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * $(@F) type transform. Remove the path
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * from the word if any.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe eq = (wchar_t *) wcsrchr(block_start, (int) slash_char);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * $(FOO:.o=.c) type transform.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Maybe replace the tail of the word.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* $(X:a%b=c%d) type transform. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (extracted.text.p - extracted.buffer.start)-left_head_len-left_tail_len);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This is for the case when the macro name did not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * specify transforms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value_with_daemon(name, macro, destination, cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (macro_to_add->prop->body.macro.value != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe value_to_add = macro_to_add->prop->body.macro.value->string_mb;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Check if this macro is already on list, if so, do nothing
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe new_macro = (Macro_list) malloc(sizeof(Macro_list_rec));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * init_arch_macros(void)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Set the magic macros TARGET_ARCH, HOST_ARCH,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * host_arch Property for magic macro HOST_ARCH
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target_arch Property for magic macro TARGET_ARCH
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The function does not return a value, but can
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * call fatal() in case of error.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe set_host = (get_prop(host_arch->prop, macro_prop) == NULL);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe set_target = (get_prop(target_arch->prop, macro_prop) == NULL);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) hyphen_char, &result_string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((pipe = popen(mach_command, "r")) == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_mksh(gettext("Execute of %s failed"), mach_command);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (fgets(mb_buf, sizeof(mb_buf), pipe) != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_string(wcs_buffer, &result_string, wcslen(wcs_buffer));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_mksh(gettext("Execute of %s failed"), mach_command);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe value = GETNAME(result_string.buffer.start, wcslen(result_string.buffer.start));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) setvar_daemon(host_arch, value, false, no_daemon, true, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) setvar_daemon(target_arch, value, false, no_daemon, true, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * init_mach_macros(void)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Set the magic macros TARGET_MACH, HOST_MACH,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * host_mach Property for magic macro HOST_MACH
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target_mach Property for magic macro TARGET_MACH
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The function does not return a value, but can
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * call fatal() in case of error.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe set_host = (get_prop(host_mach->prop, macro_prop) == NULL);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe set_target = (get_prop(target_mach->prop, macro_prop) == NULL);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) hyphen_char, &result_string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((pipe = popen(arch_command, "r")) == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_mksh(gettext("Execute of %s failed"), arch_command);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (fgets(mb_buf, sizeof(mb_buf), pipe) != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_string(wcs_buffer, &result_string, wcslen(wcs_buffer));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_mksh(gettext("Execute of %s failed"), arch_command);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe value = GETNAME(result_string.buffer.start, wcslen(result_string.buffer.start));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) setvar_daemon(host_mach, value, false, no_daemon, true, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) setvar_daemon(target_mach, value, false, no_daemon, true, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * expand_value_with_daemon(name, macro, destination, cmd)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Checks for daemons and then maybe calls expand_value().
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * name Name of the macro (Added by the NSE)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * macro The property block with the value to expand
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * destination Where the result should be deposited
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * cmd If we are evaluating a command line we
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * turn \ quoting off
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweexpand_value_with_daemon(Name, register Property macro, register String destination, Boolean cmd)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(macro->body.macro.value, destination, cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(dollarless_value, destination, cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(macro->body.macro.value, destination, cmd);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If this is a $? value we call the daemon to translate the */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* list of names to a string */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We use a permanent buffer to reset SUNPRO_DEPENDENCIES value.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * setvar_daemon(name, value, append, daemon, strip_trailing_spaces)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Set a macro value, possibly supplying a daemon to be used
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * when referencing the value.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The property block with the new value
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * name Name of the macro to set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * value The value to set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * append Should we reset or append to the current value?
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * daemon Special treatment when reading the value
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * strip_trailing_spaces from the end of value->string
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * debug_level Indicates how much tracing we should do
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * makefile_type Used to check if we should enforce read only
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * path_name The Name "PATH", compared against
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * virtual_root The Name "VIRTUAL_ROOT", compared against
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * vpath_defined Set if the macro VPATH is set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * vpath_name The Name "VPATH", compared against
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * envvar A list of environment vars with $ in value
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesetvar_daemon(register Name name, register Name value, Boolean append, Daemon daemon, Boolean strip_trailing_spaces, short debug_level)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property macro = maybe_append_prop(name, macro_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property macro_apx = get_prop(name->prop, macro_append_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Strip spaces from the end of the value */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((length > 0) && iswspace(val_string[length-1])) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_string(val_string, &destination, length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((length > 0) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe iswspace(destination.buffer.start[length-1])) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe value = GETNAME(destination.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If we are appending, we just tack the new value after
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the old one with a space in between.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe value = GETNAME(destination.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Debugging trace */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Set the new values in the macro property block */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (macro_apx->body.macro_appendix.value_to_append != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (macro_apx->body.macro_appendix.value_to_append != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APPEND_NAME(macro_apx->body.macro_appendix.value_to_append,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int) macro_apx->body.macro_appendix.value_to_append->hash.length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe value = GETNAME(destination.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If the user changes the VIRTUAL_ROOT, we need to flush
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the vroot package cache.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If this sets the VPATH we remember that */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For environment variables we also set the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * environment value each time.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } if (reading_environment || (value == NULL) || !value->dollar) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Property env_prop = maybe_append_prop(name, env_mem_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We use a permanent buffer to reset SUNPRO_DEPENDENCIES value.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!strncmp(name->string_mb, "SUNPRO_DEPENDENCIES", 19)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sunpro_dependencies_buf_size = 4096; // Default minimum size
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sunpro_dependencies_oldbuf = sunpro_dependencies_buf;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sunpro_dependencies_buf=getmem(sunpro_dependencies_buf_size);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Return old buffer */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe old_vr = (wchar_t *) wcschr(old_vr, (int) colon_char) + 1;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) swprintf(new_value, length * SIZEOFWCHAR_T,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe L"/usr/arch/%s/%s:%s",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (new_value[0] != 0) {