Date: Wed, 14 Apr 2010 22:56:13 +0300 From: Alex RAY <ray@ddteam.net> To: "M. Warner Losh" <imp@bsdimp.com> Cc: ray@dlink.ua, hackers@FreeBSD.org, embedded@FreeBSD.org Subject: Re: Patch for config utility Message-ID: <20100414225613.99ceff5d.ray@ddteam.net> In-Reply-To: <20100414.094536.918765004165097153.imp@bsdimp.com> References: <20100414130353.c28d5128.ray@dlink.ua> <20100414.094536.918765004165097153.imp@bsdimp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Thanks for On Wed, 14 Apr 2010 09:45:36 -0600 (MDT) "M. Warner Losh" <imp@bsdimp.com> wrote: > Quick comment: Why not set srcdir instead of inventing ksrcdir? I've tried to use a variable srcdir, but found several points where need to change relative to absolute paths. Because I tried to minimize the impact on the behavior of utilities and tried to make the code of changes easier to read, then decided to make a separate variable. > > Warner > > In message: <20100414130353.c28d5128.ray@dlink.ua> > Alexandr Rybalko <ray@dlink.ua> writes: > : Hi All, > : > : I made a patch for the config utility, which enables execution of config outside of the kernel source tree. > : The main purpose is to avoid large number of configuration files for many boards. > : I work on D-Link DIR-320 device (Broadcom BCM5354) which must have more than 4 different profiles with different kernel > : config files. > : If every device have 3-5 configs (with different hints files), every chip have ~ 5-10 vendors (producing devices on this chip), > : every chip family have 10-20 chips (BCM5354 is a BCM4700 family), and platform have 10-20 family's, so we get 40000 files in conf > : directory of platform :) > : > : > : Index: mkoptions.c > : =================================================================== > : --- mkoptions.c (revision 206411) > : +++ mkoptions.c (working copy) > : @@ -294,7 +294,11 @@ read_options(void) > : char genopt[MAXPATHLEN]; > : > : SLIST_INIT(&otab); > : - (void) snprintf(fname, sizeof(fname), "../../conf/options"); > : + if ( *ksrcdir != '\0' ) > : + (void) snprintf(fname, sizeof(fname), "%s/conf/options", > : + ksrcdir); > : + else > : + (void) snprintf(fname, sizeof(fname), "../../conf/options"); > : openit: > : fp = fopen(fname, "r"); > : if (fp == 0) { > : @@ -306,7 +310,12 @@ next: > : (void) fclose(fp); > : if (first == 1) { > : first++; > : - (void) snprintf(fname, sizeof fname, "../../conf/options.%s", machinename); > : + if ( *ksrcdir != '\0' ) > : + (void) snprintf(fname, sizeof fname, > : + "%s/conf/options.%s", ksrcdir, machinename); > : + else > : + (void) snprintf(fname, sizeof fname, > : + "../../conf/options.%s", machinename); > : fp = fopen(fname, "r"); > : if (fp != 0) > : goto next; > : Index: main.c > : =================================================================== > : --- main.c (revision 206411) > : +++ main.c (working copy) > : @@ -72,6 +72,7 @@ static const char rcsid[] = > : > : char * PREFIX; > : char destdir[MAXPATHLEN]; > : +char ksrcdir[MAXPATHLEN]; > : char srcdir[MAXPATHLEN]; > : > : int debugging; > : @@ -110,8 +111,9 @@ main(int argc, char **argv) > : char xxx[MAXPATHLEN]; > : char *kernfile; > : > : + *ksrcdir = '\0'; > : kernfile = NULL; > : - while ((ch = getopt(argc, argv, "Cd:gpVx:")) != -1) > : + while ((ch = getopt(argc, argv, "Cd:gk:pVx:")) != -1) > : switch (ch) { > : case 'C': > : filebased = 1; > : @@ -125,6 +127,12 @@ main(int argc, char **argv) > : case 'g': > : debugging++; > : break; > : + case 'k': > : + if (*ksrcdir == '\0') > : + strlcpy(ksrcdir, optarg, sizeof(ksrcdir)); > : + else > : + errx(EXIT_FAILURE, "Kernel ksrcdir already set"); > : + break; > : case 'p': > : profiling++; > : break; > : @@ -164,7 +172,8 @@ main(int argc, char **argv) > : len = strlen(destdir); > : while (len > 1 && destdir[len - 1] == '/') > : destdir[--len] = '\0'; > : - get_srcdir(); > : + if (*ksrcdir == '\0') > : + get_srcdir(); > : } else { > : strlcpy(destdir, CDIR, sizeof(destdir)); > : strlcat(destdir, PREFIX, sizeof(destdir)); > : @@ -210,11 +219,14 @@ main(int argc, char **argv) > : * for "sys" (to make genassym.c work along with #include <sys/xxx>) > : * and similarly for "machine". > : */ > : - if (*srcdir == '\0') > : - (void)snprintf(xxx, sizeof(xxx), "../../include"); > : - else > : + if (*ksrcdir != '\0') > : (void)snprintf(xxx, sizeof(xxx), "%s/%s/include", > : + ksrcdir, machinename); > : + else if (*srcdir != '\0') > : + (void)snprintf(xxx, sizeof(xxx), "%s/%s/include", > : srcdir, machinename); > : + else > : + (void)snprintf(xxx, sizeof(xxx), "../../include"); > : (void) unlink(path("machine")); > : (void) symlink(xxx, path("machine")); > : if (strcmp(machinename, machinearch) != 0) { > : @@ -222,12 +234,15 @@ main(int argc, char **argv) > : * make symbolic links in compilation directory for > : * machinearch, if it is different than machinename. > : */ > : - if (*srcdir == '\0') > : + if (*ksrcdir != '\0') > : + (void)snprintf(xxx, sizeof(xxx), "%s/%s/include", > : + ksrcdir, machinearch); > : + else if (*srcdir != '\0') > : + (void)snprintf(xxx, sizeof(xxx), "%s/%s/include", > : + srcdir, machinearch); > : + else > : (void)snprintf(xxx, sizeof(xxx), "../../../%s/include", > : machinearch); > : - else > : - (void)snprintf(xxx, sizeof(xxx), "%s/%s/include", > : - srcdir, machinearch); > : (void) unlink(path(machinearch)); > : (void) symlink(xxx, path(machinearch)); > : } > : @@ -278,7 +293,7 @@ static void > : usage(void) > : { > : > : - fprintf(stderr, "usage: config [-CgpV] [-d destdir] sysname\n"); > : + fprintf(stderr, "usage: config [-CgpV] [-k srcdir] [-d destdir] sysname\n"); > : fprintf(stderr, " config -x kernel\n"); > : exit(EX_USAGE); > : } > : Index: mkmakefile.c > : =================================================================== > : --- mkmakefile.c (revision 206411) > : +++ mkmakefile.c (working copy) > : @@ -116,7 +116,12 @@ makefile(void) > : int versreq; > : > : read_files(); > : - snprintf(line, sizeof(line), "../../conf/Makefile.%s", machinename); > : + if (*ksrcdir != '\0') > : + snprintf(line, sizeof(line), "%s/conf/Makefile.%s", > : + ksrcdir, machinename); > : + else > : + snprintf(line, sizeof(line), "../../conf/Makefile.%s", > : + machinename); > : ifp = fopen(line, "r"); > : if (ifp == 0) { > : snprintf(line, sizeof(line), "Makefile.%s", machinename); > : @@ -139,7 +144,9 @@ makefile(void) > : fprintf(ofp, "DEBUG=-g\n"); > : if (profiling) > : fprintf(ofp, "PROFLEVEL=%d\n", profiling); > : - if (*srcdir != '\0') > : + if (*ksrcdir != '\0') > : + fprintf(ofp,"S=%s\n", ksrcdir); > : + else if (*srcdir != '\0') > : fprintf(ofp,"S=%s\n", srcdir); > : while (fgets(line, BUFSIZ, ifp) != 0) { > : if (*line != '%') { > : @@ -347,7 +354,12 @@ next: > : printf("%s: missing include filename.\n", fname); > : exit(1); > : } > : - (void) snprintf(ifname, sizeof(ifname), "../../%s", wd); > : + if (*ksrcdir != '\0') > : + (void) snprintf(ifname, sizeof(ifname), "%s/%s", > : + ksrcdir, wd); > : + else > : + (void) snprintf(ifname, sizeof(ifname), "../../%s", > : + wd); > : read_file(ifname); > : while (((wd = get_word(fp)) != (char *)EOF) && wd) > : ; > : @@ -544,9 +556,17 @@ read_files(void) > : char fname[MAXPATHLEN]; > : struct files_name *nl, *tnl; > : > : - (void) snprintf(fname, sizeof(fname), "../../conf/files"); > : + if (*ksrcdir != '\0') > : + (void) snprintf(fname, sizeof(fname), "%s/conf/files", > : + ksrcdir); > : + else > : + (void) snprintf(fname, sizeof(fname), "../../conf/files"); > : read_file(fname); > : - (void) snprintf(fname, sizeof(fname), > : + if (*ksrcdir != '\0') > : + (void) snprintf(fname, sizeof(fname), > : + "%s/conf/files.%s", ksrcdir, machinename); > : + else > : + (void) snprintf(fname, sizeof(fname), > : "../../conf/files.%s", machinename); > : read_file(fname); > : for (nl = STAILQ_FIRST(&fntab); nl != NULL; nl = tnl) { > : Index: config.8 > : =================================================================== > : --- config.8 (revision 206411) > : +++ config.8 (working copy) > : @@ -38,6 +38,7 @@ > : .Nm > : .Op Fl CVgp > : .Op Fl d Ar destdir > : +.Op Fl k Ar ksrcdir > : .Ar SYSTEM_NAME > : .Nm > : .Op Fl x Ar kernel > : @@ -78,6 +79,10 @@ Note that > : does not append > : .Ar SYSTEM_NAME > : to the directory given. > : +.It Fl k Ar ksrcdir > : +Use > : +.Ar ksrcdir > : +as the kernel source tree directory, instead of the default one. > : .It Fl g > : Configure a system for debugging. > : .It Fl x Ar kernel > : Index: config.h > : =================================================================== > : --- config.h (revision 206411) > : +++ config.h (working copy) > : @@ -196,6 +196,8 @@ extern int maxusers; > : > : extern char *PREFIX; /* Config file name - for error messages */ > : extern char srcdir[]; /* root of the kernel source tree */ > : +extern char ksrcdir[]; /* root of the kernel source tree > : + * set by -k flag */ > : > : #define eq(a,b) (!strcmp(a,b)) > : #define ns(s) strdup(s) > : Index: lang.l > : =================================================================== > : --- lang.l (revision 206411) > : +++ lang.l (working copy) > : @@ -259,7 +259,10 @@ include(const char *fname, int ateof) > : fnamebuf = NULL; > : fp = fopen(fname, "r"); > : if (fp == NULL && fname[0] != '.' && fname[0] != '/') { > : - asprintf(&fnamebuf, "../../conf/%s", fname); > : + if (*ksrcdir != '\0') > : + asprintf(&fnamebuf, "%s/conf/%s", ksrcdir, fname); > : + else > : + asprintf(&fnamebuf, "../../conf/%s", fname); > : if (fnamebuf != NULL) { > : fp = fopen(fnamebuf, "r"); > : free(fnamebuf); > : > : > : -- > : Alexandr Rybalko <ray@dlink.ua> > : aka Alex RAY <ray@ddteam.net> > : _______________________________________________ > : freebsd-embedded@freebsd.org mailing list > : http://lists.freebsd.org/mailman/listinfo/freebsd-embedded > : To unsubscribe, send any mail to "freebsd-embedded-unsubscribe@freebsd.org" > : > : -- Alex RAY <ray@ddteam.net>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100414225613.99ceff5d.ray>