bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

$(sort) - what is "lexical order"? (was RE: Follow-up)


From: Martin Dorey
Subject: $(sort) - what is "lexical order"? (was RE: Follow-up)
Date: Tue, 12 Jul 2011 14:17:06 -0700

OP has something of a point: contrast the locale-dependent behavior of sort(1) with make's $(sort):

 

$ echo 'L:=$(sort B a)' | make -f - -p 2>&1 | grep '^L '

L := B a

$ { echo B; echo a; } | sort

a

B

$ { echo B; echo a; } | LC_ALL=C sort

B

a

$

 

I present this more to provoke "we can't change that!" and clarified documentation than as a serious suggestion:

 

Index: configure.in

===================================================================

RCS file: /sources/make/make/configure.in,v

retrieving revision 1.157

diff -u -r1.157 configure.in

--- configure.in    29 Aug 2010 23:05:27 -0000       1.157

+++ configure.in 12 Jul 2011 21:11:28 -0000

@@ -166,6 +167,7 @@

 AC_CHECK_FUNCS(strcasecmp strncasecmp strcmpi strncmpi stricmp strnicmp)

 

 # strcoll() is used by the GNU glob library

+# and by $(sort)

 AC_FUNC_STRCOLL

 

 AC_FUNC_ALLOCA

Index: misc.c

===================================================================

RCS file: /sources/make/make/misc.c,v

retrieving revision 1.84

diff -u -r1.84 misc.c

--- misc.c          6 Nov 2010 21:56:24 -0000          1.84

+++ misc.c       12 Jul 2011 21:11:28 -0000

@@ -51,6 +51,10 @@

 # define VA_END(args)

 #endif

 

+#if !defined(HAVE_STRCOLL)

+# define strcoll strcmp

+#endif

+

 

 /* Compare strings *S1 and *S2.

    Return negative if the first is less, positive if it is greater,

@@ -62,9 +66,7 @@

   const char *s1 = *((char **)v1);

   const char *s2 = *((char **)v2);

 

-  if (*s1 != *s2)

-    return *s1 - *s2;

-  return strcmp (s1, s2);

+  return strcoll (s1, s2);

 }

 

 /* Discard each backslash-newline combination from LINE.

cvs diff: Diffing config

cvs diff: Diffing doc

Index: doc/make.texi

===================================================================

RCS file: /sources/make/make/doc/make.texi,v

retrieving revision 1.72

diff -u -r1.72 make.texi

--- doc/make.texi            2 May 2011 15:11:23 -0000         1.72

+++ doc/make.texi         12 Jul 2011 21:11:28 -0000

@@ -6846,6 +6846,8 @@

 

 @noindent

 returns the value @samp{bar foo lose}.

+In a change from previous versions, make now sorts in locale-dependent order.

+Run with LC_ALL=C in the environment to select the previous behavior.

 

 @cindex removing duplicate words

 @cindex duplicate words, removing

 


From: address@hidden [mailto:address@hidden On Behalf Of Rob Holbert
Sent: Monday, July 11, 2011 12:24
To: address@hidden
Subject: Follow-up

 

Wanted to followup to my earlier email. Attached is the smallest makefile I could create to demonsterate the issue.

 

or

 

#does not sort lexically like expected
LIST = $(sort widget.c main.c ad.c Buzzer.c)

#target
all: list

list:
    @echo $(LIST)

.PHONY: all list

 

Previous email:

Hello,

 

I ran across perhaps a bug or need for another feature at least. If a list of items has words beginning with both upper and lower case letters, the resulting $(sort $(LIST)) will result in all capital letter words coming before the lower case words. In this case, Zebra.c would appear before apple.c. This is dictated by the ASCII chart of course. However, it is not lexical order as the manual explains the function is. Lexical would be apple.c Zebra.c.

 

This is solved easily by making the sort comparison convert all alphas to lower case before comparing, leaving the original string case unchanged. 

 

I like to use sort to put my sources in order. This way it is easier to see if an object file is missing for instance.

 

Best Regards,

Rob


reply via email to

[Prev in Thread] Current Thread [Next in Thread]