distromatic/src/buildtools.c

130 lines
4.5 KiB
C

/*
* distromatic - tool for RPM based repositories
*
* Copyright (C) 2004-2020 by Silvan Calarco <silvan.calarco@mambasoft.it>
* Copyright (C) 2006 by Davide Madrisan <davide.madrisan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of version 2 of the GNU General Public License as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY, to the extent permitted by law; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#if HAVE_STRING_H
# if !STDC_HEADERS && HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
#endif
#if HAVE_STRINGS_H
# include <strings.h>
#endif
#include <linux/limits.h>
#include "distromatic.h"
#include "buildtools.h"
int
generateBuildInfo(struct configTag *configtag, int arch)
{
char foutname[PATH_MAX], fsourcesname[PATH_MAX], fdir[PATH_MAX];
FILE *fout, *fsources;
int i, j;
struct headerSourceList *currheadersourcelist;
struct headerList *currchild;
snprintf(fdir, sizeof(fdir), "%s", configtag->repository_source_dir);
strncpy(fsourcesname, fdir, sizeof(fsourcesname));
strncat(fsourcesname, "buildinfo/sources.dat", sizeof(fsourcesname) - strlen(fsourcesname));
if ((fsources = fopen(fsourcesname, "w")) == NULL) {
perror(fsourcesname);
return 1;
}
currheadersourcelist = configtag->headersourcelist;
while (currheadersourcelist) {
strncpy(foutname, fdir, sizeof(foutname));
strncat(foutname, "buildinfo/", sizeof(foutname) - strlen(foutname));
strncat(foutname, currheadersourcelist->name, sizeof(foutname) - strlen(foutname));
strncat(foutname, ".info", sizeof(foutname) - strlen(foutname));
if ((fout = fopen(foutname, "w")) == NULL) {
perror(foutname);
return 1;
}
fprintf(fout, "SRPM_NAME=%s\n", currheadersourcelist->name);
fprintf(fout, "SRPM_FILENAME=%s-%s-%s.src.rpm\n",
currheadersourcelist->name,
currheadersourcelist->version,
currheadersourcelist->release);
fprintf(fout, "SRPM_VERSION=%s\n",
currheadersourcelist->version);
fprintf(fout, "SRPM_RELEASE=%s\n",
currheadersourcelist->release);
fprintf(fout, "SRPM_URL=%s\n", currheadersourcelist->url);
/* if (currheadersourcelist->url) {
* fprintf(fout,"SRPM_URL=%s\n",currheadersourcelist->url); */
i = 0;
while (currheadersourcelist->source
&& currheadersourcelist->source[i]) {
i++;
}
j = i;
for (i = i - 1; i >= 0; i--) {
fprintf(fout, "SRPM_SOURCE[%d]=%s\n", j - i - 1,
currheadersourcelist->source[i]);
fprintf(fsources, "%s %s %s\n", currheadersourcelist->name,
currheadersourcelist->version,
currheadersourcelist->source[i]);
}
i = 0;
while (currheadersourcelist->patch
&& currheadersourcelist->patch[i]) {
fprintf(fout, "SRPM_PATCH[%d]=%s\n", i,
currheadersourcelist->patch[i]);
i++;
}
currchild = currheadersourcelist->firstchild[arch];
i = 0;
while (currchild) {
fprintf(fout, "SRPM_TARGET[%d]=%s\n", i, currchild->name);
currchild = currchild->nextbrother;
i++;
}
/* list filenames */
for (i = 0; i < currheadersourcelist->filenamecount; i++) {
j = strlen((currheadersourcelist->basename)[i]) - 5;
if (j > 0
&& !strcmp(&((currheadersourcelist->basename)[i])[j],
".spec")) {
fprintf(fout, "SRPM_SPECFILE=%s\n",
(currheadersourcelist->basename)[i]);
break;
}
}
fclose(fout);
currheadersourcelist = currheadersourcelist->next;
}
fclose(fsources);
return 0;
}