From owner-freebsd-arch@FreeBSD.ORG Tue Sep 16 23:51:29 2003 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 515A916A4B3 for ; Tue, 16 Sep 2003 23:51:29 -0700 (PDT) Received: from ns1.xcllnt.net (209-128-86-226.BAYAREA.NET [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id D5CE643FBD for ; Tue, 16 Sep 2003 23:51:27 -0700 (PDT) (envelope-from marcel@xcllnt.net) Received: from athlon.pn.xcllnt.net (athlon.pn.xcllnt.net [192.168.4.3]) by ns1.xcllnt.net (8.12.9/8.12.9) with ESMTP id h8H6pRjR004527 for ; Tue, 16 Sep 2003 23:51:27 -0700 (PDT) (envelope-from marcel@piii.pn.xcllnt.net) Received: from athlon.pn.xcllnt.net (localhost [127.0.0.1]) by athlon.pn.xcllnt.net (8.12.9/8.12.9) with ESMTP id h8H6pRFd004385 for ; Tue, 16 Sep 2003 23:51:27 -0700 (PDT) (envelope-from marcel@athlon.pn.xcllnt.net) Received: (from marcel@localhost) by athlon.pn.xcllnt.net (8.12.9/8.12.9/Submit) id h8H6pRY3004384 for arch@FreeBSD.org; Tue, 16 Sep 2003 23:51:27 -0700 (PDT) (envelope-from marcel) Date: Tue, 16 Sep 2003 23:51:27 -0700 From: Marcel Moolenaar To: arch@FreeBSD.org Message-ID: <20030917065127.GB4261@athlon.pn.xcllnt.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="HcAYCG3uE/tztfnV" Content-Disposition: inline User-Agent: Mutt/1.5.4i Subject: make(1): adding sort modifiers X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Sep 2003 06:51:29 -0000 --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Gang, Attached a patch that adds the functionality to make(1) to sort the words in a variable. With this functionality and a small change to bsd.subdir.mk (also attached), we automaticly have sorted subdirectory recursion, even though it's impossible or hard to do it in the makesfiles themselves. Is this too evil? -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="make.diff" Index: var.c =================================================================== RCS file: /home/ncvs/src/usr.bin/make/var.c,v retrieving revision 1.42 diff -u -r1.42 var.c --- var.c 15 Jan 2003 22:36:15 -0000 1.42 +++ var.c 17 Sep 2003 06:30:11 -0000 @@ -606,7 +606,38 @@ return (str); } +static char * +VarSortWords(char *str, int (*cmp)(const void *, const void *)) +{ + Buffer buf; + char **av; + int ac, i; + + buf = Buf_Init(0); + av = brk_string(str, &ac, FALSE); + qsort((void*)(av + 1), ac - 1, sizeof(char*), cmp); + for (i = 1; i < ac; i++) { + Buf_AddBytes(buf, strlen(av[i]), (Byte *)av[i]); + Buf_AddByte(buf, (Byte)((i < ac - 1) ? ' ' : '\0')); + } + str = (char *)Buf_GetAll(buf, (int *)NULL); + Buf_Destroy(buf, FALSE); + return (str); +} + +static int +SortIncreasing(const void *l, const void *r) +{ + return (strcmp(*(char**)l, *(char**)r)); +} + +static int +SortDecreasing(const void *l, const void *r) +{ + return (-strcmp(*(char**)l, *(char**)r)); +} + /*- *----------------------------------------------------------------------- * VarGetPattern -- @@ -1448,6 +1479,22 @@ free(pattern.matches); break; } + case '<': + if (tstr[1] == endc || tstr[1] == ':') { + newStr = VarSortWords(str, SortIncreasing); + cp = tstr + 1; + termc = *cp; + break; + } + /* FALLTHROUGH */ + case '>': + if (tstr[1] == endc || tstr[1] == ':') { + newStr = VarSortWords(str, SortDecreasing); + cp = tstr + 1; + termc = *cp; + break; + } + /* FALLTHROUGH */ case 'Q': if (tstr[1] == endc || tstr[1] == ':') { newStr = VarQuote (str); --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="subdir.diff" Index: bsd.subdir.mk =================================================================== RCS file: /home/ncvs/src/share/mk/bsd.subdir.mk,v retrieving revision 1.44 diff -u -r1.44 bsd.subdir.mk --- bsd.subdir.mk 12 Jul 2002 15:09:35 -0000 1.44 +++ bsd.subdir.mk 17 Sep 2003 06:46:57 -0000 @@ -42,7 +42,7 @@ _SUBDIR: .USE .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR) - @for entry in ${SUBDIR}; do \ + @for entry in ${SUBDIR:<}; do \ if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \ ${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH}"; \ edir=$${entry}.${MACHINE_ARCH}; \ --HcAYCG3uE/tztfnV--