NetBSD Problem Report #50201

From www@NetBSD.org  Fri Sep  4 03:17:05 2015
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 2518AA6531
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  4 Sep 2015 03:17:05 +0000 (UTC)
Message-Id: <20150904031702.EC60EA6562@mollari.NetBSD.org>
Date: Fri,  4 Sep 2015 03:17:02 +0000 (UTC)
From: davshao@gmail.com
Reply-To: davshao@gmail.com
To: gnats-bugs@NetBSD.org
Subject: devel/libdevq port from FreeBSD / DragonFly
X-Send-Pr-Version: www-1.0

>Number:         50201
>Category:       pkg
>Synopsis:       devel/libdevq port from FreeBSD / DragonFly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 04 03:20:00 +0000 2015
>Originator:     David Shao
>Release:        pkgsrc current
>Organization:
>Environment:
DragonFly  4.3-DEVELOPMENT DragonFly v4.3.1.401.g3f4ec-DEVELOPMENT #2: Thu Sep  3 07:03:26 PDT 2015     xxxxxx@:/usr/obj/usr/src/sys/X86_64_GENERIC  x86_64

>Description:
devel/libdevq from FreeBSD ports / DragonFly dports could be the basis for some of the functionality of udev.  Right now it is used for one function in MesaLib.

The port for pkgsrc is complicated by my ignorance:  There is a pkg-config .pc file that unfortunately is not named directly after libdevq but has a version number, which isn't the real version number, in it.  I was having difficulty getting a piece of configure spliced into MesaLib's to find the .pc file, so finally I just patched libdevq to rename it to the standard name libdevq.pc.

Also libdevq's library is dlopened in MesaLib, so does that mean 
.include "../../mk/dlopen.buildlink3.mk"
should be in the buildlink3.mk?


>How-To-Repeat:

>Fix:
Makefile:

# $NetBSD$

DISTNAME=	libdevq-0.0.2
CATEGORIES=	devel
MASTER_SITES=	http://rainbow-runner.nl/freebsd/
EXTRACT_SUFX=	.tar.xz

MAINTAINER=	INSERT_YOUR_MAIL_ADDRESS_HERE
HOMEPAGE=	http://rainbow-runner.nl/freebsd/
COMMENT=	Generic Device Query and Monitor interface

LICENSE=	2-clause-bsd

GNU_CONFIGURE=	yes
USE_LIBTOOL=	yes
USE_TOOLS+=	gmake pkg-config

PKGCONFIG_OVERRIDE+=	src/libdevq.pc.in

PKG_OPTIONS_VAR=	PKG_OPTIONS.libdevq
PKG_SUPPORTED_OPTIONS=	diagnostic-bin	
PKG_SUGGESTED_OPTIONS+=	diagnostic-bin	

.include "../../mk/bsd.options.mk"

PLIST_VARS+=	diagnostic-bin

.if !empty(PKG_OPTIONS:Mdiagnostic-bin)
PLIST.libdevq=		yes
.endif

.include "../../mk/bsd.pkg.mk"

DESCR:

Generic Device Query and Monitor interface

WWW: https://github.com/freebsd/libdevq

PLIST:

@comment $NetBSD$
${PLIST.diagnostic-bin}bin/devq-evwatch
${PLIST.diagnostic-bin}bin/lsdri
include/libdevq.h
lib/libdevq.la
lib/pkgconfig/libdevq.pc

buildlink3.mk:

# $NetBSD: buildlink3.mk$

BUILDLINK_TREE+=	libdevq

.if !defined(LIBDEVQ_BUILDLINK3_MK)
LIBDEVQ_BUILDLINK3_MK:=

BUILDLINK_API_DEPENDS.libdevq+=	libdevq>=0.0.2
BUILDLINK_PKGSRCDIR.libdevq?=	../../devel/libdevq
.include "../../mk/dlopen.buildlink3.mk"
.endif # LIBDEVQ_BUILDLINK3_MK

BUILDLINK_TREE+=	-libdevq

distinfo:

$NetBSD$

SHA1 (libdevq-0.0.2.tar.xz) = a7a06d4cc3e8de2e8015fb3f78cd596ede6e87ca
RMD160 (libdevq-0.0.2.tar.xz) = df81ed6172c2f55035ff6804b67d9fea4ba5d5ee
Size (libdevq-0.0.2.tar.xz) = 210960 bytes
SHA1 (patch-Makefile.am) = 764e298d076d53290d30b80107e1a1625b7e6b18
SHA1 (patch-Makefile.in) = 049471b08f8df28faea7057c7408edbc01bf88f0
SHA1 (patch-configure) = b10969a381619e28b4a08fa5de5f60ac4411b048
SHA1 (patch-src_device.c) = cd545f3f1bdb5ab72a87c7d2defbb978b781082c
SHA1 (patch-src_libdevq.pc.in) = 9adb9aa98ec927a7a5728f6d8c2d3b394ab7f808

patches/patch-Makefile.am:

$NetBSD$

--- Makefile.am.orig	2015-08-12 04:46:06.219961000 +0000
+++ Makefile.am
@@ -22,4 +22,4 @@ devq_lsdri_CPPFLAGS = -I$(top_srcdir)/in
 devq_lsdri_LDADD = libdevq.la

 pkgconfigdir = $(libdir)/pkgconfig
-nodist_pkgconfig_DATA = src/libdevq-1.0.pc
+nodist_pkgconfig_DATA = src/libdevq.pc

patches/patch-Makefile.in

$NetBSD$

--- Makefile.in.orig	2015-08-12 04:46:58.299449000 +0000
+++ Makefile.in
@@ -87,7 +87,7 @@ target_triplet = @target@
 subdir = .
 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
 	$(top_srcdir)/configure $(am__configure_deps) \
-	$(top_srcdir)/src/libdevq-1.0.pc.in \
+	$(top_srcdir)/src/libdevq.pc.in \
 	$(top_srcdir)/ac-aux/depcomp $(include_HEADERS) AUTHORS \
 	COPYING README ac-aux/compile ac-aux/config.guess \
 	ac-aux/config.sub ac-aux/depcomp ac-aux/install-sh \
@@ -106,7 +106,7 @@ am__configure_deps = $(am__aclocal_m4_de
 am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
  configure.lineno config.status.lineno
 mkinstalldirs = $(install_sh) -d
-CONFIG_CLEAN_FILES = src/libdevq-1.0.pc
+CONFIG_CLEAN_FILES = src/libdevq.pc
 CONFIG_CLEAN_VPATH_FILES =
 am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
 am__vpath_adj = case $$p in \
@@ -373,7 +373,7 @@ devq_lsdri_SOURCES = tools/lsdri/lsdri.c
 devq_lsdri_CPPFLAGS = -I$(top_srcdir)/include
 devq_lsdri_LDADD = libdevq.la
 pkgconfigdir = $(libdir)/pkgconfig
-nodist_pkgconfig_DATA = src/libdevq-1.0.pc
+nodist_pkgconfig_DATA = src/libdevq.pc
 all: all-am

 .SUFFIXES:
@@ -412,7 +412,7 @@ $(top_srcdir)/configure:  $(am__configur
 $(ACLOCAL_M4):  $(am__aclocal_m4_deps)
 	$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
 $(am__aclocal_m4_deps):
-src/libdevq-1.0.pc: $(top_builddir)/config.status $(top_srcdir)/src/libdevq-1.0.pc.in
+src/libdevq.pc: $(top_builddir)/config.status $(top_srcdir)/src/libdevq.pc.in
 	cd $(top_builddir) && $(SHELL) ./config.status $@

 install-libLTLIBRARIES: $(lib_LTLIBRARIES)

patches/patch-configure:

$NetBSD$

--- configure.orig	2014-05-09 09:39:39.000000000 +0000
+++ configure
@@ -11725,7 +11725,7 @@ esac


 case $target_os in
-freebsd*) opsys=freebsd ;;
+dragonfly*|freebsd*) opsys=freebsd ;;
 *) opsys=$target_os ;;
 esac

@@ -11836,7 +11836,7 @@ fi

 # ----------------------------------------------------------------------------

-ac_config_files="$ac_config_files Makefile src/libdevq-1.0.pc"
+ac_config_files="$ac_config_files Makefile src/libdevq.pc"


 cat >confcache <<\_ACEOF
@@ -12864,7 +12866,7 @@ do
     "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
     "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
-    "src/libdevq-1.0.pc") CONFIG_FILES="$CONFIG_FILES src/libdevq-1.0.pc" ;;
+    "src/libdevq.pc") CONFIG_FILES="$CONFIG_FILES src/libdevq.pc" ;;

   *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
   esac

patches/patch-src_device.c

$NetBSD$

--- src/device.c.orig	2014-05-08 14:38:51.000000000 +0000
+++ src/device.c
@@ -187,6 +187,58 @@ out:
 #endif /* defined(HAVE_LIBPROCSTAT_H) */
 }

+static int
+devq_compare_vgapci_busaddr(int i, int *domain, int *bus, int *slot,
+    int *function)
+{
+	int ret;
+	char sysctl_name[32], sysctl_value[128];
+	size_t sysctl_value_len;
+
+	sprintf(sysctl_name, "dev.vgapci.%d.%%location", i);
+
+	sysctl_value_len = sizeof(sysctl_value);
+	memset(sysctl_value, 0, sysctl_value_len);
+	ret = sysctlbyname(sysctl_name, sysctl_value,
+	    &sysctl_value_len, NULL, 0);
+	if (ret != 0)
+		return (-1);
+
+	/*
+	 * dev.vgapci.$m.%location can have two formats:
+	 *     o  "pci0:2:0:0 handle=\_SB_.PCI0.PEG3.MXM3" (FreeBSD 11+)
+	 *     o  "slot=1 function=0" (up-to FreeBSD 10)
+	 */
+
+	ret = sscanf(sysctl_value, "pci%d:%d:%d:%d %*s",
+	    domain, bus, slot, function);
+	if (ret == 4)
+		return (0);
+
+	ret = sscanf(sysctl_value, "slot=%d function=%d %*s",
+	    slot, function);
+	if (ret != 2)
+		return (-1);
+
+	sprintf(sysctl_name, "dev.vgapci.%d.%%parent", i);
+
+	sysctl_value_len = sizeof(sysctl_value);
+	memset(sysctl_value, 0, sysctl_value_len);
+	ret = sysctlbyname(sysctl_name, sysctl_value,
+	    &sysctl_value_len, NULL, 0);
+	if (ret != 0)
+		return (-1);
+
+	ret = sscanf(sysctl_value, "pci%d", bus);
+	if (ret != 1)
+		return (-1);
+
+	/* FIXME: What domain to assume? */
+	*domain = 0;
+
+	return (0);
+}
+
 int
 devq_device_get_pciid_from_fd(int fd,
     int *vendor_id, int *device_id)
@@ -252,38 +304,17 @@ devq_device_get_pciid_from_fd(int fd,
 	 *     o  dev.vgapci.$m.%parent
 	 */
 	for (i = 0; i < DEVQ_MAX_DEVS; ++i) {
-		sprintf(sysctl_name, "dev.vgapci.%d.%%location", i);
-
-		sysctl_value_len = sizeof(sysctl_value);
-		memset(sysctl_value, 0, sysctl_value_len);
-		ret = sysctlbyname(sysctl_name, sysctl_value,
-		    &sysctl_value_len, NULL, 0);
-		if (ret != 0)
-			continue;
+		int tmp_domain, tmp_bus, tmp_slot, tmp_function;

-		int tmp_slot, tmp_function;
-		ret = sscanf(sysctl_value, "slot=%d function=%d %*s",
+		ret = devq_compare_vgapci_busaddr(i, &tmp_domain, &tmp_bus,
 		    &tmp_slot, &tmp_function);
-		if (ret != 2 ||
-		    tmp_slot != slot || tmp_function != function)
-			continue;
-
-		sprintf(sysctl_name, "dev.vgapci.%d.%%parent", i);
-
-		sysctl_value_len = sizeof(sysctl_value);
-		memset(sysctl_value, 0, sysctl_value_len);
-		ret = sysctlbyname(sysctl_name, sysctl_value,
-		    &sysctl_value_len, NULL, 0);
-		if (ret != 0)
-			continue;
-
-		int tmp_bus;
-		ret = sscanf(sysctl_value, "pci%d",
-		    &tmp_bus);
-		if (ret != 1 || tmp_bus != bus)
-			continue;

-		break;
+		if (ret == 0 &&
+		    tmp_domain == domain &&
+		    tmp_bus == bus &&
+		    tmp_slot == slot &&
+		    tmp_function == function)
+			break;
 	}

 	if (i == DEVQ_MAX_DEVS) {

patches/patch-src_libdevq.pc.in

$NetBSD$

--- src/libdevq.pc.in.orig	2015-08-12 04:48:57.548278000 +0000
+++ src/libdevq.pc.in
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+includedir=${prefix}/include
+libdir=${exec_prefix}/lib
+
+Name: @PACKAGE_NAME@
+Description: Generic device query and monitor interface
+Version: @PACKAGE_VERSION@
+Cflags: -I${includedir}
+Libs: -Wl,-R${libdir} -L${libdir} -ldevq

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.