[packages/rpm-getdeps] - port to rpm 4.16 - add Makefile - version 0.0.8

baggins baggins at pld-linux.org
Sat Oct 24 15:46:14 CEST 2020


commit df2ac7c1e2ef9f4954c0368ff272c0552fe66659
Author: Jan Rękorajski <baggins at pld-linux.org>
Date:   Sat Oct 24 15:45:49 2020 +0200

    - port to rpm 4.16
    - add Makefile
    - version 0.0.8

 Makefile         |  14 +++++++
 getdeps.c        | 110 +++++++++++++++++++++++++------------------------------
 rpm-getdeps.spec |  15 +++++---
 3 files changed, 73 insertions(+), 66 deletions(-)
---
diff --git a/rpm-getdeps.spec b/rpm-getdeps.spec
index c025b9f..d8565cd 100644
--- a/rpm-getdeps.spec
+++ b/rpm-getdeps.spec
@@ -1,13 +1,13 @@
 Summary:	Get dependencies out of RPM spec file
 Summary(pl):	Pobieranie zależności z pliku spec pakietu RPM
 Name:		rpm-getdeps
-Version:	0.0.7
-Release:	2
+Version:	0.0.8
+Release:	1
 License:	GPL
 Group:		Applications/System
 Source0:	getdeps.c
-# Source0-md5:	c20a7f6a0ef86461514fbf55092ae434
-BuildRequires:	rpm-devel
+Source1:	Makefile
+BuildRequires:	rpm-devel >= 1:4.16.0
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
 %description
@@ -18,9 +18,14 @@ Pobieranie zależności z pliku spec pakietu RPM.
 
 %prep
 %setup -q -c -T
+ln -s %{SOURCE0} .
+ln -s %{SOURCE1} .
 
 %build
-%{__cc} %{rpmcflags} %{rpmldflags} -I/usr/include/rpm -Wall -lrpm -lrpmbuild %{SOURCE0} -o rpm-getdeps
+%{__make} \
+	CC="%{__cc}" \
+	RPMLDFLAGS="%{rpmldflags}" \
+	RPMCFLAGS="%{rpmcflags}"
 
 %install
 rm -rf $RPM_BUILD_ROOT
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..cb34e24
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+RPM_FORMAT_VERSION := `pkg-config --modversion rpm | cut -d . -f 1`
+RPM_MAJOR_VERSION := `pkg-config --modversion rpm | cut -d . -f 2`
+RPM_MINOR_VERSION := `pkg-config --modversion rpm | cut -d . -f 3`
+
+CC := gcc
+CFLAGS := -Wall -Wno-unused-result -DRPM_FORMAT_VERSION=$(RPM_FORMAT_VERSION) -DRPM_MAJOR_VERSION=$(RPM_MAJOR_VERSION) -DRPM_MINOR_VERSION=$(RPM_MINOR_VERSION) $(RPMCFLAGS)
+LDFLAGS := $(RPMLDFLAGS)
+INCLUDES := `pkg-config --cflags rpm`
+LIBS := `pkg-config --libs rpm`
+rpm-getdeps: rpm-getdeps.o
+	$(CC) $(LDFLAGS) $< -o $@ $(LIBS)
+
+rpm-getdeps.o: getdeps.c
+	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
diff --git a/getdeps.c b/getdeps.c
index 571df0f..428d1ee 100644
--- a/getdeps.c
+++ b/getdeps.c
@@ -1,5 +1,3 @@
-// $Id$    --*- c -*--
-
 // Copyright (C) 2003 Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de>
 //  
 // This program is free software; you can redistribute it and/or modify
@@ -37,28 +35,21 @@
 // version 0.0.1, 2003-11-19
 //    * initial version
 
-
-#define _GNU_SOURCE
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
+#include <assert.h>
 #include <getopt.h>
+#include <grp.h>
+#include <libgen.h>
 #include <stdbool.h>
 #include <string.h>
-#include <assert.h>
-#include <unistd.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <unistd.h>
 
+#include <header.h>
 #include <rpmbuild.h>
 #include <rpmlib.h>
-#include <header.h>
-
-#ifndef RPM404
-#  include <rpmts.h>
-#endif
+#include <rpmlog.h>
+#include <rpmts.h>
 
 #define ARG_WITH	1024
 #define ARG_WITHOUT	1025
@@ -102,10 +93,10 @@ struct Arguments
 };
 
 struct DepSet {
-    int32_t const *	flags;
-    char const **	name;
-    char const **	version;
-    ssize_t		cnt;
+    rpmtd	flags;
+    rpmtd	name;
+    rpmtd	version;
+    ssize_t	cnt;
 };
 
 inline static void 
@@ -222,42 +213,55 @@ setMacros(char const * const *macros, size_t cnt)
 }
 
 static void
-printDepSet(struct DepSet const *set, char const *prefix)
+printDepSet(struct DepSet set, char const *prefix)
 {
   ssize_t	i;
-  for (i=0; i<set->cnt; ++i)
-    printf("%s%08x %s %s\n", prefix, set->flags[i], set->name[i], set->version[i]);
+  for (i=0; i<set.cnt; ++i) {
+    printf("%s%08x %s %s\n", prefix, (uint32_t)rpmtdGetNumber(set.flags), rpmtdGetString(set.name), rpmtdGetString(set.version));
+    rpmtdNext(set.flags);
+    rpmtdNext(set.name);
+    rpmtdNext(set.version);
+  }
 }
 
 static void
 evaluateHeader(Header h)
 {
-  int32_t		cnt[3];
-  struct DepSet		buildreqs = { 0,0,0,0 };
-  struct DepSet		conflicts = { 0,0,0,0 };
-
-  if (headerGetEntry(h, RPMTAG_REQUIREFLAGS,    0, (void**)&buildreqs.flags,   cnt+0) &&
-      headerGetEntry(h, RPMTAG_REQUIRENAME,     0, (void**)&buildreqs.name,    cnt+1) &&
-      headerGetEntry(h, RPMTAG_REQUIREVERSION,  0, (void**)&buildreqs.version, cnt+2)) {
-    assert(cnt[0]==cnt[1] && cnt[1]==cnt[2]);
-    buildreqs.cnt = cnt[0];
+  struct DepSet		buildreqs;
+  struct DepSet		conflicts;
+
+  buildreqs.flags = rpmtdNew();
+  buildreqs.name = rpmtdNew();
+  buildreqs.version = rpmtdNew();
+  buildreqs.cnt = 0;
+
+  if (headerGet(h, RPMTAG_REQUIREFLAGS,    buildreqs.flags,   0) &&
+      headerGet(h, RPMTAG_REQUIRENAME,     buildreqs.name,    0) &&
+      headerGet(h, RPMTAG_REQUIREVERSION,  buildreqs.version, 0)) {
+    assert(buildreqs.flags->count==buildreqs.name->count && buildreqs.name->count==buildreqs.version->count);
+    buildreqs.cnt = buildreqs.flags->count;
   }
 
-  if (headerGetEntry(h, RPMTAG_CONFLICTFLAGS,   0, (void**)&conflicts.flags,   cnt+0) &&
-      headerGetEntry(h, RPMTAG_CONFLICTNAME,    0, (void**)&conflicts.name,    cnt+1) &&
-      headerGetEntry(h, RPMTAG_CONFLICTVERSION, 0, (void**)&conflicts.version, cnt+2)) {
-    assert(cnt[0]==cnt[1] && cnt[1]==cnt[2]);
-    conflicts.cnt = cnt[0];
+  conflicts.flags = rpmtdNew();
+  conflicts.name = rpmtdNew();
+  conflicts.version = rpmtdNew();
+  conflicts.cnt = 0;
+
+  if (headerGet(h, RPMTAG_CONFLICTFLAGS,   conflicts.flags,   0) &&
+      headerGet(h, RPMTAG_CONFLICTNAME,    conflicts.name,    0) &&
+      headerGet(h, RPMTAG_CONFLICTVERSION, conflicts.version, 0)) {
+    assert(conflicts.flags->count==conflicts.name->count && conflicts.name->count==conflicts.version->count);
+    conflicts.cnt = conflicts.flags->count;
   }
 
-  printDepSet(&buildreqs, "+ ");
-  printDepSet(&conflicts, "- ");
+  printDepSet(buildreqs, "+ ");
+  printDepSet(conflicts, "- ");
 }
 
 int main(int argc, char *argv[])
 {
   struct Arguments	args = { 0,0,0,-1,-1, {0,0,0}, 0 };
-  Spec			s;
+  rpmSpec		s;
 
   parseArgs(&args, argc, argv);
 
@@ -268,28 +272,12 @@ int main(int argc, char *argv[])
     perror("chroot/setuid/setgid()");
     return EXIT_FAILURE;
   }
-  
-  rpmReadConfigFiles(args.rcfile, args.target);
-  setMacros(args.macros.values, args.macros.cnt);
 
+  rpmSetVerbosity(RPMLOG_ERR);
 
-#ifndef RPM404
-  rpmts			ts = rpmtsCreate();
-  if (parseSpec(ts, args.specfile, 0,0, 1, 0,0, 1,1)!=0) {
-    return EXIT_FAILURE;
-  }
-  
-  s = rpmtsSpec(ts);
-#else
-  if (parseSpec(&s, args.specfile, 0,0, 1, 0,0, 1,1)!=0) {
-    return EXIT_FAILURE;
-  }
-#endif
+  rpmReadConfigFiles(args.rcfile, args.target);
+  setMacros(args.macros.values, args.macros.cnt);
 
-  evaluateHeader(s->buildRestrictions);
+  s = rpmSpecParse(args.specfile, RPMSPEC_FORCE, NULL);
+  evaluateHeader(rpmSpecSourceHeader(s));
 }
-
-/// Local Variables:
-/// compile-command: "make getdeps LDFLAGS='-lrpm       -lrpmbuild'       CFLAGS='-I/usr/include/rpm       -Wall -W -pedantic --std=c99 -g3 -O0'"
-/// compile-commandX: "make getdeps LDFLAGS='-lrpm-4.0.4 -lrpmbuild-4.0.4 -lrpmio-4.0.4 -lrpmdb-4.0.4 -lpopt' CFLAGS='-I/usr/include/rpm-4.0.4 -Wall -W -pedantic --std=c99 -g3 -O0 -DRPM404'"
-/// End:
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/rpm-getdeps.git/commitdiff/df2ac7c1e2ef9f4954c0368ff272c0552fe66659



More information about the pld-cvs-commit mailing list