Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU make wildcard no longer gives sorted output. Is there any control switch?

The wildcard function returns sorted results in version 3.81, but it does do that in version 4.2. Is there any compile/runtime switch to control this fucntion?

Below shows the results from two version of GNU make.

$ ls
a.mk  a0.svp  a1.svp  a2.svp  a3.svp  a4.svp  a5.svp  a6.svp  a7.svp  a8.svp  a9.svp

$ cat a.mk 
SVP_FILES := $(wildcard *.svp)

all:
        @echo $(SVP_FILES)

$ make  -f a.mk all          
a0.svp a1.svp **a2.svp a3.svp a4.svp a5.svp a6.svp a7.svp a8.svp a9.svp**

$ ~/sandbox/bin/make  -f a.mk all          
a0.svp a1.svp **a6.svp a5.svp a9.svp a4.svp a3.svp a2.svp a7.svp a8.svp**

$make –v | head -n 1

GNU Make 3.81

$ ~/sandbox/bin/make -v | head -n 1

GNU Make 4.2
like image 570
kko Avatar asked Nov 12 '16 00:11

kko


People also ask

What are the wildcard characters in make in Linux?

The wildcard characters in make are ‘*’, ‘?’ and ‘[…]’, the same as in the Bourne shell. For example, *.c specifies a list of all the files (in the working directory) whose names end in ‘.c’. The character ‘~’ at the beginning of a file name also has special significance.

How do I use the wildcard function in C?

One use of the wildcard function is to get a list of all the C source files in a directory, like this: We can change the list of C source files into a list of object files by replacing the ‘ .c ’ suffix with ‘ .o ’ in the result, like this: (Here we have used another function, patsubst .

How to turn off the special significance of a wildcard character?

The special significance of a wildcard character can be turned off by preceding it with a backslash. Thus, foo*bar would refer to a specific file whose name consists of ‘ foo ’, an asterisk, and ‘ bar ’.

What is $wildcard pattern in makefile?

$ (wildcard pattern …) This string, used anywhere in a makefile, is replaced by a space-separated list of names of existing files that match one of the given file name patterns. If no existing file name matches a pattern, then that pattern is omitted from the output of the wildcard function.


2 Answers

GNU make 4.3 has sorted globs again.

In https://savannah.gnu.org/bugs/index.php?52076

It turned out, that nobody knew why the sorting was dropped.

like image 26
Bernhard M. Avatar answered Oct 18 '22 19:10

Bernhard M.


As mentioned in the NEWS file

Version 3.82 (28 Jul 2010)

[...]

  • WARNING: Backward-incompatibility! Wildcards were not documented as returning sorted values, but the results have been sorted up until this release.. If your makefiles require sorted results from wildcard expansions, use the $(sort ...) function to request it explicitly.

I.e. SVP_FILES := $(sort $(wildcard *.svp))

like image 165
user657267 Avatar answered Oct 18 '22 18:10

user657267