Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper pattern rules (a'la GNU make) #2

Open
1 of 3 tasks
xparq opened this issue Oct 25, 2023 · 1 comment
Open
1 of 3 tasks

Proper pattern rules (a'la GNU make) #2

xparq opened this issue Oct 25, 2023 · 1 comment

Comments

@xparq
Copy link
Owner

xparq commented Oct 25, 2023

  • First, just add inf. rules with paths (and introduce the approximate syntax, with the usual % as a placeholder, for (always) the target's name). -> Path-aware inference rules #1
  • Next, get the GNU syntax (target%pattern : src%pattern) accepted & recognized as inf. rule
  • And then make it actually work, too...
@xparq xparq mentioned this issue Oct 25, 2023
12 tasks
@xparq
Copy link
Owner Author

xparq commented Oct 29, 2023

It would be very likely useful to generalize this part out of the static modify_words in input.c (maybe straight to utils.c?):

if (find_pref) {
	// get length of find prefix, e.g: src/
	find_pref_len = strlen(find_pref);
	// get length of find suffix, e.g: .c
	find_suff_len = lenf - find_pref_len - 1;
}

s = copy = xstrdup(val);
while ((word = gettok(&s)) != NULL) {
	newword = NULL;
	if (IF_FEATURE_MAKE_POSIX_202X(find_pref != NULL ||)
			lenf != 0 || lenr != 0) {
		size_t lenw = strlen(word);
#if ENABLE_FEATURE_MAKE_POSIX_202X
		// This code implements pattern macro expansions:
		//    https://austingroupbugs.net/view.php?id=519
		//
		// find: <prefix>%<suffix>
		// example: src/%.c
		//
		// For a pattern of the form:
		//    $(string1:[op]%[os]=[np][%][ns])
		// lenf is the length of [op]%[os].  So lenf >= 1.
		if (find_pref != NULL && lenw + 1 >= lenf) {
			// If prefix and suffix of word match find_pref and
			// find_suff, then do substitution.
			if (strncmp(word, find_pref, find_pref_len) == 0 &&
					strcmp(word + lenw - find_suff_len, find_suff) == 0) {
				// replace: <prefix>[%<suffix>]
				// example: build/%.o or build/all.o (notice no %)
				// If repl_suff is NULL, replace whole word with repl_pref.
				if (!repl_suff) {
					word = newword = xstrdup(repl_pref);
				} else {
					word[lenw - find_suff_len] = '\0';
					word = newword = xconcat3(repl_pref,
								word + find_pref_len, repl_suff);
				}
			}
		} else
#endif
		if (lenw >= lenf && strcmp(word + lenw - lenf, find_suff) == 0) {
			word[lenw - lenf] = '\0';
			word = newword = xconcat3(word, repl_suff, "");
		}
	}

@xparq xparq pinned this issue Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant