summaryrefslogtreecommitdiff
path: root/usr.sbin/config/mkmakefile.c
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2008-03-22 22:30:37 +0000
committerMarc Espie <espie@cvs.openbsd.org>2008-03-22 22:30:37 +0000
commitded523d27e36fc3c3d30b310249b8d8501159c68 (patch)
treecd74a4898ec2afad9dd842b179cfe1b7b5b1452d /usr.sbin/config/mkmakefile.c
parent5e35f4f050f1ccddbff8141231e8763e6b2d3dbb (diff)
put in explicit suffix rules, they're needed anyways since $< is only used
for suffix rules. Use them to avoid writing loads of explicit lines. Shaves 2/3 of each Makefile off. okay miod@, deraadt@, henning@
Diffstat (limited to 'usr.sbin/config/mkmakefile.c')
-rw-r--r--usr.sbin/config/mkmakefile.c75
1 files changed, 51 insertions, 24 deletions
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index 83bd8cfa675..7f77bdc09fd 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkmakefile.c,v 1.27 2007/11/27 14:56:31 chl Exp $ */
+/* $OpenBSD: mkmakefile.c,v 1.28 2008/03/22 22:30:36 espie Exp $ */
/* $NetBSD: mkmakefile.c,v 1.34 1997/02/02 21:12:36 thorpej Exp $ */
/*
@@ -444,46 +444,73 @@ emitfiles(FILE *fp, int suffix)
* Emit the make-rules.
*/
static int
-emitrules1(FILE *fp, const char *suffix, const char *rule_prefix, int ruleindex)
+emit_1rule(FILE *fp, struct files *fi, const char *fpath, const char *suffix,
+ int ruleindex)
+{
+ if (fprintf(fp, "%s%s: %s%s\n", fi->fi_base, suffix,
+ *fpath != '/' ? "$S/" : "", fpath) < 0)
+ return (1);
+ if (fi->fi_mkrule[ruleindex] != NULL) {
+ if (fprintf(fp, "\t%s\n\n", fi->fi_mkrule[ruleindex]) < 0)
+ return (1);
+ }
+}
+
+static int
+emitrules(FILE *fp)
{
struct files *fi;
const char *cp, *fpath;
int ch;
char buf[200];
+ /* write suffixes */
+ if (fprintf(fp,
+ ".SUFFIXES:\n"
+ ".SUFFIXES: .s .S .c .o .ln\n\n"
+
+ ".c.o:\n"
+ "\t${NORMAL_C}\n\n"
+
+ ".c.ln:\n"
+ "\t${LINT_C}\n\n"
+
+ ".s.o:\n"
+ "\t${NORMAL_S}\n\n"
+
+ ".s.ln:\n"
+ "\t${LINT_S}\n\n"
+
+ ".S.o:\n"
+ "\t${NORMAL_S}\n\n"
+
+ ".S.ln:\n"
+ "\t${LINT_S}\n\n") < 0)
+ return (1);
+
+
for (fi = allfiles; fi != NULL; fi = fi->fi_next) {
if ((fi->fi_flags & FI_SEL) == 0)
continue;
if ((fpath = srcpath(fi)) == NULL)
return (1);
- if (fprintf(fp, "%s%s: %s%s\n", fi->fi_base, suffix,
- *fpath != '/' ? "$S/" : "", fpath) < 0)
- return (1);
- if ((cp = fi->fi_mkrule[ruleindex]) == NULL) {
- cp = rule_prefix;
- if (fpath[0] == '\0') {
- errno = ENOENT;
+ /* special rule: need to emit them independently */
+ if (fi->fi_mkrule[0] || fi->fi_mkrule[1]) {
+ if (emit_1rule(fp, fi, fpath, ".o", 0) ||
+ emit_1rule(fp, fi, fpath, ".ln", 1))
+ return (1);
+ /* simple default rule */
+ } else {
+ if (fprintf(fp, "%s.o %s.ln: %s%s\n", fi->fi_base,
+ fi->fi_base,
+ *fpath != '/' ? "$S/" : "", fpath) < 0)
return (1);
- }
- ch = fpath[strlen(fpath) - 1];
- if (islower(ch))
- ch = toupper(ch);
- (void)snprintf(buf, sizeof buf, "${%s_%c}",
- cp, ch);
- cp = buf;
}
- if (fprintf(fp, "\t%s\n\n", cp) < 0)
- return (1);
+
}
return (0);
}
-static int
-emitrules(FILE *fp)
-{
- return emitrules1(fp, ".o", "NORMAL", 0) || emitrules1(fp, ".ln", "LINT", 1);
-}
-
/*
* Emit the load commands.
*