Friday, August 04, 2023

Re: NEW: misc/libcpucycles

commit c9829ec24d37a8e2f143174504965c7dd2b0ac7e
Author: Miguel Landaeta <miguel@miguel.cc>
Date: Fri Aug 4 21:39:13 2023 +0100

Add misc/libcpucycles

diff --git a/misc/libcpucycles/Makefile b/misc/libcpucycles/Makefile
new file mode 100644
index 00000000000..d4106f0a574
--- /dev/null
+++ b/misc/libcpucycles/Makefile
@@ -0,0 +1,27 @@
+COMMENT= library for counting CPU cycles
+
+V= 20230115
+DISTNAME= libcpucycles-${V}
+SHARED_LIBS+= cpucycles 0.0 # 1.0
+CATEGORIES= misc
+HOMEPAGE= https://cpucycles.cr.yp.to/
+MASTER_SITES= ${HOMEPAGE}
+
+MAINTAINER= Miguel Landaeta <miguel@miguel.cc>
+
+# Public-domain
+PERMIT_PACKAGE= Yes
+
+WANTLIB+= c m
+MODULES+= lang/python
+MODPY_RUNDEP= No
+MODPY_PYTEST= No
+
+CONFIGURE_STYLE= simple
+CONFIGURE_ARGS+= --prefix="${WRKINST}${PREFIX}" \
+ --host="${MACHINE_ARCH}" \
+ --soversion="${LIBcpucycles_VERSION}"
+ALL_TARGET=
+MAKE_FLAGS+= LIBcpucycles_VERSION=${LIBcpucycles_VERSION}
+
+.include <bsd.port.mk>
diff --git a/misc/libcpucycles/distinfo b/misc/libcpucycles/distinfo
new file mode 100644
index 00000000000..6f2ee7574ef
--- /dev/null
+++ b/misc/libcpucycles/distinfo
@@ -0,0 +1,2 @@
+SHA256 (libcpucycles-20230115.tar.gz) = 3TjBIgVVAha5Jgfw9CcnxSoBCaFq8uqnoTg11T67wiU=
+SIZE (libcpucycles-20230115.tar.gz) = 34852
diff --git a/misc/libcpucycles/patches/patch-configure_fix_soname b/misc/libcpucycles/patches/patch-configure_fix_soname
new file mode 100644
index 00000000000..d6424a812ac
--- /dev/null
+++ b/misc/libcpucycles/patches/patch-configure_fix_soname
@@ -0,0 +1,78 @@
+Fix library soname.
+Index: configure
+--- configure.orig
++++ configure
+@@ -10,6 +10,7 @@
+ prefix = '/usr/local'
+ clean = True
+ linktype = 'so'
++soversion = '0.0'
+
+ host = platform.machine()
+ host = ''.join(c for c in host if c in '_0123456789abcdefghijklmnopqrstuvwxyz')
+@@ -43,6 +44,9 @@
+ host = arg[7:]
+ host = host.split('-')[0]
+ continue
++ if arg.startswith('--soversion='):
++ soversion = arg[12:]
++ continue
+ if arg == '--clean':
+ clean = True
+ continue
+@@ -54,6 +58,7 @@
+ echoargs = './configure'
+ echoargs += ' --prefix=%s' % prefix
+ echoargs += ' --host=%s' % host
++echoargs += ' --soversion=%s' % soversion
+ if clean: echoargs += ' --clean'
+ if not clean: echoargs += ' --noclean'
+ print(echoargs)
+@@ -222,23 +227,17 @@
+ f.write('%s -shared \\\n' % firstcompiler)
+ if rpath:
+ f.write(' -Wl,-rpath=%s \\\n' % rpath)
+- f.write(' -Wl,-soname,libcpucycles.so.1 \\\n')
+- f.write(' -o package/lib/libcpucycles.so.1 \\\n')
++ f.write(' -Wl,-soname,libcpucycles.so.%s \\\n' % soversion)
++ f.write(' -o package/lib/libcpucycles.so.%s \\\n' % soversion)
+ f.write(' "$@"\n')
+- f.write('chmod 644 package/lib/libcpucycles.so.1\n')
++ f.write('chmod 644 package/lib/libcpucycles.so.%s\n' % soversion)
+ os.chmod('build/%s/scripts/sharedlib' % host,0o755)
+
+-M = 'package/lib/libcpucycles.so.1: scripts/sharedlib %s\n' % ' '.join(cpucyclesofiles)
++M = 'package/lib/libcpucycles.so.$(LIBcpucycles_VERSION): scripts/sharedlib %s\n' % ' '.join(cpucyclesofiles)
+ M += '\tscripts/sharedlib %s\n' % ' '.join(cpucyclesofiles)
+ M += '\n'
+ makefile = M + makefile
+
+-M = 'package/lib/libcpucycles.so: package/lib/libcpucycles.so.1\n'
+-M += '\trm -f package/lib/libcpucycles.so\n'
+-M += '\tln -s libcpucycles.so.1 package/lib/libcpucycles.so\n'
+-M += '\n'
+-makefile = M + makefile
+-
+ # ----- command
+
+ os.makedirs('build/%s/command'%host)
+@@ -267,8 +266,8 @@
+ M += '\tscripts/compiledefault command %s c -I include\n' % base
+ M += '\n'
+ makefile = M + makefile
+- M = 'package/bin/%s: command/%s.o%s\n' % (base,base,''.join(' package/lib/%s.%s' % (x,linktype) for x in libs))
+- M += '\tcd command && ./link bin/%s %s.o%s -lm -lrt\n' % (base,base,''.join(' lib/%s.%s' % (x,linktype) for x in libs))
++ M = 'package/bin/%s: command/%s.o%s.$(LIBcpucycles_VERSION)\n' % (base,base,''.join(' package/lib/%s.%s' % (x,linktype) for x in libs))
++ M += '\tcd command && ./link bin/%s %s.o%s.$(LIBcpucycles_VERSION) -lm -lrt\n' % (base,base,''.join(' lib/%s.%s' % (x,linktype) for x in libs))
+ M += '\n'
+ makefile = M + makefile
+ commands += ['package/bin/%s' % base]
+@@ -286,7 +285,7 @@
+
+ # ----- make default
+
+-M = 'default: package/lib/libcpucycles.a package/lib/libcpucycles.so package/lib/libcpucycles.so.1 \\\n'
++M = 'default: package/lib/libcpucycles.a package/lib/libcpucycles.so.$(LIBcpucycles_VERSION) \\\n'
+ M += 'commands\n'
+ M += '\n'
+ makefile = M + makefile
diff --git a/misc/libcpucycles/patches/patch-configure_remove_librt b/misc/libcpucycles/patches/patch-configure_remove_librt
new file mode 100644
index 00000000000..16589772bee
--- /dev/null
+++ b/misc/libcpucycles/patches/patch-configure_remove_librt
@@ -0,0 +1,13 @@
+OpenBSD neither provides nor requires librt.
+Index: configure
+--- configure.orig
++++ configure
+@@ -267,7 +267,7 @@
+ M += '\n'
+ makefile = M + makefile
+ M = 'package/bin/%s: command/%s.o%s.$(LIBcpucycles_VERSION)\n' % (base,base,''.join(' package/lib/%s.%s' % (x,linktype) for x in libs))
+- M += '\tcd command && ./link bin/%s %s.o%s.$(LIBcpucycles_VERSION) -lm -lrt\n' % (base,base,''.join(' lib/%s.%s' % (x,linktype) for x in libs))
++ M += '\tcd command && ./link bin/%s %s.o%s.$(LIBcpucycles_VERSION) -lm\n' % (base,base,''.join(' lib/%s.%s' % (x,linktype) for x in libs))
+ M += '\n'
+ makefile = M + makefile
+ commands += ['package/bin/%s' % base]
diff --git a/misc/libcpucycles/patches/patch-configure_translate_host_arch b/misc/libcpucycles/patches/patch-configure_translate_host_arch
new file mode 100644
index 00000000000..a9454fcec31
--- /dev/null
+++ b/misc/libcpucycles/patches/patch-configure_translate_host_arch
@@ -0,0 +1,36 @@
+Translate OpenBSD architecture name to the name used by upstream.
+Index: configure
+--- configure.orig
++++ configure
+@@ -36,13 +36,30 @@
+
+ makefile = ''
+
++
++# Some OpenBSD architecture names don't match the
++# architecture name used by upstream, so they require to
++# be translated, so they can be recognized by build scripts.
++#
++def translate_arch(openbsd_arch):
++ archs = {
++ 'arm': 'arm32',
++ 'armv7': 'arm32',
++ 'i386': 'x86',
++ 'powerpc64': 'ppc64',
++ 'macppc': 'ppc32',
++ 'powerpc': 'ppc32',
++ }
++ return archs.get(openbsd_arch, openbsd_arch)
++
++
+ for arg in sys.argv[1:]:
+ if arg.startswith('--prefix='):
+ prefix = arg[9:]
+ continue
+ if arg.startswith('--host='):
+ host = arg[7:]
+- host = host.split('-')[0]
++ host = translate_arch(host.split('-')[0])
+ continue
+ if arg.startswith('--soversion='):
+ soversion = arg[12:]
diff --git a/misc/libcpucycles/pkg/DESCR b/misc/libcpucycles/pkg/DESCR
new file mode 100644
index 00000000000..163c73252bb
--- /dev/null
+++ b/misc/libcpucycles/pkg/DESCR
@@ -0,0 +1,6 @@
+libcpucycles provides a simple API to access hardware precise timers
+to understand and improve software performance.
+
+libcpucycles understands machine-level cycle counters for most architectures.
+libcpucycles also understands common OS-level mechanisms, which give varying
+levels of accuracy.
diff --git a/misc/libcpucycles/pkg/PLIST b/misc/libcpucycles/pkg/PLIST
new file mode 100644
index 00000000000..fd12f3cabd2
--- /dev/null
+++ b/misc/libcpucycles/pkg/PLIST
@@ -0,0 +1,5 @@
+@bin bin/cpucycles-info
+include/cpucycles.h
+@static-lib lib/libcpucycles.a
+@lib lib/libcpucycles.so.${LIBcpucycles_VERSION}
+@man man/man3/cpucycles.3
Thanks for the feedback.

I attached a fixed version of the port.

On Thu, Aug 3, 2023 at 11:04 PM Stuart Henderson <stu@spacehopper.org> wrote:
>
> Make sure that you can still produce a package if the 0.0 in
> SHARED_LIBRARIES is changed (you probably need to pass
> ${LIBcpucycles_VERSION} in to the build).

Got it. I was missing this in my first revision. I reworked one of the patches
and verified that I can update the library version if/when required.

> : MODULES+= lang/python
> : BUILD_DEPENDS= lang/python/${MODPY_DEFAULT_VERSION_3}
>
> BUILD_DEPENDS is automatically set by the python module, this isn't
> needed.

Fixed.

>
> > Description:
> > libcpucyples provides a simple API to access hardware precise timers
> typo ^
>

Silly typo, fixed.

> > +Small adjustments to make library manpage consistent
> > +Index: doc/man/cpucycles.3
>
> Unless necessary to make it work, I'd skip those.

Ack. It makes more sense to fix it upstream.


--
Miguel Landaeta, miguel at miguel.cc
secure email with PGP 0x6E608B637D8967E9 available at http://keyserver.pgp.com/
"Faith means not wanting to know what is true." -- Nietzsche

No comments:

Post a Comment