2014-11-16 18:10:54 +03:00
|
|
|
/* $NetBSD: mkmakefile.c,v 1.32 2014/11/16 15:10:54 uebayasi Exp $ */
|
1996-03-03 20:21:25 +03:00
|
|
|
|
1996-03-17 09:29:19 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratories.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 15:25:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-04-28 10:54:58 +04:00
|
|
|
*
|
|
|
|
* from: @(#)mkmakefile.c 8.1 (Berkeley) 6/6/93
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
2004-06-21 02:20:14 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-29 20:14:50 +03:00
|
|
|
#include <sys/cdefs.h>
|
2014-11-16 18:10:54 +03:00
|
|
|
__RCSID("$NetBSD: mkmakefile.c,v 1.32 2014/11/16 15:10:54 uebayasi Exp $");
|
2014-10-29 20:14:50 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <sys/param.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <ctype.h>
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-01-14 02:47:36 +03:00
|
|
|
#include <err.h>
|
2014-11-15 11:21:38 +03:00
|
|
|
#include <util.h>
|
2002-01-29 13:20:28 +03:00
|
|
|
#include "defs.h"
|
1995-04-28 10:54:58 +04:00
|
|
|
#include "sem.h"
|
1996-03-17 16:18:15 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Make the Makefile.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
2000-10-02 23:48:34 +04:00
|
|
|
static const char *srcpath(struct files *);
|
2000-01-20 03:08:08 +03:00
|
|
|
|
2000-10-02 23:48:34 +04:00
|
|
|
static const char *prefix_prologue(const char *);
|
2005-11-07 06:26:20 +03:00
|
|
|
static const char *filetype_prologue(struct filetype *);
|
|
|
|
|
2000-01-20 03:08:08 +03:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void emitdefs(FILE *);
|
|
|
|
static void emitfiles(FILE *, int, int);
|
1996-03-17 16:18:15 +03:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void emitobjs(FILE *);
|
2014-10-09 21:00:15 +04:00
|
|
|
static void emitallkobjs(FILE *);
|
|
|
|
static int emitallkobjscb(const char *, void *, void *);
|
|
|
|
static void emitattrkobjs(FILE *);
|
|
|
|
static int emitattrkobjscb(const char *, void *, void *);
|
|
|
|
static void emitkobjs(FILE *);
|
2006-10-05 00:34:48 +04:00
|
|
|
static void emitcfiles(FILE *);
|
|
|
|
static void emitsfiles(FILE *);
|
|
|
|
static void emitrules(FILE *);
|
|
|
|
static void emitload(FILE *);
|
|
|
|
static void emitincludes(FILE *);
|
|
|
|
static void emitappmkoptions(FILE *);
|
2009-02-15 04:39:54 +03:00
|
|
|
static void emitsubs(FILE *, const char *, const char *, int);
|
2009-03-13 21:24:41 +03:00
|
|
|
static int selectopt(const char *, void *);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
mkmakefile(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
FILE *ifp, *ofp;
|
|
|
|
int lineno;
|
2006-10-05 00:34:48 +04:00
|
|
|
void (*fn)(FILE *);
|
1997-10-18 11:58:56 +04:00
|
|
|
char *ifname;
|
1996-09-01 00:58:16 +04:00
|
|
|
char line[BUFSIZ], buf[200];
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2000-12-03 02:01:54 +03:00
|
|
|
/* Try a makefile for the port first.
|
|
|
|
*/
|
2003-07-13 16:29:20 +04:00
|
|
|
(void)snprintf(buf, sizeof(buf), "arch/%s/conf/Makefile.%s",
|
|
|
|
machine, machine);
|
1996-09-01 00:58:16 +04:00
|
|
|
ifname = sourcepath(buf);
|
2000-12-03 02:01:54 +03:00
|
|
|
if ((ifp = fopen(ifname, "r")) == NULL) {
|
2014-10-09 23:33:43 +04:00
|
|
|
/*
|
|
|
|
* Try a makefile for the architecture second.
|
2000-12-03 02:01:54 +03:00
|
|
|
*/
|
2003-07-13 16:29:20 +04:00
|
|
|
(void)snprintf(buf, sizeof(buf), "arch/%s/conf/Makefile.%s",
|
|
|
|
machinearch, machinearch);
|
2006-03-19 19:27:13 +03:00
|
|
|
free(ifname);
|
2000-12-03 02:01:54 +03:00
|
|
|
ifname = sourcepath(buf);
|
2006-03-19 19:27:13 +03:00
|
|
|
ifp = fopen(ifname, "r");
|
2000-12-03 02:01:54 +03:00
|
|
|
}
|
2006-03-19 19:27:13 +03:00
|
|
|
if (ifp == NULL) {
|
2007-01-14 02:47:36 +03:00
|
|
|
warn("cannot read %s", ifname);
|
2006-03-19 19:27:13 +03:00
|
|
|
goto bad2;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
|
2002-02-13 02:20:11 +03:00
|
|
|
if ((ofp = fopen("Makefile.tmp", "w")) == NULL) {
|
2007-01-14 02:47:36 +03:00
|
|
|
warn("cannot write Makefile");
|
2006-03-19 19:27:13 +03:00
|
|
|
goto bad1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
|
|
|
|
emitdefs(ofp);
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
lineno = 0;
|
|
|
|
while (fgets(line, sizeof(line), ifp) != NULL) {
|
|
|
|
lineno++;
|
2009-02-20 08:20:25 +03:00
|
|
|
if ((version < 20090214 && line[0] != '%') || line[0] == '#') {
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs(line, ofp);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
if (strcmp(line, "%OBJS\n") == 0)
|
2014-11-06 14:40:32 +03:00
|
|
|
fn = Mflag ? emitkobjs : emitobjs;
|
1995-04-28 10:54:58 +04:00
|
|
|
else if (strcmp(line, "%CFILES\n") == 0)
|
|
|
|
fn = emitcfiles;
|
|
|
|
else if (strcmp(line, "%SFILES\n") == 0)
|
|
|
|
fn = emitsfiles;
|
|
|
|
else if (strcmp(line, "%RULES\n") == 0)
|
|
|
|
fn = emitrules;
|
|
|
|
else if (strcmp(line, "%LOAD\n") == 0)
|
|
|
|
fn = emitload;
|
1999-07-09 13:52:55 +04:00
|
|
|
else if (strcmp(line, "%INCLUDES\n") == 0)
|
|
|
|
fn = emitincludes;
|
2004-06-04 08:38:27 +04:00
|
|
|
else if (strcmp(line, "%MAKEOPTIONSAPPEND\n") == 0)
|
|
|
|
fn = emitappmkoptions;
|
2009-02-15 04:39:54 +03:00
|
|
|
else if (strncmp(line, "%VERSION ", sizeof("%VERSION ")-1) == 0) {
|
|
|
|
int newvers;
|
|
|
|
if (sscanf(line, "%%VERSION %d\n", &newvers) != 1) {
|
|
|
|
cfgxerror(ifname, lineno, "syntax error for "
|
|
|
|
"%%VERSION");
|
|
|
|
} else
|
|
|
|
setversion(newvers);
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (version < 20090214)
|
|
|
|
cfgxerror(ifname, lineno,
|
|
|
|
"unknown %% construct ignored: %s", line);
|
|
|
|
else
|
|
|
|
emitsubs(ofp, line, ifname, lineno);
|
1995-04-28 10:54:58 +04:00
|
|
|
continue;
|
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
(*fn)(ofp);
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
|
|
|
|
fflush(ofp);
|
|
|
|
if (ferror(ofp))
|
|
|
|
goto wrerror;
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
if (ferror(ifp)) {
|
2007-01-14 02:47:36 +03:00
|
|
|
warn("error reading %s (at line %d)", ifname, lineno);
|
1995-04-28 10:54:58 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
if (fclose(ofp)) {
|
|
|
|
ofp = NULL;
|
|
|
|
goto wrerror;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
(void)fclose(ifp);
|
2006-10-05 00:34:48 +04:00
|
|
|
|
2002-02-13 02:20:11 +03:00
|
|
|
if (moveifchanged("Makefile.tmp", "Makefile") != 0) {
|
2007-01-14 02:47:36 +03:00
|
|
|
warn("error renaming Makefile");
|
2006-03-19 19:27:13 +03:00
|
|
|
goto bad2;
|
2002-02-13 02:20:11 +03:00
|
|
|
}
|
1996-09-01 00:58:16 +04:00
|
|
|
free(ifname);
|
1995-04-28 10:54:58 +04:00
|
|
|
return (0);
|
2006-03-19 19:27:13 +03:00
|
|
|
|
2002-06-05 14:56:17 +04:00
|
|
|
wrerror:
|
2007-01-14 02:47:36 +03:00
|
|
|
warn("error writing Makefile");
|
2002-06-05 14:56:17 +04:00
|
|
|
bad:
|
1995-04-28 10:54:58 +04:00
|
|
|
if (ofp != NULL)
|
|
|
|
(void)fclose(ofp);
|
2006-03-19 19:27:13 +03:00
|
|
|
bad1:
|
|
|
|
(void)fclose(ifp);
|
2002-02-13 02:20:11 +03:00
|
|
|
/* (void)unlink("Makefile.tmp"); */
|
2006-03-19 19:27:13 +03:00
|
|
|
bad2:
|
1996-09-01 00:58:16 +04:00
|
|
|
free(ifname);
|
1995-04-28 10:54:58 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-02-15 04:39:54 +03:00
|
|
|
static void
|
|
|
|
emitsubs(FILE *fp, const char *line, const char *file, int lineno)
|
|
|
|
{
|
2009-02-15 06:45:44 +03:00
|
|
|
char *nextpct;
|
|
|
|
const char *optname;
|
2009-02-15 04:39:54 +03:00
|
|
|
struct nvlist *option;
|
|
|
|
|
|
|
|
while (*line != '\0') {
|
|
|
|
if (*line != '%') {
|
|
|
|
fputc(*line++, fp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
line++;
|
|
|
|
nextpct = strchr(line, '%');
|
|
|
|
if (nextpct == NULL) {
|
|
|
|
cfgxerror(file, lineno, "unbalanced %% or "
|
|
|
|
"unknown construct");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*nextpct = '\0';
|
|
|
|
|
|
|
|
if (*line == '\0')
|
|
|
|
fputc('%', fp);
|
|
|
|
else {
|
|
|
|
optname = intern(line);
|
|
|
|
if (!DEFINED_OPTION(optname)) {
|
|
|
|
cfgxerror(file, lineno, "unknown option %s",
|
|
|
|
optname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((option = ht_lookup(opttab, optname)) == NULL)
|
|
|
|
option = ht_lookup(fsopttab, optname);
|
|
|
|
if (option != NULL)
|
|
|
|
fputs(option->nv_str ? option->nv_str : "1",
|
|
|
|
fp);
|
2014-10-09 23:33:43 +04:00
|
|
|
/*
|
|
|
|
* Otherwise it's not a selected option and we don't
|
|
|
|
* output anything.
|
|
|
|
*/
|
2009-02-15 04:39:54 +03:00
|
|
|
}
|
|
|
|
|
2014-10-09 23:33:43 +04:00
|
|
|
line = nextpct + 1;
|
2009-02-15 04:39:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-03-17 16:18:15 +03:00
|
|
|
/*
|
|
|
|
* 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 *
|
2000-10-02 23:48:34 +04:00
|
|
|
srcpath(struct files *fi)
|
1996-03-17 16:18:15 +03:00
|
|
|
{
|
|
|
|
#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) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgerror("obj-directory not set");
|
1996-03-17 16:18:15 +03:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
(void)snprintf(buf, sizeof buf, "%s/%s.o", objpath, fi->fi_base);
|
|
|
|
return (buf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-01-20 03:08:08 +03:00
|
|
|
static const char *
|
2005-11-07 06:26:20 +03:00
|
|
|
filetype_prologue(struct filetype *fit)
|
2000-01-20 03:08:08 +03:00
|
|
|
{
|
2014-10-09 23:24:36 +04:00
|
|
|
if (*fit->fit_path == '/')
|
2005-11-07 06:26:20 +03:00
|
|
|
return ("");
|
|
|
|
else
|
|
|
|
return ("$S/");
|
|
|
|
}
|
2000-01-20 03:08:08 +03:00
|
|
|
|
2005-11-07 06:26:20 +03:00
|
|
|
static const char *
|
|
|
|
prefix_prologue(const char *path)
|
|
|
|
{
|
2000-01-20 03:08:08 +03:00
|
|
|
if (*path == '/')
|
|
|
|
return ("");
|
|
|
|
else
|
|
|
|
return ("$S/");
|
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitdefs(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct nvlist *nv;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "KERNEL_BUILD=%s\n", conffile);
|
2014-11-16 17:26:14 +03:00
|
|
|
fputs("IDENT= \\\n", fp);
|
1995-04-28 10:54:58 +04:00
|
|
|
for (nv = options; nv != NULL; nv = nv->nv_next) {
|
1998-06-30 07:30:56 +04:00
|
|
|
|
2014-10-09 23:33:43 +04:00
|
|
|
/* Skip any options output to a header file */
|
1998-06-30 07:30:56 +04:00
|
|
|
if (DEFINED_OPTION(nv->nv_name))
|
1997-02-03 00:12:30 +03:00
|
|
|
continue;
|
2014-11-16 17:26:14 +03:00
|
|
|
fprintf(fp, "\t-D%s%s%s%s \\\n", nv->nv_name,
|
|
|
|
(nv->nv_str != NULL) ? "=\"" : "",
|
|
|
|
(nv->nv_str != NULL) ? nv->nv_str : "",
|
|
|
|
(nv->nv_str != NULL) ? "\"" : "");
|
1994-01-08 13:33:43 +03:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
putc('\n', fp);
|
|
|
|
fprintf(fp, "PARAM=-DMAXUSERS=%d\n", maxusers);
|
|
|
|
fprintf(fp, "MACHINE=%s\n", machine);
|
1996-09-23 09:04:23 +04:00
|
|
|
if (*srcdir == '/' || *srcdir == '.') {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "S=\t%s\n", srcdir);
|
1996-09-01 00:58:16 +04:00
|
|
|
} else {
|
1996-09-23 09:04:23 +04:00
|
|
|
/*
|
|
|
|
* libkern and libcompat "Makefile.inc"s want relative S
|
|
|
|
* specification to begin with '.'.
|
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "S=\t./%s\n", srcdir);
|
1996-09-01 00:58:16 +04:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
for (nv = mkoptions; nv != NULL; nv = nv->nv_next)
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "%s=%s\n", nv->nv_name, nv->nv_str);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitobjs(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct files *fi;
|
|
|
|
struct objects *oi;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2014-10-09 21:36:10 +04:00
|
|
|
fputs("OBJS= \\\n", fp);
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(fi, &allfiles, fi_next) {
|
1995-04-28 10:54:58 +04:00
|
|
|
if ((fi->fi_flags & FI_SEL) == 0)
|
|
|
|
continue;
|
2014-10-09 21:36:10 +04:00
|
|
|
fprintf(fp, "\t%s.o \\\n", fi->fi_base);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(oi, &allobjects, oi_next) {
|
2014-11-16 17:49:12 +03:00
|
|
|
const char *prologue, *prefix, *sep;
|
|
|
|
|
1997-10-10 14:27:53 +04:00
|
|
|
if ((oi->oi_flags & OI_SEL) == 0)
|
|
|
|
continue;
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = prefix = sep = "";
|
|
|
|
if (*oi->oi_path != '/') {
|
1999-07-09 10:44:58 +04:00
|
|
|
if (oi->oi_prefix != NULL) {
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = prefix_prologue(oi->oi_path);
|
|
|
|
prefix = oi->oi_prefix;
|
|
|
|
sep = "/";
|
1999-07-09 10:44:58 +04:00
|
|
|
} else {
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = filetype_prologue(&oi->oi_fit);
|
1999-07-09 10:44:58 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-16 17:49:12 +03:00
|
|
|
fprintf(fp, "\t%s%s%s%s \\\n", prologue, prefix, sep,
|
|
|
|
oi->oi_path);
|
1997-10-10 14:27:53 +04:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
putc('\n', fp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2014-10-09 21:00:15 +04:00
|
|
|
static void
|
|
|
|
emitkobjs(FILE *fp)
|
|
|
|
{
|
|
|
|
emitallkobjs(fp);
|
|
|
|
emitattrkobjs(fp);
|
|
|
|
}
|
|
|
|
|
2014-11-15 11:21:38 +03:00
|
|
|
static int emitallkobjsweighcb(const char *name, void *v, void *arg);
|
|
|
|
static void weighattr(struct attr *a);
|
|
|
|
static int attrcmp(const void *l, const void *r);
|
|
|
|
|
|
|
|
struct attr **attrbuf;
|
|
|
|
int attridx;
|
|
|
|
|
2014-10-09 21:00:15 +04:00
|
|
|
static void
|
|
|
|
emitallkobjs(FILE *fp)
|
|
|
|
{
|
2014-11-15 11:21:38 +03:00
|
|
|
int i;
|
2014-10-09 21:00:15 +04:00
|
|
|
|
2014-11-15 15:18:55 +03:00
|
|
|
attrbuf = emalloc((size_t)nattrs * sizeof(attrbuf));
|
2014-11-15 11:21:38 +03:00
|
|
|
|
|
|
|
ht_enumerate(attrtab, emitallkobjsweighcb, NULL);
|
2014-11-15 15:18:55 +03:00
|
|
|
ht_enumerate(attrtab, emitallkobjscb, NULL);
|
2014-11-15 11:21:38 +03:00
|
|
|
qsort(attrbuf, (size_t)attridx, sizeof(struct attr *), attrcmp);
|
|
|
|
|
2014-11-16 17:26:14 +03:00
|
|
|
fputs("OBJS= \\\n", fp);
|
2014-11-15 11:21:38 +03:00
|
|
|
for (i = 0; i < attridx; i++)
|
2014-11-16 17:26:14 +03:00
|
|
|
fprintf(fp, "\t%s.ko \\\n", attrbuf[i]->a_name);
|
2014-10-09 21:00:15 +04:00
|
|
|
putc('\n', fp);
|
2014-11-15 11:21:38 +03:00
|
|
|
|
|
|
|
free(attrbuf);
|
2014-10-09 21:00:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
emitallkobjscb(const char *name, void *v, void *arg)
|
|
|
|
{
|
|
|
|
struct attr *a = v;
|
|
|
|
|
|
|
|
if (ht_lookup(selecttab, name) == NULL)
|
|
|
|
return 0;
|
|
|
|
if (TAILQ_EMPTY(&a->a_files))
|
|
|
|
return 0;
|
2014-11-15 11:21:38 +03:00
|
|
|
attrbuf[attridx++] = a;
|
2014-11-15 15:18:55 +03:00
|
|
|
/* XXX nattrs tracking is not exact yet */
|
|
|
|
if (attridx == nattrs) {
|
|
|
|
nattrs *= 2;
|
|
|
|
attrbuf = erealloc(attrbuf, (size_t)nattrs * sizeof(attrbuf));
|
|
|
|
}
|
2014-10-09 21:00:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-15 11:21:38 +03:00
|
|
|
static int
|
|
|
|
emitallkobjsweighcb(const char *name, void *v, void *arg)
|
|
|
|
{
|
|
|
|
struct attr *a = v;
|
|
|
|
|
|
|
|
weighattr(a);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
weighattr(struct attr *a)
|
|
|
|
{
|
|
|
|
struct attrlist *al;
|
|
|
|
|
|
|
|
for (al = a->a_deps; al != NULL; al = al->al_next) {
|
|
|
|
weighattr(al->al_this);
|
|
|
|
}
|
|
|
|
a->a_weight++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
attrcmp(const void *l, const void *r)
|
|
|
|
{
|
|
|
|
const struct attr * const *a = l, * const *b = r;
|
|
|
|
const int wa = (*a)->a_weight, wb = (*b)->a_weight;
|
|
|
|
return (wa > wb) ? -1 : (wa < wb) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2014-10-09 21:00:15 +04:00
|
|
|
static void
|
|
|
|
emitattrkobjs(FILE *fp)
|
|
|
|
{
|
|
|
|
extern struct hashtab *attrtab;
|
|
|
|
|
|
|
|
ht_enumerate(attrtab, emitattrkobjscb, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
emitattrkobjscb(const char *name, void *v, void *arg)
|
|
|
|
{
|
|
|
|
struct attr *a = v;
|
|
|
|
struct files *fi;
|
|
|
|
FILE *fp = arg;
|
|
|
|
|
|
|
|
if (ht_lookup(selecttab, name) == NULL)
|
|
|
|
return 0;
|
|
|
|
if (TAILQ_EMPTY(&a->a_files))
|
|
|
|
return 0;
|
|
|
|
fputc('\n', fp);
|
2014-11-15 11:21:38 +03:00
|
|
|
fprintf(fp, "# %s (%d)\n", name, a->a_weight);
|
2014-11-16 17:26:14 +03:00
|
|
|
fprintf(fp, "OBJS.%s= \\\n", name);
|
2014-10-09 21:00:15 +04:00
|
|
|
TAILQ_FOREACH(fi, &a->a_files, fi_anext) {
|
2014-11-16 17:26:14 +03:00
|
|
|
fprintf(fp, "\t%s.o \\\n", fi->fi_base);
|
2014-10-09 21:00:15 +04:00
|
|
|
}
|
|
|
|
fputc('\n', fp);
|
|
|
|
fprintf(fp, "%s.ko: ${OBJS.%s}\n", name, name);
|
|
|
|
fprintf(fp, "\t${LINK_O}\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitcfiles(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
emitfiles(fp, 'c', 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitsfiles(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
emitfiles(fp, 's', 'S');
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2001-01-31 03:15:40 +03:00
|
|
|
emitfiles(FILE *fp, int suffix, int upper_suffix)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct files *fi;
|
2014-10-29 20:14:50 +03:00
|
|
|
size_t len;
|
1997-10-18 11:58:56 +04:00
|
|
|
const char *fpath;
|
2005-11-07 21:45:34 +03:00
|
|
|
struct config *cf;
|
|
|
|
char swapname[100];
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2014-10-09 21:36:10 +04:00
|
|
|
fprintf(fp, "%cFILES= \\\n", toupper(suffix));
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(fi, &allfiles, fi_next) {
|
2014-11-16 17:49:12 +03:00
|
|
|
const char *prologue, *prefix, *sep;
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
if ((fi->fi_flags & FI_SEL) == 0)
|
1993-08-03 04:02:01 +04:00
|
|
|
continue;
|
2006-10-05 00:34:48 +04:00
|
|
|
fpath = srcpath(fi);
|
1996-03-17 16:18:15 +03:00
|
|
|
len = strlen(fpath);
|
2006-10-05 00:34:48 +04:00
|
|
|
if (fpath[len - 1] != suffix && fpath[len - 1] != upper_suffix)
|
1993-08-03 04:02:01 +04:00
|
|
|
continue;
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = prefix = sep = "";
|
|
|
|
if (*fi->fi_path != '/') {
|
1999-07-09 10:44:58 +04:00
|
|
|
if (fi->fi_prefix != NULL) {
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = prefix_prologue(fi->fi_prefix);
|
|
|
|
prefix = fi->fi_prefix;
|
|
|
|
sep = "/";
|
1999-07-09 10:44:58 +04:00
|
|
|
} else {
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = filetype_prologue(&fi->fi_fit);
|
1999-07-09 10:44:58 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-16 17:49:12 +03:00
|
|
|
fprintf(fp, "\t%s%s%s%s \\\n",
|
|
|
|
prologue, prefix, sep, fpath);
|
1993-08-03 04:02:01 +04:00
|
|
|
}
|
2005-11-07 21:45:34 +03:00
|
|
|
/*
|
|
|
|
* The allfiles list does not include the configuration-specific
|
|
|
|
* C source files. These files should be eliminated someday, but
|
|
|
|
* for now, we have to add them to ${CFILES} (and only ${CFILES}).
|
|
|
|
*/
|
|
|
|
if (suffix == 'c') {
|
|
|
|
TAILQ_FOREACH(cf, &allcf, cf_next) {
|
|
|
|
(void)snprintf(swapname, sizeof(swapname), "swap%s.c",
|
|
|
|
cf->cf_name);
|
2014-10-09 21:36:10 +04:00
|
|
|
fprintf(fp, "\t%s \\\n", swapname);
|
2005-11-07 21:45:34 +03:00
|
|
|
}
|
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
putc('\n', fp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Emit the make-rules.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitrules(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct files *fi;
|
2014-11-16 17:57:59 +03:00
|
|
|
size_t len;
|
|
|
|
const char *fpath;
|
|
|
|
int suffix;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(fi, &allfiles, fi_next) {
|
2014-11-16 17:49:12 +03:00
|
|
|
const char *prologue, *prefix, *sep;
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
if ((fi->fi_flags & FI_SEL) == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
2006-10-05 00:34:48 +04:00
|
|
|
fpath = srcpath(fi);
|
2014-11-16 17:57:59 +03:00
|
|
|
len = strlen(fpath);
|
|
|
|
suffix = fpath[len - 1];
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = prefix = sep = "";
|
|
|
|
if (*fpath != '/') {
|
1999-07-09 13:52:55 +04:00
|
|
|
if (fi->fi_prefix != NULL) {
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = prefix_prologue(fi->fi_prefix);
|
|
|
|
prefix = fi->fi_prefix;
|
|
|
|
sep = "/";
|
1999-07-09 13:52:55 +04:00
|
|
|
} else {
|
2014-11-16 17:49:12 +03:00
|
|
|
prologue = filetype_prologue(&fi->fi_fit);
|
2008-07-16 15:45:56 +04:00
|
|
|
}
|
1999-07-09 13:52:55 +04:00
|
|
|
}
|
2014-11-16 17:49:12 +03:00
|
|
|
fprintf(fp, "%s.o: %s%s%s%s\n", fi->fi_base,
|
|
|
|
prologue, prefix, sep, fpath);
|
2008-07-16 15:45:56 +04:00
|
|
|
if (fi->fi_mkrule != NULL) {
|
|
|
|
fprintf(fp, "\t%s\n\n", fi->fi_mkrule);
|
|
|
|
} else {
|
2014-11-16 17:57:59 +03:00
|
|
|
fprintf(fp, "\t${NORMAL_%c}\n\n", toupper(suffix));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Emit the load commands.
|
|
|
|
*
|
|
|
|
* This function is not to be called `spurt'.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitload(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct config *cf;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs(".MAIN: all\nall:", fp);
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(cf, &allcf, cf_next) {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, " %s", cf->cf_name);
|
2012-06-08 12:56:45 +04:00
|
|
|
/*
|
|
|
|
* If we generate multiple configs inside the same build directory
|
|
|
|
* with a parallel build, strange things may happen, so sequentialize
|
|
|
|
* them.
|
|
|
|
*/
|
|
|
|
if (cf != TAILQ_LAST(&allcf,conftq))
|
|
|
|
fprintf(fp, " .WAIT");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs("\n\n", fp);
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(cf, &allcf, cf_next) {
|
2014-08-18 12:07:02 +04:00
|
|
|
fprintf(fp, "KERNELS+=%s\n", cf->cf_name);
|
2014-08-18 01:17:43 +04:00
|
|
|
fprintf(fp, "%s: ${SYSTEM_DEP} swap%s.o vers.o build_kernel\n",
|
2014-10-09 23:33:43 +04:00
|
|
|
cf->cf_name, cf->cf_name);
|
2014-08-18 12:07:02 +04:00
|
|
|
fprintf(fp, "swap%s.o: swap%s.c\n"
|
2014-10-09 23:33:43 +04:00
|
|
|
"\t${NORMAL_C}\n\n", cf->cf_name, cf->cf_name);
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
2014-08-18 01:17:43 +04:00
|
|
|
fputs("\n", fp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1999-07-09 13:52:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit include headers (for any prefixes encountered)
|
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitincludes(FILE *fp)
|
1999-07-09 13:52:55 +04:00
|
|
|
{
|
|
|
|
struct prefix *pf;
|
|
|
|
|
2002-06-05 14:56:17 +04:00
|
|
|
SLIST_FOREACH(pf, &allprefixes, pf_next) {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "EXTRA_INCLUDES+=\t-I%s%s\n",
|
|
|
|
prefix_prologue(pf->pf_prefix), pf->pf_prefix);
|
1999-07-09 13:52:55 +04:00
|
|
|
}
|
|
|
|
}
|
2004-06-04 08:38:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit appending makeoptions.
|
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2004-06-04 08:38:27 +04:00
|
|
|
emitappmkoptions(FILE *fp)
|
|
|
|
{
|
|
|
|
struct nvlist *nv;
|
2012-03-11 12:21:53 +04:00
|
|
|
struct condexpr *cond;
|
2004-06-04 08:38:27 +04:00
|
|
|
|
|
|
|
for (nv = appmkoptions; nv != NULL; nv = nv->nv_next)
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "%s+=%s\n", nv->nv_name, nv->nv_str);
|
2004-06-04 11:28:26 +04:00
|
|
|
|
2012-03-11 12:21:53 +04:00
|
|
|
for (nv = condmkoptions; nv != NULL; nv = nv->nv_next) {
|
|
|
|
cond = nv->nv_ptr;
|
|
|
|
if (expr_eval(cond, selectopt, NULL))
|
2009-03-13 21:24:41 +03:00
|
|
|
fprintf(fp, "%s+=%s\n", nv->nv_name, nv->nv_str);
|
2012-03-11 12:21:53 +04:00
|
|
|
condexpr_destroy(cond);
|
|
|
|
nv->nv_ptr = NULL;
|
2009-03-13 21:24:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
/*ARGSUSED*/
|
|
|
|
selectopt(const char *name, void *context)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ht_lookup(selecttab, strtolower(name)) != NULL);
|
2004-06-04 08:38:27 +04:00
|
|
|
}
|