Exemple #1
0
static Boolean
ReadMakefile(
	const char *fname,	/* makefile to read */
	Boolean isSystem)	/* system makefile */
{
	FILE *stream;
	string_t name;

	if (!strcmp(fname, "-")) {
		Var_Set(sMAKEFILE, sNULL, VAR_GLOBAL);
		Parse_File(string_create("(stdin)"), stdin);
	} else {
		string_t sfname = string_create(fname);
		if (!isSystem) {
		    name = Dir_FindFile(sfname, dirSearchPath);
		} else {
		    name = Dir_FindFile(sfname, parseIncPath);
		    if (name == (string_t) NULL)
			name = Dir_FindFile(sfname, sysIncPath);
		}
		string_deref(sfname);
		if (name == (string_t) NULL ||
		    (stream = fopen(name->data, "r")) == NULL)
			return(FALSE);
		/*
		 * set the MAKEFILE variable desired by System V fans -- the
		 * placement of the setting here means it gets set to the last
		 * makefile specified, as it is set by SysV make.
		 */
		Var_Set(sMAKEFILE, name, VAR_GLOBAL);
		Parse_File(name, stream);
		(void)fclose(stream);
	}
	return(TRUE);
}
Exemple #2
0
/*-
 * ReadMakefile  --
 *	Open and parse the given makefile.
 *
 * Results:
 *	true if ok. false if couldn't open file.
 *
 * Side Effects:
 *	lots
 */
static bool
ReadMakefile(void *p, void *q)
{
	const char *fname = p;	/* makefile to read */
	struct dirs *d = q;
	FILE *stream;
	char *name;

	if (!strcmp(fname, "-")) {
		Var_Set("MAKEFILE", "");
		Parse_File(estrdup("(stdin)"), stdin);
	} else {
		if ((stream = fopen(fname, "r")) != NULL)
			goto found;
		/* if we've chdir'd, rebuild the path name */
		if (d->current != d->object && *fname != '/') {
			char *path;

			path = Str_concat(d->current, fname, '/');
			if ((stream = fopen(path, "r")) == NULL)
				free(path);
			else {
				fname = path;
				goto found;
			}
		}
		/* look in -I and system include directories. */
		name = Dir_FindFile(fname, userIncludePath);
		if (!name)
			name = Dir_FindFile(fname, systemIncludePath);
		if (!name || !(stream = fopen(name, "r")))
			return false;
		fname = name;
		/*
		 * set the MAKEFILE variable desired by System V fans -- the
		 * placement of the setting here means it gets set to the last
		 * makefile specified, as it is set by SysV make.
		 */
found:		Var_Set("MAKEFILE", fname);
		Parse_File(fname, stream);
	}
	return true;
}
Exemple #3
0
/*-
 *-----------------------------------------------------------------------
 * Arch_FindLib --
 *	Search for a library along the given search path.
 *
 * Input:
 *	gn		Node of library to find
 *	path		Search path
 *
 * Results:
 *	None.
 *
 * Side Effects:
 *	The node's 'path' field is set to the found path (including the
 *	actual file name, not -l...). If the system can handle the -L
 *	flag when linking (or we cannot find the library), we assume that
 *	the user has placed the .LIBRARIES variable in the final linking
 *	command (or the linker will know where to find it) and set the
 *	TARGET variable for this node to be the node's name. Otherwise,
 *	we set the TARGET variable to be the full path of the library,
 *	as returned by Dir_FindFile.
 *
 *-----------------------------------------------------------------------
 */
void
Arch_FindLib(GNode *gn, Lst path)
{
    char	    *libName;   /* file name for archive */
    size_t	     sz = strlen(gn->name) + 6 - 2;

    libName = bmake_malloc(sz);
    snprintf(libName, sz, "lib%s.a", &gn->name[2]);

    gn->path = Dir_FindFile(libName, path);

    free(libName);

#ifdef LIBRARIES
    Var_Set(TARGET, gn->name, gn, 0);
#else
    Var_Set(TARGET, gn->path == NULL ? gn->name : gn->path, gn, 0);
#endif /* LIBRARIES */
}
Exemple #4
0
/*-
 *-----------------------------------------------------------------------
 * CondDoExists --
 *	See if the given file exists.
 *
 * Results:
 *	TRUE if the file exists and FALSE if it does not.
 *
 * Side Effects:
 *	None.
 *
 *-----------------------------------------------------------------------
 */
static Boolean
CondDoExists(int argLen MAKE_ATTR_UNUSED, const char *arg)
{
    Boolean result;
    char    *path;

    path = Dir_FindFile(arg, dirSearchPath);
    if (DEBUG(COND)) {
	fprintf(debug_file, "exists(%s) result is \"%s\"\n",
	       arg, path ? path : "");
    }    
    if (path != NULL) {
	result = TRUE;
	free(path);
    } else {
	result = FALSE;
    }
    return (result);
}
Exemple #5
0
/*-
 * ReadMakefile  --
 *	Open and parse the given makefile.
 *
 * Results:
 *	TRUE if ok. FALSE if couldn't open file.
 *
 * Side Effects:
 *	lots
 */
static Boolean
ReadMakefile(ClientData p, ClientData q __unused)
{
	char *fname = p;		/* makefile to read */
	FILE *stream;
	size_t len = MAXPATHLEN;
	char *name, *path = emalloc(len);
	int setMAKEFILE;

	if (!strcmp(fname, "-")) {
		Parse_File("(stdin)", stdin);
		Var_Set("MAKEFILE", "", VAR_GLOBAL, 0);
	} else {
		setMAKEFILE = strcmp(fname, ".depend");

		/* if we've chdir'd, rebuild the path name */
		if (strcmp(curdir, objdir) && *fname != '/') {
			size_t plen = strlen(curdir) + strlen(fname) + 2;
			if (len < plen)
				path = erealloc(path, len = 2 * plen);
			
			(void)snprintf(path, len, "%s/%s", curdir, fname);
			if ((stream = fopen(path, "r")) != NULL) {
				fname = path;
				goto found;
			}
			
			/* If curdir failed, try objdir (ala .depend) */
			plen = strlen(objdir) + strlen(fname) + 2;
			if (len < plen)
				path = erealloc(path, len = 2 * plen);
			(void)snprintf(path, len, "%s/%s", objdir, fname);
			if ((stream = fopen(path, "r")) != NULL) {
				fname = path;
				goto found;
			}
		} else if ((stream = fopen(fname, "r")) != NULL)
			goto found;
		/* look in -I and system include directories. */
		name = Dir_FindFile(fname, parseIncPath);
		if (!name)
			name = Dir_FindFile(fname,
				Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
		if (!name || !(stream = fopen(name, "r"))) {
			free(path);
			return(FALSE);
		}
		fname = name;
		/*
		 * set the MAKEFILE variable desired by System V fans -- the
		 * placement of the setting here means it gets set to the last
		 * makefile specified, as it is set by SysV make.
		 */
found:
		if (setMAKEFILE)
			Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0);
		Parse_File(fname, stream);
		(void)fclose(stream);
	}
	free(path);
	return(TRUE);
}