From 5fd18a2986fb63d78b53f20ea07c4e9170ca4b6f Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Tue, 15 Dec 2020 15:16:56 +0100 Subject: [PATCH 1/9] start adding this_file,n this_line, this_counter functions --- src/function.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/function.c b/src/function.c index 6a578ada4..6e554decb 100644 --- a/src/function.c +++ b/src/function.c @@ -1370,6 +1370,50 @@ 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, char **argv, const char *funcname UNUSED) +{ + fprintf(stderr, "@func_this_file (%s:%d)\n", __FILE__, __LINE__); + return o; +} + + +/** + $(this_line) + + Always expands to the current line number. Inspired by the __LINE__macro of C. +**/ + +static char * +func_this_line (char *o, char **argv, const char *funcname UNUSED) +{ + return o; +} + + +/** + $(this_counter) + + Always expands to a unique, incremented, counter. Inspired by the __COUNT__macro of GCC. +**/ + +static char * +func_this_counter (char *o, char **argv, const char *funcname UNUSED) +{ + return o; +} +///// end of functions added by + + /* \r is replaced on UNIX as well. Is this desirable? */ @@ -2210,6 +2254,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 +2284,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) From 0cab240f1848d6bf46bde8b59352a5c91b48687f Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Tue, 15 Dec 2020 15:36:55 +0100 Subject: [PATCH 2/9] more code, untested, in func_this_file, func_this_line, func_this_counter --- src/function.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/function.c b/src/function.c index 6e554decb..719d3ef3b 100644 --- a/src/function.c +++ b/src/function.c @@ -1383,6 +1383,13 @@ static char * func_this_file (char *o, char **argv, const char *funcname UNUSED) { fprintf(stderr, "@func_this_file (%s:%d)\n", __FILE__, __LINE__); + if (reading_file) + { + const char*curfil = reading_file->filenm; + if (curfil && curfil[0]) { +#warning should func_this_file return curfil or strdup(curfil) here? + } + } return o; } @@ -1396,6 +1403,16 @@ func_this_file (char *o, char **argv, const char *funcname UNUSED) static char * func_this_line (char *o, char **argv, const char *funcname UNUSED) { + if (reading_file) + { + unsigned long curlineno = reading_file->lineno; + if (curlineno) { + char linenobuf[32]; + memset(linenobuf, 0, sizeof(linenobuf)); + snprintf(linenobuf, sizeof(linenobuf), "%lu", curlineno); +#warning should func_this_line return strdup(linenobuf) here? + } + } return o; } @@ -1409,6 +1426,12 @@ func_this_line (char *o, char **argv, const char *funcname UNUSED) static char * func_this_counter (char *o, char **argv, const char *funcname UNUSED) { + static unsigned long curcounter; + curcounter++; + char curcountbuf[32]; + memset (curcountbuf, 0, sizeof(curcountbuf)); + snprintf (curcountbuf, sizeof(curcountbuf), "%lu", curcounter); +#warning should func_this_counter return strdup(curcountbuf) here? return o; } ///// end of functions added by From 4f3c4d2708ea80e67a36be94549093d94fdf9952 Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Tue, 15 Dec 2020 15:44:29 +0100 Subject: [PATCH 3/9] coded more in func_this_file, func_this_line , func_this_counter --- src/function.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/function.c b/src/function.c index 719d3ef3b..acbfed3bf 100644 --- a/src/function.c +++ b/src/function.c @@ -1380,14 +1380,14 @@ func_value (char *o, char **argv, const char *funcname UNUSED) **/ static char * -func_this_file (char *o, char **argv, const char *funcname UNUSED) +func_this_file (char *o, char **argv UNUSED, const char *funcname UNUSED) { fprintf(stderr, "@func_this_file (%s:%d)\n", __FILE__, __LINE__); if (reading_file) { const char*curfil = reading_file->filenm; if (curfil && curfil[0]) { -#warning should func_this_file return curfil or strdup(curfil) here? + return strdup(curfil); } } return o; @@ -1401,8 +1401,9 @@ func_this_file (char *o, char **argv, const char *funcname UNUSED) **/ static char * -func_this_line (char *o, char **argv, const char *funcname UNUSED) +func_this_line (char *o, char **argv UNUSED, const char *funcname UNUSED) { + fprintf(stderr, "@func_this_line (%s:%d)\n", __FILE__, __LINE__); if (reading_file) { unsigned long curlineno = reading_file->lineno; @@ -1410,7 +1411,7 @@ func_this_line (char *o, char **argv, const char *funcname UNUSED) char linenobuf[32]; memset(linenobuf, 0, sizeof(linenobuf)); snprintf(linenobuf, sizeof(linenobuf), "%lu", curlineno); -#warning should func_this_line return strdup(linenobuf) here? + return strdup(linenobuf); } } return o; @@ -1424,15 +1425,15 @@ func_this_line (char *o, char **argv, const char *funcname UNUSED) **/ static char * -func_this_counter (char *o, char **argv, const char *funcname UNUSED) +func_this_counter (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) { static unsigned long curcounter; - curcounter++; char curcountbuf[32]; + fprintf(stderr, "@func_this_counter (%s:%d)\n", __FILE__, __LINE__); memset (curcountbuf, 0, sizeof(curcountbuf)); + curcounter++; snprintf (curcountbuf, sizeof(curcountbuf), "%lu", curcounter); -#warning should func_this_counter return strdup(curcountbuf) here? - return o; + return strdup(curcountbuf); } ///// end of functions added by From 38438dd3c7b9cc90acbb784054dc2b64f8b48b3c Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Fri, 8 Jan 2021 11:30:47 +0100 Subject: [PATCH 4/9] coded func_this_counter for $(this_counter) inspired by GCC __COUNTER__ --- src/function.c | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/src/function.c b/src/function.c index acbfed3bf..a219c628e 100644 --- a/src/function.c +++ b/src/function.c @@ -1376,20 +1376,13 @@ func_value (char *o, char **argv, const char *funcname UNUSED) /** $(this_file) - Always expands to the current Makefile path. Inspired by the __FILE__macro of C. + Always expands to the current Makefile path. Inspired by the __FILE__ macro of C. **/ static char * -func_this_file (char *o, char **argv UNUSED, const char *funcname UNUSED) +func_this_file (char *o, char **argv, const char *funcname UNUSED) { fprintf(stderr, "@func_this_file (%s:%d)\n", __FILE__, __LINE__); - if (reading_file) - { - const char*curfil = reading_file->filenm; - if (curfil && curfil[0]) { - return strdup(curfil); - } - } return o; } @@ -1397,23 +1390,12 @@ func_this_file (char *o, char **argv UNUSED, const char *funcname UNUSED) /** $(this_line) - Always expands to the current line number. Inspired by the __LINE__macro of C. + Always expands to the current line number. Inspired by the __LINE__ macro of C. **/ static char * -func_this_line (char *o, char **argv UNUSED, const char *funcname UNUSED) +func_this_line (char *o, char **argv, const char *funcname UNUSED) { - fprintf(stderr, "@func_this_line (%s:%d)\n", __FILE__, __LINE__); - if (reading_file) - { - unsigned long curlineno = reading_file->lineno; - if (curlineno) { - char linenobuf[32]; - memset(linenobuf, 0, sizeof(linenobuf)); - snprintf(linenobuf, sizeof(linenobuf), "%lu", curlineno); - return strdup(linenobuf); - } - } return o; } @@ -1421,19 +1403,18 @@ func_this_line (char *o, char **argv UNUSED, const char *funcname UNUSED) /** $(this_counter) - Always expands to a unique, incremented, counter. Inspired by the __COUNT__macro of GCC. + 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 unsigned long curcounter; - char curcountbuf[32]; - fprintf(stderr, "@func_this_counter (%s:%d)\n", __FILE__, __LINE__); - memset (curcountbuf, 0, sizeof(curcountbuf)); - curcounter++; - snprintf (curcountbuf, sizeof(curcountbuf), "%lu", curcounter); - return strdup(curcountbuf); + 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 From 1284d31a87dc6755836a69670d7e9207b90694cd Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Fri, 8 Jan 2021 14:49:53 +0100 Subject: [PATCH 5/9] implemented $(this_line) and $(this_file) textual functions --- src/function.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/function.c b/src/function.c index a219c628e..f14e8e8fb 100644 --- a/src/function.c +++ b/src/function.c @@ -1380,10 +1380,13 @@ func_value (char *o, char **argv, const char *funcname UNUSED) **/ static char * -func_this_file (char *o, char **argv, const char *funcname UNUSED) +func_this_file (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) { - fprintf(stderr, "@func_this_file (%s:%d)\n", __FILE__, __LINE__); - return o; + if (reading_file) { + return xstrdup(reading_file->filenm); + } + else + return xstrdup("?"); } @@ -1394,9 +1397,16 @@ func_this_file (char *o, char **argv, const char *funcname UNUSED) **/ static char * -func_this_line (char *o, char **argv, const char *funcname UNUSED) +func_this_line (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) { - return o; + 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"); } From 9d6be5e3fd7755129ceb7cc0bb66920dc36c7481 Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Fri, 8 Jan 2021 14:50:47 +0100 Subject: [PATCH 6/9] bad documentation for new functions this_line, this_file, this_counter --- doc/make.texi | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/make.texi b/doc/make.texi index 733c0b962..e2a78cab6 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -7626,9 +7626,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 From e7e147cb658ff3d6e261cac2fc1ec74202b12ea3 Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Fri, 8 Jan 2021 16:03:44 +0100 Subject: [PATCH 7/9] the GNUremakefile is used if existing --- src/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From 6932b33fcb09698b8bf79db149ec0ef904a2f932 Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Tue, 12 Jan 2021 11:04:42 +0100 Subject: [PATCH 8/9] doc/make.pdf seems good and document properly this_line, this_file, this_counter --- doc/make.texi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/make.texi b/doc/make.texi index e2a78cab6..4aa42876d 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. From 4bcaf92e69e6fafa09ba249ce28e869661fca6a5 Mon Sep 17 00:00:00 2001 From: Basile Starynkevitch Date: Tue, 12 Jan 2021 11:07:47 +0100 Subject: [PATCH 9/9] mention GNUremakefile --- doc/make.texi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/make.texi b/doc/make.texi index 4aa42876d..55af61eb7 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -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