diff --git a/doc/make.texi b/doc/make.texi index 733c0b962..55af61eb7 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -5,7 +5,7 @@ @include version.texi @set EDITION 0.75 -@settitle GNU @code{make} +@settitle GNU @code{[re]make} @setchapternewpage odd @c Combine the variable and function indices: @syncodeindex vr fn @@ -17,7 +17,7 @@ @c %**end of header @copying -This file documents the GNU @code{make} utility, which determines +This file documents the GNU @code{[re]make} utility, which determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them. @@ -1154,9 +1154,10 @@ var := oneword @c following paragraph rewritten to avoid overfull hbox By default, when @code{make} looks for the makefile, it tries the -following names, in order: @file{GNUmakefile}, @file{makefile} +following names, in order: @file{GNUremakefile}, @file{GNUmakefile}, @file{makefile} and @file{Makefile}.@refill @findex Makefile +@findex GNUremakefile @findex GNUmakefile @findex makefile @@ -7626,9 +7627,33 @@ separators (@code{/}). Note that, in contrast to @code{realpath} function, @code{abspath} does not resolve symlinks and does not require the file names to refer to an existing file or directory. Use the @code{wildcard} function to test for existence. + +@item $(this_line) +@findex this_line +@cindex this_line, function +The invocation @code{$(this_line)} expands to the current line +number. It is inspired by the @code{__LINE__} magical macro of the C +programming language. + + +@item $(this_file) +@findex this_file +@cindex this_file, function +The invocation @code{$(this_file)} expands to the current filename, +e.g. to @code{Makefile}. It is inspired by the @code{__FILE__} +magical macro of the C programming language. + + +@item $(this_counter) +@findex this_counter +@cindex this_counter, function +The invocation @code{$(this_counter)} expands to a unique, incremented, +counter (in decimal). It is inspired by the @code{__COUNTER__} magical +macro of the C programming language understood by GCC. + @end table -@node Conditional Functions, Foreach Function, File Name Functions, Functions + @section Functions for Conditionals @findex if @cindex conditional expansion diff --git a/src/function.c b/src/function.c index 6a578ada4..f14e8e8fb 100644 --- a/src/function.c +++ b/src/function.c @@ -1370,6 +1370,65 @@ func_value (char *o, char **argv, const char *funcname UNUSED) return o; } +///// added by + + +/** + $(this_file) + + Always expands to the current Makefile path. Inspired by the __FILE__ macro of C. +**/ + +static char * +func_this_file (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) +{ + if (reading_file) { + return xstrdup(reading_file->filenm); + } + else + return xstrdup("?"); +} + + +/** + $(this_line) + + Always expands to the current line number. Inspired by the __LINE__ macro of C. +**/ + +static char * +func_this_line (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) +{ + if (reading_file) { + char linumbuf[32]; + memset (linumbuf, 0, sizeof(linumbuf)); + snprintf(linumbuf, sizeof(linumbuf), "%lu", reading_file->lineno); + return xstrdup(linumbuf); + } + else + return xstrdup("0"); +} + + +/** + $(this_counter) + + Always expands to a unique, incremented, counter. Inspired by the __COUNTER__ macro of GCC. +**/ + +static char * +func_this_counter (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) +{ + static long counter; + char cntbuf[32]; + memset (cntbuf, 0, sizeof(cntbuf)); + counter++; + snprintf (cntbuf, sizeof(cntbuf), "%ld", counter); + return xstrdup(cntbuf); +} +///// end of functions added by + + /* \r is replaced on UNIX as well. Is this desirable? */ @@ -2210,6 +2269,10 @@ static struct function_table_entry function_table_init[] = FT_ENTRY ("eval", 0, 1, 1, func_eval), FT_ENTRY ("file", 1, 2, 1, func_file), FT_ENTRY ("debugger", 0, 1, 1, func_debugger), + /// three functions added by + FT_ENTRY ("this_file", 0, 0, 0, func_this_file), + FT_ENTRY ("this_line", 0, 0, 0, func_this_line), + FT_ENTRY ("this_counter", 0, 0, 0, func_this_counter), #ifdef EXPERIMENTAL FT_ENTRY ("eq", 2, 2, 1, func_eq), FT_ENTRY ("not", 0, 1, 1, func_not), @@ -2236,7 +2299,10 @@ expand_builtin_function (char *o, int argc, char **argv, but so far no internal ones do, so just test it for all functions here rather than in each one. We can change it later if necessary. */ - if (!argc && !entry_p->alloc_fn) + if (!argc + /// the functions named this_* by take no arguments... + && strncmp(entry_p->name, "this", sizeof("this")-1) + && !entry_p->alloc_fn) return o; if (!entry_p->fptr.func_ptr) diff --git a/src/read.c b/src/read.c index df5a2c645..5db5a3a9d 100644 --- a/src/read.c +++ b/src/read.c @@ -228,7 +228,7 @@ read_all_makefiles (const char **makefiles) { PATH_VAR (current_directory); static const char *default_makefiles[] = - { "GNUmakefile", "makefile", "Makefile", 0 }; + { "GNUremakefile", "GNUmakefile", "makefile", "Makefile", 0 }; const char **p; while (1) {