Wednesday, December 22, 2021

Re: new graphics/qr-code-generator 1.7.0

Klemens Nanni <kn@openbsd.org> writes:

> Another port that I currently build as bundle of telegram desktop.
> I figured it would be useful to other ports and a dedicated port always
> gives us more control.
>
> Information for inst:qr-code-generator-1.7.0
>
> Comment:
> QR Code generator library
>
> Description:
> High-quality QR Code generator library in Java, TypeScript/JavaScript,
> Python, Rust, C++, C.
>
> This project aims to be the best, clearest QR Code generator library in
> multiple languages. The primary goals are flexible options and absolute
> correctness. Secondary goals are compact implementation size and good
> documentation comments.
>
> This package only contains libraries for C++ and C.
>
> Maintainer: Klemens Nanni <kn@openbsd.org>
>
> WWW: https://www.nayuki.io/page/qr-code-generator-library
>
>
> Upstream has poor Makefiles, so I leveraged our bsd.{subdir,lib}.mk
> which works great.
>
> Builds fine on amd64, arm64, sparc64.
>
> One thing seems off which I spotted by building on a pre clang 13 amd64
> snapshot, here is the "fix" inlined from Makefile:
>
>
> # XXX on an amd64 snapshot with base-clang 11.1.0:
> # - base-clang builds without this
> # - ports-gcc needs this
> # on an amd64 snapshot with base-clang 13.0.0:
> # - base-clang needs this
> # - ports-gcc needs this
> #
> # qrcodegen.cpp:24:10: fatal error: 'algorithm' file not found
> # include <algorithm>
> CPPFLAGS += -I/usr/include/c++/v1
>
>
> Feedback? OK?

WANTLIB is missing.

I think it'd be easier to just roll our own do-build and do-install
instead of trying to hook bsd.lib.mk in. Bonus points: we don't need
the CPPFLAGS hack. Also, we could enable the tests since we're here:

% make test
===> Regression tests for qr-code-generator-1.7.0
cd /home/ports/pobj/qr-code-generator-1.7.0/QR-Code-generator-1.7.0/c && cc -DQRCODEGEN_TEST qrcodegen{,-test}.c -o test && ./test
All 521 test cases passed

What do you think?

--- Makefile.orig Wed Dec 22 17:00:19 2021
+++ Makefile Wed Dec 22 17:31:21 2021
@@ -12,61 +12,43 @@
# MIT
PERMIT_PACKAGE = Yes

+WANTLIB += ${COMPILER_LIBCXX} m
+
MAINTAINER = Klemens Nanni <kn@openbsd.org>

-# C++
COMPILER = base-clang ports-gcc

-# upstream supports c cpp java python rust typescript-javascript
-LANGS = c cpp
-
MAKE_ENV += CPPFLAGS='${CPPFLAGS}' \
CXXFLAGS='${CXXFLAGS}'

-# upstream provides no shared library versions for any language;
-# maintain one version and keep all libraries in sync
-LIBVER = 0.0
-MAKE_FLAGS += SHLIB_MAJOR=${LIBVER:R} \
- SHLIB_MINOR=${LIBVER:E}
-.for _lang in ${LANGS}
-_LIB${_lang} = qrcodegen${_lang:c=}
-SHARED_LIBS += ${_LIB${_lang}} ${LIBVER}
-.endfor
-# just shared libraries
-MAKE_FLAGS += -DNOLIBSTATIC \
- -DNOPROFILE
+SHARED_LIBS += qrcodegen 0.0
+SHARED_LIBS += qrcodegencpp 0.0

-FAKE_FLAGS = LIBDIR=/usr/local/lib
+CFLAGS += -shared
+CXXFLAGS += -shared -fPIC

-# XXX on an amd64 snapshot with base-clang 11.1.0:
-# - base-clang builds without this
-# - ports-gcc needs this
-# on an amd64 snapshot with base-clang 13.0.0:
-# - base-clang needs this
-# - ports-gcc needs this
-#
-# qrcodegen.cpp:24:10: fatal error: 'algorithm' file not found
-# include <algorithm>
-CPPFLAGS += -I/usr/include/c++/v1
+do-build:
+ cd ${WRKSRC}/c && \
+ ${CC} ${CFLAGS} qrcodegen.c -o \
+ libqrcodegen.so.${LIBqrcodegen_VERSION}
+ cd ${WRKSRC}/cpp && \
+ ${CXX} ${CXXFLAGS} qrcodegen.cpp -o \
+ libqrcodegencpp.so.${LIBqrcodegencpp_VERSION}

-INC_DIR = ${PREFIX}/include
-DOC_DIR = ${PREFIX}/share/doc/qr-code-generator
-
-post-patch:
- echo 'SUBDIR = ${LANGS}' >| ${WRKSRC}/${MAKE_FILE}
- echo '.include <bsd.subdir.mk>' >> ${WRKSRC}/${MAKE_FILE}
-.for _lang in ${LANGS}
- echo 'LIB = ${_LIB${_lang}}' >| ${WRKSRC}/${_lang}/Makefile
- echo 'SRCS = qrcodegen.${_lang}' >> ${WRKSRC}/${_lang}/Makefile
- echo '.include <bsd.lib.mk>' >> ${WRKSRC}/${_lang}/Makefile
-.endfor
-
-post-install:
-.for _lang in ${LANGS}
- ${INSTALL_DATA_DIR} ${INC_DIR}
- ${INSTALL_DATA} ${WRKSRC}/${_lang}/qrcodegen.${_lang:S/c/h/} ${INC_DIR}/
-.endfor
- ${INSTALL_DATA_DIR} ${DOC_DIR}
- ${INSTALL_DATA} ${WRKSRC}/Readme.markdown ${DOC_DIR}/
+do-install:
+ ${INSTALL_DATA_DIR} ${PREFIX}/lib
+ ${INSTALL_DATA_DIR} ${PREFIX}/include
+ ${INSTALL_DATA} ${WRKSRC}/c/*.so* ${PREFIX}/lib
+ ${INSTALL_DATA} ${WRKSRC}/c/*.h ${PREFIX}/include
+ ${INSTALL_DATA} ${WRKSRC}/cpp/*.so* ${PREFIX}/lib
+ ${INSTALL_DATA} ${WRKSRC}/cpp/*.hpp ${PREFIX}/include
+ ${INSTALL_DATA_DIR} ${PREFIX}/share/doc/qr-code-generator
+ ${INSTALL_DATA} ${WRKSRC}/Readme.markdown \
+ ${PREFIX}/share/doc/qr-code-generator
+
+do-test:
+ cd ${WRKSRC}/c && \
+ ${CC} -DQRCODEGEN_TEST qrcodegen{,-test}.c -o test && \
+ ./test

.include <bsd.port.mk>

No comments:

Post a Comment