Refactor emit file functions. No functional changes.

This commit is contained in:
uebayasi 2015-09-01 00:38:30 +00:00
parent 13b8e486ae
commit 4c482b808f
1 changed files with 30 additions and 95 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkmakefile.c,v 1.49 2015/08/30 21:58:19 uebayasi Exp $ */ /* $NetBSD: mkmakefile.c,v 1.50 2015/09/01 00:38:30 uebayasi Exp $ */
/* /*
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
@ -45,7 +45,7 @@
#endif #endif
#include <sys/cdefs.h> #include <sys/cdefs.h>
__RCSID("$NetBSD: mkmakefile.c,v 1.49 2015/08/30 21:58:19 uebayasi Exp $"); __RCSID("$NetBSD: mkmakefile.c,v 1.50 2015/09/01 00:38:30 uebayasi Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <ctype.h> #include <ctype.h>
@ -62,12 +62,6 @@ __RCSID("$NetBSD: mkmakefile.c,v 1.49 2015/08/30 21:58:19 uebayasi Exp $");
* Make the Makefile. * Make the Makefile.
*/ */
static const char *srcpath(struct files *);
static const char *prefix_prologue(const char *);
static const char *filetype_prologue(struct filetype *);
static void emitdefs(FILE *); static void emitdefs(FILE *);
static void emitfiles(FILE *, int, int); static void emitfiles(FILE *, int, int);
@ -263,46 +257,6 @@ emitsubs(FILE *fp, const char *line, const char *file, int lineno)
} }
} }
/*
* Return (possibly in a static buffer) the name of the `source' for a
* file. If we have `options source', or if the file is marked `always
* source', this is always the path from the `file' line; otherwise we
* get the .o from the obj-directory.
*/
static const char *
srcpath(struct files *fi)
{
#if 1
/* Always have source, don't support object dirs for kernel builds. */
return (fi->fi_path);
#else
static char buf[MAXPATHLEN];
if (have_source || (fi->fi_flags & FI_ALWAYSSRC) != 0)
return (fi->fi_path);
if (objpath == NULL) {
cfgerror("obj-directory not set");
return (NULL);
}
(void)snprintf(buf, sizeof buf, "%s/%s.o", objpath, fi->fi_base);
return (buf);
#endif
}
static const char *
filetype_prologue(struct filetype *fit)
{
return (*fit->fit_path == '/') ? "" : "$S/";
}
static const char *
prefix_prologue(const char *path)
{
return (*path == '/') ? "" : "$S/";
}
static void static void
emitdefs(FILE *fp) emitdefs(FILE *fp)
{ {
@ -337,6 +291,22 @@ emitdefs(FILE *fp)
fprintf(fp, "%s=%s\n", nv->nv_name, nv->nv_str); fprintf(fp, "%s=%s\n", nv->nv_name, nv->nv_str);
} }
static void
emitfiletype(FILE *fp, struct filetype *fit)
{
const char *prologue, *prefix, *sep;
prologue = prefix = sep = "";
if (*fit->fit_path != '/') {
prologue = "$S/";
if (fit->fit_prefix != NULL) {
prefix = fit->fit_prefix;
sep = "/";
}
}
fprintf(fp, "%s%s%s%s", prologue, prefix, sep, fit->fit_path);
}
static void static void
emitobjs(FILE *fp) emitobjs(FILE *fp)
{ {
@ -350,22 +320,11 @@ emitobjs(FILE *fp)
fprintf(fp, "\t%s.o \\\n", fi->fi_base); fprintf(fp, "\t%s.o \\\n", fi->fi_base);
} }
TAILQ_FOREACH(oi, &allobjects, oi_next) { TAILQ_FOREACH(oi, &allobjects, oi_next) {
const char *prologue, *prefix, *sep;
if ((oi->oi_flags & OI_SEL) == 0) if ((oi->oi_flags & OI_SEL) == 0)
continue; continue;
prologue = prefix = sep = ""; putc('\t', fp);
if (*oi->oi_path != '/') { emitfiletype(fp, &oi->oi_fit);
if (oi->oi_prefix != NULL) { fputs(" \\\n", fp);
prologue = prefix_prologue(oi->oi_path);
prefix = oi->oi_prefix;
sep = "/";
} else {
prologue = filetype_prologue(&oi->oi_fit);
}
}
fprintf(fp, "\t%s%s%s%s \\\n", prologue, prefix, sep,
oi->oi_path);
} }
putc('\n', fp); putc('\n', fp);
} }
@ -498,31 +457,18 @@ static void
emitfiles(FILE *fp, int suffix, int upper_suffix) emitfiles(FILE *fp, int suffix, int upper_suffix)
{ {
struct files *fi; struct files *fi;
const char *fpath;
struct config *cf; struct config *cf;
char swapname[100]; char swapname[100];
fprintf(fp, "%cFILES= \\\n", toupper(suffix)); fprintf(fp, "%cFILES= \\\n", toupper(suffix));
TAILQ_FOREACH(fi, &allfiles, fi_next) { TAILQ_FOREACH(fi, &allfiles, fi_next) {
const char *prologue, *prefix, *sep;
if ((fi->fi_flags & FI_SEL) == 0) if ((fi->fi_flags & FI_SEL) == 0)
continue; continue;
fpath = srcpath(fi);
if (fi->fi_suffix != suffix && fi->fi_suffix != upper_suffix) if (fi->fi_suffix != suffix && fi->fi_suffix != upper_suffix)
continue; continue;
prologue = prefix = sep = ""; putc('\t', fp);
if (*fi->fi_path != '/') { emitfiletype(fp, &fi->fi_fit);
if (fi->fi_prefix != NULL) { fputs(" \\\n", fp);
prologue = prefix_prologue(fi->fi_prefix);
prefix = fi->fi_prefix;
sep = "/";
} else {
prologue = filetype_prologue(&fi->fi_fit);
}
}
fprintf(fp, "\t%s%s%s%s \\\n",
prologue, prefix, sep, fpath);
} }
/* /*
@ -547,28 +493,15 @@ static void
emitrules(FILE *fp) emitrules(FILE *fp)
{ {
struct files *fi; struct files *fi;
const char *fpath;
TAILQ_FOREACH(fi, &allfiles, fi_next) { TAILQ_FOREACH(fi, &allfiles, fi_next) {
const char *prologue, *prefix, *sep;
if ((fi->fi_flags & FI_SEL) == 0) if ((fi->fi_flags & FI_SEL) == 0)
continue; continue;
if (fi->fi_mkrule == NULL) if (fi->fi_mkrule == NULL)
continue; continue;
fpath = srcpath(fi); fprintf(fp, "%s.o: ", fi->fi_base);
prologue = prefix = sep = ""; emitfiletype(fp, &fi->fi_fit);
if (*fpath != '/') { putc('\n', fp);
if (fi->fi_prefix != NULL) {
prologue = prefix_prologue(fi->fi_prefix);
prefix = fi->fi_prefix;
sep = "/";
} else {
prologue = filetype_prologue(&fi->fi_fit);
}
}
fprintf(fp, "%s.o: %s%s%s%s\n", fi->fi_base,
prologue, prefix, sep, fpath);
fprintf(fp, "\t%s\n\n", fi->fi_mkrule); fprintf(fp, "\t%s\n\n", fi->fi_mkrule);
} }
} }
@ -627,8 +560,10 @@ emitincludes(FILE *fp)
struct prefix *pf; struct prefix *pf;
SLIST_FOREACH(pf, &allprefixes, pf_next) { SLIST_FOREACH(pf, &allprefixes, pf_next) {
const char *prologue = (*pf->pf_prefix == '/') ? "" : "$S/";
fprintf(fp, "EXTRA_INCLUDES+=\t-I%s%s\n", fprintf(fp, "EXTRA_INCLUDES+=\t-I%s%s\n",
prefix_prologue(pf->pf_prefix), pf->pf_prefix); prologue, pf->pf_prefix);
} }
} }