2 * Copyright (C) 2002-2005 Roman Zippel <zippel@linux-m68k.org>
3 * Copyright (C) 2002-2005 Sam Ravnborg <sam@ravnborg.org>
5 * Released under the terms of the GNU GPL v2.0.
11 /* file already present in list? If not add it */
12 struct file *file_lookup(const char *name)
15 const char *file_name = sym_expand_string_value(name);
17 for (file = file_list; file; file = file->next) {
18 if (!strcmp(name, file->name)) {
19 free((void *)file_name);
24 file = malloc(sizeof(*file));
25 memset(file, 0, sizeof(*file));
26 file->name = file_name;
27 file->next = file_list;
32 /* write a dependency file as used by kbuild to track dependencies */
33 int file_write_dep(const char *name)
35 struct symbol *sym, *env_sym;
42 out = fopen("..config.tmp", "w");
45 fprintf(out, "deps_config := \\\n");
46 for (file = file_list; file; file = file->next) {
48 fprintf(out, "\t%s \\\n", file->name);
50 fprintf(out, "\t%s\n", file->name);
52 fprintf(out, "\n%s: \\\n"
53 "\t$(deps_config)\n\n", conf_get_autoconfig_name());
55 expr_list_for_each_sym(sym_env_list, e, sym) {
56 struct property *prop;
59 prop = sym_get_env_prop(sym);
60 env_sym = prop_get_symbol(prop);
63 value = getenv(env_sym->name);
66 fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value);
67 fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name());
68 fprintf(out, "endif\n");
71 fprintf(out, "\n$(deps_config): ;\n");
73 rename("..config.tmp", name);
78 /* Allocate initial growable string */
79 struct gstr str_new(void)
82 gs.s = malloc(sizeof(char) * 64);
89 /* Allocate and assign growable string */
90 struct gstr str_assign(const char *s)
94 gs.len = strlen(s) + 1;
99 /* Free storage for growable string */
100 void str_free(struct gstr *gs)
108 /* Append to growable string */
109 void str_append(struct gstr *gs, const char *s)
113 l = strlen(gs->s) + strlen(s) + 1;
115 gs->s = realloc(gs->s, l);
122 /* Append printf formatted string to growable string */
123 void str_printf(struct gstr *gs, const char *fmt, ...)
126 char s[10000]; /* big enough... */
128 vsnprintf(s, sizeof(s), fmt, ap);
133 /* Retrieve value of growable string */
134 const char *str_get(struct gstr *gs)