Fri Aug 28 08:31:28 2015 UTC ()
Accept only relative paths (from $S) for `file' and `object'.  Simplify code.
config(1) does not need to be super-smart about path handling, because it is
usually used with make(1), that is much smarter.

Pre-compiled object files, specified using `object', are regarded as read-only
input, thus they should be put under $S (or $S/..), as part of a source tree.


(uebayasi)
diff -r1.38 -r1.39 src/usr.bin/config/mkmakefile.c

cvs diff -r1.38 -r1.39 src/usr.bin/config/mkmakefile.c (expand / switch to unified diff)

--- src/usr.bin/config/mkmakefile.c 2015/08/28 03:55:15 1.38
+++ src/usr.bin/config/mkmakefile.c 2015/08/28 08:31:28 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mkmakefile.c,v 1.38 2015/08/28 03:55:15 uebayasi Exp $ */ 1/* $NetBSD: mkmakefile.c,v 1.39 2015/08/28 08:31:28 uebayasi Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This software was developed by the Computer Systems Engineering group 7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley. 9 * contributed to Berkeley.
10 * 10 *
11 * All advertising materials mentioning features or use of this software 11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement: 12 * must display the following acknowledgement:
13 * This product includes software developed by the University of 13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories. 14 * California, Lawrence Berkeley Laboratories.
@@ -35,49 +35,43 @@ @@ -35,49 +35,43 @@
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE. 38 * SUCH DAMAGE.
39 * 39 *
40 * from: @(#)mkmakefile.c 8.1 (Berkeley) 6/6/93 40 * from: @(#)mkmakefile.c 8.1 (Berkeley) 6/6/93
41 */ 41 */
42 42
43#if HAVE_NBTOOL_CONFIG_H 43#if HAVE_NBTOOL_CONFIG_H
44#include "nbtool_config.h" 44#include "nbtool_config.h"
45#endif 45#endif
46 46
47#include <sys/cdefs.h> 47#include <sys/cdefs.h>
48__RCSID("$NetBSD: mkmakefile.c,v 1.38 2015/08/28 03:55:15 uebayasi Exp $"); 48__RCSID("$NetBSD: mkmakefile.c,v 1.39 2015/08/28 08:31:28 uebayasi Exp $");
49 49
50#include <sys/param.h> 50#include <sys/param.h>
51#include <ctype.h> 51#include <ctype.h>
52#include <errno.h> 52#include <errno.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <stdlib.h> 54#include <stdlib.h>
55#include <string.h> 55#include <string.h>
56#include <err.h> 56#include <err.h>
57#include <util.h> 57#include <util.h>
58#include "defs.h" 58#include "defs.h"
59#include "sem.h" 59#include "sem.h"
60 60
61/* 61/*
62 * Make the Makefile. 62 * Make the Makefile.
63 */ 63 */
64 64
65static const char *srcpath(struct files *);  
66 
67static const char *prefix_prologue(const char *); 
68static const char *filetype_prologue(struct filetype *); 
69 
70 
71static void emitdefs(FILE *); 65static void emitdefs(FILE *);
72static void emitfiles(FILE *, int, int); 66static void emitfiles(FILE *, int, int);
73 67
74static void emitobjs(FILE *); 68static void emitobjs(FILE *);
75static void emitallkobjs(FILE *); 69static void emitallkobjs(FILE *);
76static int emitallkobjscb(const char *, void *, void *); 70static int emitallkobjscb(const char *, void *, void *);
77static void emitattrkobjs(FILE *); 71static void emitattrkobjs(FILE *);
78static int emitattrkobjscb(const char *, void *, void *); 72static int emitattrkobjscb(const char *, void *, void *);
79static void emitkobjs(FILE *); 73static void emitkobjs(FILE *);
80static void emitcfiles(FILE *); 74static void emitcfiles(FILE *);
81static void emitsfiles(FILE *); 75static void emitsfiles(FILE *);
82static void emitrules(FILE *); 76static void emitrules(FILE *);
83static void emitload(FILE *); 77static void emitload(FILE *);
@@ -253,66 +247,26 @@ emitsubs(FILE *fp, const char *line, con @@ -253,66 +247,26 @@ emitsubs(FILE *fp, const char *line, con
253 if (option != NULL) 247 if (option != NULL)
254 fputs(option->nv_str ? option->nv_str : "1", 248 fputs(option->nv_str ? option->nv_str : "1",
255 fp); 249 fp);
256 /* 250 /*
257 * Otherwise it's not a selected option and we don't 251 * Otherwise it's not a selected option and we don't
258 * output anything. 252 * output anything.
259 */ 253 */
260 } 254 }
261 255
262 line = nextpct + 1; 256 line = nextpct + 1;
263 } 257 }
264} 258}
265 259
266/* 
267 * Return (possibly in a static buffer) the name of the `source' for a 
268 * file. If we have `options source', or if the file is marked `always 
269 * source', this is always the path from the `file' line; otherwise we 
270 * get the .o from the obj-directory. 
271 */ 
272static const char * 
273srcpath(struct files *fi) 
274{ 
275#if 1 
276 /* Always have source, don't support object dirs for kernel builds. */ 
277 return (fi->fi_path); 
278#else 
279 static char buf[MAXPATHLEN]; 
280 
281 if (have_source || (fi->fi_flags & FI_ALWAYSSRC) != 0) 
282 return (fi->fi_path); 
283 if (objpath == NULL) { 
284 cfgerror("obj-directory not set"); 
285 return (NULL); 
286 } 
287 (void)snprintf(buf, sizeof buf, "%s/%s.o", objpath, fi->fi_base); 
288 return (buf); 
289#endif 
290} 
291 
292static const char * 
293filetype_prologue(struct filetype *fit) 
294{ 
295 
296 return (*fit->fit_path == '/') ? "" : "$S/"; 
297} 
298 
299static const char * 
300prefix_prologue(const char *path) 
301{ 
302 
303 return (*path == '/') ? "" : "$S/"; 
304} 
305 
306static void 260static void
307emitdefs(FILE *fp) 261emitdefs(FILE *fp)
308{ 262{
309 struct nvlist *nv; 263 struct nvlist *nv;
310 264
311 fprintf(fp, "KERNEL_BUILD=%s\n", conffile); 265 fprintf(fp, "KERNEL_BUILD=%s\n", conffile);
312 fputs("IDENT= \\\n", fp); 266 fputs("IDENT= \\\n", fp);
313 for (nv = options; nv != NULL; nv = nv->nv_next) { 267 for (nv = options; nv != NULL; nv = nv->nv_next) {
314 268
315 /* Skip any options output to a header file */ 269 /* Skip any options output to a header file */
316 if (DEFINED_OPTION(nv->nv_name)) 270 if (DEFINED_OPTION(nv->nv_name))
317 continue; 271 continue;
318 const char *s = nv->nv_str; 272 const char *s = nv->nv_str;
@@ -345,35 +299,32 @@ emitobjs(FILE *fp) @@ -345,35 +299,32 @@ emitobjs(FILE *fp)
345 struct objects *oi; 299 struct objects *oi;
346 300
347 fputs("OBJS= \\\n", fp); 301 fputs("OBJS= \\\n", fp);
348 TAILQ_FOREACH(fi, &allfiles, fi_next) { 302 TAILQ_FOREACH(fi, &allfiles, fi_next) {
349 if ((fi->fi_flags & FI_SEL) == 0) 303 if ((fi->fi_flags & FI_SEL) == 0)
350 continue; 304 continue;
351 fprintf(fp, "\t%s.o \\\n", fi->fi_base); 305 fprintf(fp, "\t%s.o \\\n", fi->fi_base);
352 } 306 }
353 TAILQ_FOREACH(oi, &allobjects, oi_next) { 307 TAILQ_FOREACH(oi, &allobjects, oi_next) {
354 const char *prologue, *prefix, *sep; 308 const char *prologue, *prefix, *sep;
355 309
356 if ((oi->oi_flags & OI_SEL) == 0) 310 if ((oi->oi_flags & OI_SEL) == 0)
357 continue; 311 continue;
358 prologue = prefix = sep = ""; 312 prologue = "$S/";
359 if (*oi->oi_path != '/') { 313 if (oi->oi_prefix != NULL) {
360 if (oi->oi_prefix != NULL) { 314 prefix = oi->oi_prefix;
361 prologue = prefix_prologue(oi->oi_path); 315 sep = "/";
362 prefix = oi->oi_prefix; 316 } else {
363 sep = "/"; 317 prefix = sep = "";
364 } else { 
365 prologue = filetype_prologue(&oi->oi_fit); 
366 } 
367 } 318 }
368 fprintf(fp, "\t%s%s%s%s \\\n", prologue, prefix, sep, 319 fprintf(fp, "\t%s%s%s%s \\\n", prologue, prefix, sep,
369 oi->oi_path); 320 oi->oi_path);
370 } 321 }
371 putc('\n', fp); 322 putc('\n', fp);
372} 323}
373 324
374static void 325static void
375emitkobjs(FILE *fp) 326emitkobjs(FILE *fp)
376{ 327{
377 emitallkobjs(fp); 328 emitallkobjs(fp);
378 emitattrkobjs(fp); 329 emitattrkobjs(fp);
379} 330}
@@ -489,94 +440,84 @@ emitcfiles(FILE *fp) @@ -489,94 +440,84 @@ emitcfiles(FILE *fp)
489} 440}
490 441
491static void 442static void
492emitsfiles(FILE *fp) 443emitsfiles(FILE *fp)
493{ 444{
494 445
495 emitfiles(fp, 's', 'S'); 446 emitfiles(fp, 's', 'S');
496} 447}
497 448
498static void 449static void
499emitfiles(FILE *fp, int suffix, int upper_suffix) 450emitfiles(FILE *fp, int suffix, int upper_suffix)
500{ 451{
501 struct files *fi; 452 struct files *fi;
502 const char *fpath; 
503 struct config *cf; 453 struct config *cf;
504 char swapname[100]; 454 char swapname[100];
505 455
506 fprintf(fp, "%cFILES= \\\n", toupper(suffix)); 456 fprintf(fp, "%cFILES= \\\n", toupper(suffix));
507 TAILQ_FOREACH(fi, &allfiles, fi_next) { 457 TAILQ_FOREACH(fi, &allfiles, fi_next) {
508 const char *prologue, *prefix, *sep; 458 const char *prologue, *prefix, *sep;
509 459
510 if ((fi->fi_flags & FI_SEL) == 0) 460 if ((fi->fi_flags & FI_SEL) == 0)
511 continue; 461 continue;
512 fpath = srcpath(fi); 
513 if (fi->fi_suffix != suffix && fi->fi_suffix != upper_suffix) 462 if (fi->fi_suffix != suffix && fi->fi_suffix != upper_suffix)
514 continue; 463 continue;
515 prologue = prefix = sep = ""; 464 prologue = "$S/";
516 if (*fi->fi_path != '/') { 465 if (fi->fi_prefix != NULL) {
517 if (fi->fi_prefix != NULL) { 466 prefix = fi->fi_prefix;
518 prologue = prefix_prologue(fi->fi_prefix); 467 sep = "/";
519 prefix = fi->fi_prefix; 468 } else {
520 sep = "/"; 469 prefix = sep = "";
521 } else { 
522 prologue = filetype_prologue(&fi->fi_fit); 
523 } 
524 } 470 }
525 fprintf(fp, "\t%s%s%s%s \\\n", 471 fprintf(fp, "\t%s%s%s%s \\\n", prologue, prefix, sep,
526 prologue, prefix, sep, fpath); 472 fi->fi_path);
527 } 473 }
528 /* 474 /*
529 * The allfiles list does not include the configuration-specific 475 * The allfiles list does not include the configuration-specific
530 * C source files. These files should be eliminated someday, but 476 * C source files. These files should be eliminated someday, but
531 * for now, we have to add them to ${CFILES} (and only ${CFILES}). 477 * for now, we have to add them to ${CFILES} (and only ${CFILES}).
532 */ 478 */
533 if (suffix == 'c') { 479 if (suffix == 'c') {
534 TAILQ_FOREACH(cf, &allcf, cf_next) { 480 TAILQ_FOREACH(cf, &allcf, cf_next) {
535 (void)snprintf(swapname, sizeof(swapname), "swap%s.c", 481 (void)snprintf(swapname, sizeof(swapname), "swap%s.c",
536 cf->cf_name); 482 cf->cf_name);
537 fprintf(fp, "\t%s \\\n", swapname); 483 fprintf(fp, "\t%s \\\n", swapname);
538 } 484 }
539 } 485 }
540 putc('\n', fp); 486 putc('\n', fp);
541} 487}
542 488
543/* 489/*
544 * Emit the make-rules. 490 * Emit the make-rules.
545 */ 491 */
546static void 492static void
547emitrules(FILE *fp) 493emitrules(FILE *fp)
548{ 494{
549 struct files *fi; 495 struct files *fi;
550 const char *fpath; 
551 496
552 TAILQ_FOREACH(fi, &allfiles, fi_next) { 497 TAILQ_FOREACH(fi, &allfiles, fi_next) {
553 const char *prologue, *prefix, *sep; 498 const char *prologue, *prefix, *sep;
554 499
555 if ((fi->fi_flags & FI_SEL) == 0) 500 if ((fi->fi_flags & FI_SEL) == 0)
556 continue; 501 continue;
557 fpath = srcpath(fi); 502 prologue = "$S/";
558 prologue = prefix = sep = ""; 503 if (fi->fi_prefix != NULL) {
559 if (*fpath != '/') { 504 prefix = fi->fi_prefix;
560 if (fi->fi_prefix != NULL) { 505 sep = "/";
561 prologue = prefix_prologue(fi->fi_prefix); 506 } else {
562 prefix = fi->fi_prefix; 507 prefix = sep = "";
563 sep = "/"; 508 }
564 } else { 509 fprintf(fp, "%s.o: %s%s%s%s\n", fi->fi_base, prologue, prefix,
565 prologue = filetype_prologue(&fi->fi_fit); 510 sep, fi->fi_path);
566 } 
567 } 
568 fprintf(fp, "%s.o: %s%s%s%s\n", fi->fi_base, 
569 prologue, prefix, sep, fpath); 
570 if (fi->fi_mkrule != NULL) { 511 if (fi->fi_mkrule != NULL) {
571 fprintf(fp, "\t%s\n\n", fi->fi_mkrule); 512 fprintf(fp, "\t%s\n\n", fi->fi_mkrule);
572 } else { 513 } else {
573 fprintf(fp, "\t${NORMAL_%c}\n\n", toupper(fi->fi_suffix)); 514 fprintf(fp, "\t${NORMAL_%c}\n\n", toupper(fi->fi_suffix));
574 } 515 }
575 } 516 }
576} 517}
577 518
578/* 519/*
579 * Emit the load commands. 520 * Emit the load commands.
580 * 521 *
581 * This function is not to be called `spurt'. 522 * This function is not to be called `spurt'.
582 */ 523 */
@@ -622,27 +563,27 @@ emitload(FILE *fp) @@ -622,27 +563,27 @@ emitload(FILE *fp)
622 fputs("\n", fp); 563 fputs("\n", fp);
623} 564}
624 565
625/* 566/*
626 * Emit include headers (for any prefixes encountered) 567 * Emit include headers (for any prefixes encountered)
627 */ 568 */
628static void 569static void
629emitincludes(FILE *fp) 570emitincludes(FILE *fp)
630{ 571{
631 struct prefix *pf; 572 struct prefix *pf;
632 573
633 SLIST_FOREACH(pf, &allprefixes, pf_next) { 574 SLIST_FOREACH(pf, &allprefixes, pf_next) {
634 fprintf(fp, "EXTRA_INCLUDES+=\t-I%s%s\n", 575 fprintf(fp, "EXTRA_INCLUDES+=\t-I%s%s\n",
635 prefix_prologue(pf->pf_prefix), pf->pf_prefix); 576 "$S/", pf->pf_prefix);
636 } 577 }
637} 578}
638 579
639/* 580/*
640 * Emit appending makeoptions. 581 * Emit appending makeoptions.
641 */ 582 */
642static void 583static void
643emitappmkoptions(FILE *fp) 584emitappmkoptions(FILE *fp)
644{ 585{
645 struct nvlist *nv; 586 struct nvlist *nv;
646 struct condexpr *cond; 587 struct condexpr *cond;
647 588
648 for (nv = appmkoptions; nv != NULL; nv = nv->nv_next) 589 for (nv = appmkoptions; nv != NULL; nv = nv->nv_next)