$(NAME) / ${NAME} / $(shell pwd) / $(abspath X): its expansion. */
| 2968 | |
| 2969 | /* $(NAME) / ${NAME} / $(shell pwd) / $(abspath X): its expansion. */ |
| 2970 | static const char *mk_reference(mk_t *m, const char *ref) { |
| 2971 | static const char *const pwd[] = {"pwd", NULL}; |
| 2972 | static const char *const pwd_p[] = {"pwd", "-P", NULL}; |
| 2973 | static const char *const toplevel[] = {"git", "rev-parse", "--show-toplevel", NULL}; |
| 2974 | size_t rl = strcspn(ref, " \t"); |
| 2975 | if (!ref[rl]) { |
| 2976 | return mk_lookup(m, ref); |
| 2977 | } |
| 2978 | const char *fn = cbm_arena_strndup(m->a, ref, rl); |
| 2979 | const char *arg = mk_trim(m->a, ref + rl, strlen(ref + rl)); |
| 2980 | if (!fn || !arg) { |
| 2981 | return MK_UNKNOWN; |
| 2982 | } |
| 2983 | if (strcmp(fn, "shell") == 0) { |
| 2984 | const char *cmd = mk_expand(m, arg); |
| 2985 | if (cmd && (mk_words(cmd, pwd) || mk_words(cmd, pwd_p))) { |
| 2986 | return m->makefile ? "${__cbm_curdir}" : MK_UNKNOWN; |
| 2987 | } |
| 2988 | if (cmd && mk_words(cmd, toplevel)) { |
| 2989 | return "${__cbm_root}"; |
| 2990 | } |
| 2991 | return MK_UNKNOWN; |
| 2992 | } |
| 2993 | if (strcmp(fn, "abspath") == 0 || strcmp(fn, "realpath") == 0) { |
| 2994 | const char *v = mk_expand(m, arg); |
| 2995 | return v && !strchr(v, ' ') ? v : MK_UNKNOWN; |
| 2996 | } |
| 2997 | return MK_UNKNOWN; |
| 2998 | } |
| 2999 | |
| 3000 | /* Make's expansion of `text`: references replaced, $$ -> $, what is not |
| 3001 | * known -> a shell variable no line sets. */ |