}
PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
- char makefiles[PATH_MAX];
- glob_t buffer;
+ struct pakfire_archive* archive = NULL;
+ struct pakfire_package* package = NULL;
+
+ char makefile[PATH_MAX];
int r;
- INFO(build->pakfire, "Building %s...\n", path);
+ // Open source archive
+ r = pakfire_archive_open(&archive, build->pakfire, path);
+ if (r) {
+ ERROR(build->pakfire, "Could not open source archive %s: %m\n", path);
+ goto ERROR;
+ }
+
+ // Fetch package metadata
+ r = pakfire_archive_make_package(archive, NULL, &package);
+ if (r) {
+ ERROR(build->pakfire, "Could not read package metadata: %m\n");
+ goto ERROR;
+ }
+
+ // Fetch some information
+ const char* nevra = pakfire_package_get_nevra(package);
+ const char* name = pakfire_package_get_name(package);
+
+ INFO(build->pakfire, "Building %s...\n", nevra);
// Setup build environment
r = pakfire_build_setup(build->pakfire);
if (r)
- return r;
+ goto ERROR;
const char* packages[] = {
path, NULL
NULL, NULL, NULL);
if (r) {
ERROR(build->pakfire, "Could not install %s\n", path);
- return r;
+ goto ERROR;
}
- // Where are the makefiles located?
- r = pakfire_make_path(build->pakfire, makefiles, "/usr/src/packages/*/*.nm");
- if (r < 0)
+ // Compose path to makefile
+ r = pakfire_string_format(makefile, "/usr/src/packages/%s/%s.nm", name, name);
+ if (r < 0) {
+ ERROR(build->pakfire, "Could not compose makefile path: %m\n");
goto ERROR;
+ }
- // Find all makefiles
- r = glob(makefiles, 0, NULL, &buffer);
+ // Run build
+ r = pakfire_build_makefile(build->pakfire, makefile, build->target,
+ &build->id, build->flags);
if (r) {
- ERROR(build->pakfire, "glob() on %s failed: %m\n", makefiles);
- globfree(&buffer);
+ ERROR(build->pakfire, "Could not build %s: %m\n", nevra);
goto ERROR;
}
- // Iterate over all makefiles
- for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
- r = pakfire_build_makefile(build->pakfire, buffer.gl_pathv[i], build->target,
- &build->id, build->flags);
- if (r) {
- ERROR(build->pakfire, "Could not build %s: %m\n", buffer.gl_pathv[i]);
- globfree(&buffer);
- goto ERROR;
- }
- }
-
ERROR:
+ if (archive)
+ pakfire_archive_unref(archive);
+ if (package)
+ pakfire_package_unref(package);
+
return r;
}