teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame rpm-4.4.2-devel-autodep.patch

Jeremy Katz b914fc
--- rpm-4.4.2/build/rpmfc.c	2006-04-27 21:35:41.000000000 -0400
Jeremy Katz b914fc
+++ rpm/build/rpmfc.c	2006-04-27 21:33:48.000000000 -0400
Jeremy Katz b914fc
@@ -492,7 +492,7 @@
Jeremy Katz b914fc
   { "ASCII text",		RPMFC_WHITE|RPMFC_INCLUDE },
Jeremy Katz b914fc
   { "ISO-8859 text",		RPMFC_WHITE|RPMFC_INCLUDE },
Jeremy Katz b914fc
 
Jeremy Katz b914fc
-  { "symbolic link to",		RPMFC_SYMLINK },
Jeremy Katz b914fc
+  { "symbolic link to",		RPMFC_SYMLINK|RPMFC_INCLUDE },
Jeremy Katz b914fc
   { "socket",			RPMFC_DEVICE },
Jeremy Katz b914fc
   { "special",			RPMFC_DEVICE },
Jeremy Katz b914fc
 
Jeremy Katz b914fc
@@ -642,6 +642,103 @@
Jeremy Katz b914fc
 }
Jeremy Katz b914fc
 
Jeremy Katz b914fc
 /**
Jeremy Katz b914fc
+ * Ensure that symlinks for shared libs generate a dep on the shared lib
Jeremy Katz b914fc
+ * @param fc            file classifier
Jeremy Katz b914fc
+ * @return              0 on success
Jeremy Katz b914fc
+ */
Jeremy Katz b914fc
+static int rpmfcSYMLINK(rpmfc fc)
Jeremy Katz b914fc
+{
Jeremy Katz b914fc
+    const char * fn = fc->fn[fc->ix];
Jeremy Katz b914fc
+    struct stat sb;
Jeremy Katz b914fc
+    int fdno;
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+    if (stat(fn, &sb) < 0)
Jeremy Katz b914fc
+	return -1;
Jeremy Katz b914fc
+    if (S_ISLNK(sb.st_mode))
Jeremy Katz b914fc
+        return -1;
Jeremy Katz b914fc
+    
Jeremy Katz b914fc
+    fdno = open(fn, O_RDONLY);
Jeremy Katz b914fc
+    if (fdno < 0) {
Jeremy Katz b914fc
+	return fdno;
Jeremy Katz b914fc
+    }
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+#if HAVE_GELF_H && HAVE_LIBELF
Jeremy Katz b914fc
+    Elf * elf = NULL;
Jeremy Katz b914fc
+    GElf_Ehdr ehdr_mem, * ehdr;
Jeremy Katz b914fc
+    int isElf64;
Jeremy Katz b914fc
+    int i, cnt;
Jeremy Katz b914fc
+    char * soname = NULL;
Jeremy Katz b914fc
+    char buf[BUFSIZ];
Jeremy Katz b914fc
+    char * t;
Jeremy Katz b914fc
+    rpmds ds;
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+    (void) elf_version(EV_CURRENT);
Jeremy Katz b914fc
+    elf = NULL;
Jeremy Katz b914fc
+    if ((elf = elf_begin (fdno, ELF_C_READ_MMAP, NULL)) == NULL
Jeremy Katz b914fc
+        || elf_kind(elf) != ELF_K_ELF
Jeremy Katz b914fc
+        || (ehdr = gelf_getehdr(elf, &ehdr_mem)) == NULL
Jeremy Katz b914fc
+        || ehdr->e_type != ET_DYN)
Jeremy Katz b914fc
+	goto exit;
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+    isElf64 = ehdr->e_ident[EI_CLASS] == ELFCLASS64;
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+    for (i = 0; i < ehdr->e_phnum; ++i) {
Jeremy Katz b914fc
+      GElf_Phdr phdr_mem;
Jeremy Katz b914fc
+      GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
Jeremy Katz b914fc
+      GElf_Shdr shdr_mem;
Jeremy Katz b914fc
+      Elf_Data * data = NULL;
Jeremy Katz b914fc
+      Elf_Scn * scn;
Jeremy Katz b914fc
+      GElf_Shdr *shdr;
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+      if (phdr == NULL || phdr->p_type != PT_DYNAMIC)
Jeremy Katz b914fc
+          continue;
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+      scn = gelf_offscn(elf, phdr->p_offset);
Jeremy Katz b914fc
+      shdr = gelf_getshdr(scn, &shdr_mem);
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+      if (shdr != NULL && shdr->sh_type == SHT_DYNAMIC)
Jeremy Katz b914fc
+          data = elf_getdata (scn, NULL);
Jeremy Katz b914fc
+      if (data == NULL)
Jeremy Katz b914fc
+          continue; 
Jeremy Katz b914fc
+          
Jeremy Katz b914fc
+      for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) {
Jeremy Katz b914fc
+          GElf_Dyn dynmem;
Jeremy Katz b914fc
+          GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dynmem);
Jeremy Katz b914fc
+          if (dyn == NULL)
Jeremy Katz b914fc
+              break;
Jeremy Katz b914fc
+          if (dyn->d_tag != DT_SONAME)
Jeremy Katz b914fc
+              continue;
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+          /* add the soname to package deps */
Jeremy Katz b914fc
+          soname = elf_strptr(elf, shdr->sh_link, dyn->d_un.d_val);
Jeremy Katz b914fc
+          if (soname == NULL)
Jeremy Katz b914fc
+              break;
Jeremy Katz b914fc
+          buf[0] = '\0';
Jeremy Katz b914fc
+          t = buf;
Jeremy Katz b914fc
+          t = stpcpy(t, soname);
Jeremy Katz b914fc
+#if !defined(__alpha__)
Jeremy Katz b914fc
+          if (isElf64)
Jeremy Katz b914fc
+              t = stpcpy(t, "()(64bit)");
Jeremy Katz b914fc
+#endif
Jeremy Katz b914fc
+          t++;
Jeremy Katz b914fc
+          /* Add to package dependencies. */
Jeremy Katz b914fc
+          ds = rpmdsSingle(RPMTAG_REQUIRENAME,
Jeremy Katz b914fc
+                           buf, "", RPMSENSE_FIND_REQUIRES);
Jeremy Katz b914fc
+          rpmdsMerge(&fc->requires, ds);
Jeremy Katz b914fc
+          rpmfcSaveArg(&fc->ddict, rpmfcFileDep(t, fc->ix, ds));
Jeremy Katz b914fc
+          ds = rpmdsFree(ds);
Jeremy Katz b914fc
+          break;
Jeremy Katz b914fc
+      }
Jeremy Katz b914fc
+    }
Jeremy Katz b914fc
+exit:
Jeremy Katz b914fc
+    if (elf) (void) elf_end(elf);
Jeremy Katz b914fc
+    close(fdno);
Jeremy Katz b914fc
+    return 0;
Jeremy Katz b914fc
+#endif
Jeremy Katz b914fc
+    return -1;
Jeremy Katz b914fc
+}
Jeremy Katz b914fc
+
Jeremy Katz b914fc
+/**
Jeremy Katz b914fc
  * Extract script dependencies.
Jeremy Katz b914fc
  * @param fc		file classifier
Jeremy Katz b914fc
  * @return		0 on success
Jeremy Katz b914fc
@@ -1069,6 +1166,7 @@
Jeremy Katz b914fc
     { rpmfcSCRIPT,	(RPMFC_SCRIPT|RPMFC_PERL) },
Jeremy Katz b914fc
     { rpmfcSCRIPT,	(RPMFC_SCRIPT|RPMFC_PYTHON) },
Jeremy Katz b914fc
     { rpmfcSCRIPT,      RPMFC_MONO },
Jeremy Katz b914fc
+    { rpmfcSYMLINK,     RPMFC_SYMLINK },
Jeremy Katz b914fc
     { NULL, 0 }
Jeremy Katz b914fc
 };
Jeremy Katz b914fc