write a dependency file as used by kbuild to track dependencies */
| 1057 | |
| 1058 | /* write a dependency file as used by kbuild to track dependencies */ |
| 1059 | static int conf_write_autoconf_cmd(const char *autoconf_name) |
| 1060 | { |
| 1061 | char name[PATH_MAX], tmp[PATH_MAX]; |
| 1062 | struct file *file; |
| 1063 | FILE *out; |
| 1064 | int ret; |
| 1065 | |
| 1066 | ret = snprintf(name, sizeof(name), "%s.cmd", autoconf_name); |
| 1067 | if (ret >= sizeof(name)) /* check truncation */ |
| 1068 | return -1; |
| 1069 | |
| 1070 | if (make_parent_dir(name)) |
| 1071 | return -1; |
| 1072 | |
| 1073 | ret = snprintf(tmp, sizeof(tmp), "%s.cmd.tmp", autoconf_name); |
| 1074 | if (ret >= sizeof(tmp)) /* check truncation */ |
| 1075 | return -1; |
| 1076 | |
| 1077 | out = fopen(tmp, "w"); |
| 1078 | if (!out) { |
| 1079 | perror("fopen"); |
| 1080 | return -1; |
| 1081 | } |
| 1082 | |
| 1083 | fprintf(out, "deps_config := \\\n"); |
| 1084 | for (file = file_list; file; file = file->next) |
| 1085 | fprintf(out, "\t%s \\\n", file->name); |
| 1086 | |
| 1087 | fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name); |
| 1088 | |
| 1089 | env_write_dep(out, autoconf_name); |
| 1090 | |
| 1091 | fprintf(out, "\n$(deps_config): ;\n"); |
| 1092 | |
| 1093 | fflush(out); |
| 1094 | ret = ferror(out); /* error check for all fprintf() calls */ |
| 1095 | fclose(out); |
| 1096 | if (ret) |
| 1097 | return -1; |
| 1098 | |
| 1099 | if (rename(tmp, name)) { |
| 1100 | perror("rename"); |
| 1101 | return -1; |
| 1102 | } |
| 1103 | |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | static int conf_touch_deps(void) |
| 1108 | { |
no test coverage detected