Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cnijfilter: add 3.80 #65469

Closed
wants to merge 1 commit into from
Closed

cnijfilter: add 3.80 #65469

wants to merge 1 commit into from

Conversation

terlar
Copy link
Contributor

@terlar terlar commented Jul 27, 2019

Motivation for this change

I have a IP7200 printer and cannot get it working well with the gutenprint drivers (borderless and duplex printing). I would like to give the proprietary drivers a go. This adds support for the following printers: MP430 MG2200 E510 MG3200 MG4200 MG5400 MG6300 and IP7200 series

The versioning of the cnijfilter is not in the way where more and more support is added, so therefore I cannot use the later or earlier versions. As support for previous printers is removed.

Things done

This PR is not fully ready yet, as I got stuck during the build process. But I open this PR here early in hopes that someone might have an idea. It is based on the cnijfilter_4_00 but there seems to be no bscc2sts in the source, but it is part of the dependencies, so not sure how to get that working, currently this is where it complains.

[UPDATE]: Working and tried with the printer IP7250.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@terlar
Copy link
Contributor Author

terlar commented Jul 27, 2019

Current build state nix-build -A cnijfilter_3_80:

...
make[1]: Entering directory '/build/source/cngpijmon/cnijnpr'
make  all-recursive
make[2]: Entering directory '/build/source/cngpijmon/cnijnpr'
Making all in cnijnpr
make[3]: Entering directory '/build/source/cngpijmon/cnijnpr/cnijnpr'
gcc -DHAVE_CONFIG_H -I. -I..     -O2 -MT cnijnpr.o -MD -MP -MF .deps/cnijnpr.Tpo -c -o cnijnpr.o cnijnpr.c
cnijnpr.c: In function 'main':
cnijnpr.c:146:9: warning: implicit declaration of function 'write'; did you mean 'fwrite'? [-Wimplicit-function-declaration]
  wrtn = write(fd, buf, STATUS_BUF);
         ^~~~~
         fwrite
cnijnpr.c:147:2: warning: implicit declaration of function 'sleep' [-Wimplicit-function-declaration]
  sleep(1);
  ^~~~~
cnijnpr.c:251:13: warning: implicit declaration of function 'read'; did you mean 'fread'? [-Wimplicit-function-declaration]
    r_size = read(fdusb, buf3, BUFSZ);
             ^~~~
             fread
cnijnpr.c:266:7: warning: implicit declaration of function 'usleep'; did you mean 'fseek'? [-Wimplicit-function-declaration]
       usleep(10000);
       ^~~~~~
       fseek
cnijnpr.c:309:5: warning: implicit declaration of function 'close'; did you mean 'pclose'? [-Wimplicit-function-declaration]
     close(fdusb);
     ^~~~~
     pclose
cnijnpr.c: In function 'get_printer_devid':
cnijnpr.c:587:12: warning: type of 'fdusb' defaults to 'int' [-Wimplicit-int]
 static int get_printer_devid(fdusb)
            ^~~~~~~~~~~~~~~~~
mv -f .deps/cnijnpr.Tpo .deps/cnijnpr.Po
gcc  -O2 -L../../../com/libs_bin64 -L../../../lgmon/src  -o cnijnpr cnijnpr.o -lcnnet -lbscc2sts -ldl
/nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/ld: cannot find -lbscc2sts
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:337: cnijnpr] Error 1
make[3]: Leaving directory '/build/source/cngpijmon/cnijnpr/cnijnpr'
make[2]: *** [Makefile:353: all-recursive] Error 1
make[2]: Leaving directory '/build/source/cngpijmon/cnijnpr'
make[1]: *** [Makefile:294: all] Error 2
make[1]: Leaving directory '/build/source/cngpijmon/cnijnpr'
make: *** [Makefile:9: all] Error 1
builder for '/nix/store/kcggy4crb85z0swdh288dh7cnv9sch3r-cnijfilter-3.80.drv' failed with exit code 2
error: build of '/nix/store/kcggy4crb85z0swdh288dh7cnv9sch3r-cnijfilter-3.80.drv' failed

@symphorien
Copy link
Member

bscc2sts seems to be in lgmon/src/bscc2sts.c

@symphorien
Copy link
Member

I went further with this patch:

diff --git a/pkgs/misc/cups/drivers/cnijfilter_3_80/default.nix b/pkgs/misc/cups/drivers/cnijfilter_3_80/default.nix
index 70a6bc0f130..e7c46b4705f 100644
--- a/pkgs/misc/cups/drivers/cnijfilter_3_80/default.nix
+++ b/pkgs/misc/cups/drivers/cnijfilter_3_80/default.nix
@@ -1,6 +1,6 @@
-{ stdenv, lib, fetchzip,
-  autoconf, automake, libtool,
-  cups, popt, libtiff, libpng,
+{ stdenv, lib, fetchzip, breakpointHook,
+  autoconf, automake, libtool, gtk2,
+  cups, popt, libtiff, libpng, pkg-config,
   ghostscript, glib, libusb, libxml2 }:
 
 /* this derivation is basically just a transcription of the rpm .spec
@@ -30,8 +30,8 @@ in stdenv.mkDerivation rec {
     sha256 = "03v4yn346xn4hk498lzz8ykdbhd4l8qna909fmr0qrkypyhd4627";
   };
 
-  buildInputs = [ autoconf libtool automake
-                  cups popt libtiff libpng
+  nativeBuildInputs = [ autoconf automake libtool pkg-config ];
+  buildInputs = [ cups popt libtiff libpng gtk2
                   ghostscript glib libusb libxml2 ];
 
   # patches from https://github.com/tokiclover/bar-overlay/tree/master/net-print/cnijfilter
@@ -69,12 +69,22 @@ in stdenv.mkDerivation rec {
     cd ../backendnet
     ./autogen.sh --prefix=$out --enable-libpath=$out/lib/bjlib --enable-progpath=$out/bin
 
+    cd ../lgmon
+    # no --prefix=$out because it builds a static library that the build system looks for in lgmon/src
+    ./autogen.sh
+
     cd ../cngpijmon/cnijnpr
     ./autogen.sh --prefix=$out --enable-libpath=$out/lib/bjlib
 
     cd ../..;
   '';
 
+  preBuild = ''
+    pushd lgmon
+    make
+    popd
+  '';
+
   preInstall = ''
     mkdir -p $out/bin $out/lib/cups/filter $out/share/cups/model;
   '';
       

@symphorien
Copy link
Member

This should fix the build: 076186a

Also a nitpick: please use fetchpatch for patches which exist elsewhere on the internet.

@terlar
Copy link
Contributor Author

terlar commented Jul 27, 2019

Thank you @symphorien I will try this out with my printer to see if it works all the way. I had the build step of the lgmon but missed the stuff with the static library so didn't come as far as you did.

Regarding using fetchpatch, some of them were from elsewhere, but most of them I had to modify in some way to make them apply.

Patches not applying:

  • cnijfilter-3.20-4-libpng15.patch/cnijfilter-3.40-4-libpng15.patch - line missmatches
  • cnijfilter-3.20-4-ppd.patch/cnijfilter-4.00-4-ppd.patch - missing a/ prefix to file names
  • cnijfilter-3.80-5-abi_x86_32.patch - missing a/ and b/ prefix to file names

Patches applying:

  • cnijfilter-3.80-1-cups-1.6.patch
  • cnijfilter-3.80-6-cups-1.6.patch
  • cnijfilter-3.80-6-headers.patch

I could use the fetchpatch for those three, but the other ones I think requires a local copy with adjustments.

@terlar
Copy link
Contributor Author

terlar commented Jul 28, 2019

I have now tested the driver and successfully printed using duplex and borderless and seems to work well. Only thing is I couldn't combine borderless and duplex, but that is probably a limitation on the printer side.

So this is basically ready. Should I squash the commits? Is this fetchpatch usage good? I went with a specific commit, since technically master could change, and used the referred repository as I am not sure where these patches originally originated from.

Thanks for the help @symphorien 🙇‍♂️

@terlar terlar changed the title [WIP] cnijfilter: add 3.80 cnijfilter: add 3.80 Jul 28, 2019
storeDir = config.nix.storeDir or "/nix/store";
stateDir = config.nix.stateDir or "/nix/var";
boehmgc = boehmgc.override { enableLargeConfig = true; };
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you drop the whitespace-only changes in this file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry about that, had auto-formatting enabled for nix files, will ensure that is not part of the final squash

@symphorien
Copy link
Member

I left a nitpick, but it looks good to me overall. I have a slight preference for squashing the commits together, but it is not so important I guess.

@terlar
Copy link
Contributor Author

terlar commented Jul 28, 2019

When I went through the checklist I noticed the binaries cnijnetprn and cnijnpr complained about libcnnet.so to be missing, I guess I have to copy that file over somewhere.

Debian has a rule such as:


debian/rules
158:    install -c -m 755 com/libs_bin${_arc}/libcnnet.so.* $(CURDIR)/debian/${COMMON_PKG}/usr/lib; \

It seems to be linked via via the LDFLAGS, but I guess that doesn't ensure it is part of the build.

cnijfilter-common.spec
174:    ./autogen.sh --prefix=%{_prefix} --enable-libpath=%{_libdir}/bjlib --enable-progpath=%{_bindir} LDFLAGS="-L../../com/libs_bin%{_arc}"
223:install -c -s -m 755 com/libs_bin%{_arc}/*.so.*     ${RPM_BUILD_ROOT}%{_libdir}

debian/rules
61:     cd ./backendnet; ./autogen.sh --prefix=/usr --enable-progpath=/usr/bin LDFLAGS="-L../../com/libs_bin${_arc}"
158:    install -c -m 755 com/libs_bin${_arc}/libcnnet.so.* $(CURDIR)/debian/${COMMON_PKG}/usr/lib; \

backendnet/lmonitor/Makefile.am
12:cnijnetprn_LDFLAGS = -L../../com/libs_bin@ARC@

maintenance/src/Makefile.am
44:maintenance_LDFLAGS = -L../../@CNCL_LIB_ID@/libs_bin@ARC@ -L../../com/libs_bin@ARC@

cngpijmon/cnijnpr/cnijnpr/Makefile.am
9:cnijnpr_LDFLAGS = -L../../../com/libs_bin@ARC@ -L../../../lgmon/src

I am not so familiar with this, but will have a look at how other packages do to copy lib files.

Perhaps something similar to what we do here already:
e0d0897#diff-4f9351975837499628240d54687bbe59R106-R110

@terlar
Copy link
Contributor Author

terlar commented Jul 28, 2019

Added this install -c -s -m 755 com/libs_bin${arch}/libcnnet.so.* $out/lib; and now I can run the commands without complaints.

I also fixed the whitespace/styling changes to all-packages.

Copy link
Contributor

@turion turion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! I tried to do this myself (#85325) and ran into similar problems, but I didn't get as far as you. What is missing here until it can be merged?

make install;

cd ../cnijfilter;
./autogen.sh --prefix=$out --program-suffix=$pr --enable-libpath=/var/lib/cups/path/lib/bjlib --enable-binpath=$out/bin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
./autogen.sh --prefix=$out --program-suffix=$pr --enable-libpath=/var/lib/cups/path/lib/bjlib --enable-binpath=$out/bin;
./autogen.sh --prefix=$out --program-suffix=$pr --enable-libpath=$out/lib/bjlib --enable-binpath=$out/bin;

@terlar
Copy link
Contributor Author

terlar commented Apr 16, 2020

Thank you for the feedback, as far as I am aware this was working, it just has to be rebased and updated, if I remember correctly one of the patches stopped wokring due to the upstream having a change. Since I waited quite a bit, I didn't push and update those changes. If there is interested, I think we can revive this and get it past the finish-line.

Do you want to do it, or should I take a stab at it again? Also good to have more people testing it, so feel free to test if this is working (if you haven't already)

@chpatrick
Copy link
Contributor

Hi, it looks like on Arch there's a common package and the printer-specific PKGBUILDs don't really do much: https://aur.archlinux.org/packages/cnijfilter-common/

Do you think we could copy their approach instead of going through this misery for every printer? I also remember Gentoo had some kind of generic cnijfilter ebuild, but I can't find it any more.

@turion
Copy link
Contributor

turion commented Apr 16, 2020

@terlar Good to hear back :)

Do you want to do it, or should I take a stab at it again? Also good to have more people testing it, so feel free to test if this is working (if you haven't already)

Either way is fine for me. I rebased and fixed the hashes here: https://github.com/turion/nixpkgs/tree/cnijfilter-3.80 I'm not a C dev though, so I won't be of much use fixing anything related to that.

I can confirm that it builds and the driver shows up, but I haven't yet managed to print with it. (I'll restart my system and try again)

@turion
Copy link
Contributor

turion commented Apr 16, 2020

@chpatrick

Hi, it looks like on Arch there's a common package and the printer-specific PKGBUILDs don't really do much: https://aur.archlinux.org/packages/cnijfilter-common/

Do you think we could copy their approach instead of going through this misery for every printer? I also remember Gentoo had some kind of generic cnijfilter ebuild, but I can't find it any more.

That would be great. But it seems like that Arch Linux package is only for the 4.10 version? I.e. only for some particular printers?

@turion
Copy link
Contributor

turion commented Apr 16, 2020

@terlar How did you test? USB connection? IPP? If the latter, how did you set it up?

@terlar
Copy link
Contributor Author

terlar commented Apr 16, 2020

I updated mine as well.

Some of these patches come from a gentoo overlay ebuild:
https://gitlab.com/tokiclover/bar-overlay/-/blob/master/net-print/cnijfilter/cnijfilter-3.80-r2.ebuild

I have only tried to print via Wi-Fi. So IPP via cups I guess.

At the time I remember looking at the PKGBUILD as well, but not sure how it translates to the nix world and as @turion mentioned, I also don't know much about the details of printer drivers and C development.

@turion
Copy link
Contributor

turion commented Apr 16, 2020

I added the printer via CUPS and inserted ipp://192.168.123.45/ipp/ as the address (where 123.45 is the local address it assigned to the printer over DHCP I believe). I could select the correct driver. But when I print anything it shows the job as completed and claims it had 0 pages. (And it didn't print.)

@turion
Copy link
Contributor

turion commented Apr 16, 2020

@terlar I tried again with your branch, same thing. Does it still work for you? Can you share your CUPS config?

@turion
Copy link
Contributor

turion commented Apr 16, 2020

@terlar what happens if you run ipptool -t -v ipp://192.168.123.45/ipp/print ipp-2.0.test |grep FAIL (and put in the correct IP of your printer)?

I get:

    RFC 8011 section 4.2.1: Print-Job Operation                          [FAIL]
    PWG 5100.12 section 6.2 - Required Printer Description Attributes    [FAIL]

But no Idea whether that's important

@turion
Copy link
Contributor

turion commented Apr 16, 2020

I also got the "Filter failed" message once now.

@chpatrick
Copy link
Contributor

chpatrick commented Apr 16, 2020

@chpatrick

Hi, it looks like on Arch there's a common package and the printer-specific PKGBUILDs don't really do much: https://aur.archlinux.org/packages/cnijfilter-common/
Do you think we could copy their approach instead of going through this misery for every printer? I also remember Gentoo had some kind of generic cnijfilter ebuild, but I can't find it any more.

That would be great. But it seems like that Arch Linux package is only for the 4.10 version? I.e. only for some particular printers?

If you look at what depends on this package in AUR, those packages seem to have the printer-specific versions (for example this one). Their PKGBUILDs seem very simple.

I think @momeni wrote the PKGBUILD, maybe he could shed some light on the situation?

@chpatrick
Copy link
Contributor

Ah the generic implementation I was thinking of was actually in Ubuntu, not Gentoo: https://github.com/endlessm/cnijfilter-common

@chpatrick
Copy link
Contributor

chpatrick commented Apr 16, 2020

@chpatrick
Copy link
Contributor

I've ported the Gentoo build script and added 3.80 with it here: chpatrick@b65d189

It builds for me but it seems to add some extra junk in $out/usr/..., which should be fixed. I haven't tried it with a printer. If we get it working it should be easy to port the other driver versions too.

@momeni
Copy link

momeni commented Apr 17, 2020

About the ArchLinux packages, the common build code recursively builds a subset of source folders which can be used as shared libraries. They are independent of printer version. Another set of folders (lgmon, ppd, cnijfilter, printui, cngpijmon) must be compiled once for each printer version as their autogen.sh script needs --program-suffix=<printercode> option. See line 652 of mp640 as an example. Printer-specific outputs are placed under the corresponding three letter folder (356, 357, ...) which is specified in cnijfilter-common.spec file.
New upstream versions are not released for some old printer models, however, new versions do not ship major changes too and the latest common package version can work with older (but patched) printer-specific versions; here is the list of patches.

@turion
Copy link
Contributor

turion commented May 5, 2020

@terlar Are you still active here? In principle this looks good, except for that it doesn't work in my case.

@turion
Copy link
Contributor

turion commented May 5, 2020

@chpatrick I tried building your approach, it doesn't compile yet. Do you want to open a PR and I'll review?

@terlar
Copy link
Contributor Author

terlar commented May 6, 2020

@turion Sorry, yes, I was updating it and testing it and then it didn't work. But I was suspecting user error on my part (new computer). But then I got swamped with other stuff so never followed up. I would hope the @chpatrick solution was the way to go. If you want something other working in the meantime the gutenprint should work, although does not have the same config settings, so I still think it is valid to get this to work.

@chpatrick
Copy link
Contributor

@turian I made a PR here: #87083 I'm super busy at the moment so I don't really have time to finish it, but I think it's quite close. I would really appreciate help from anyone who's interested.

@terlar
Copy link
Contributor Author

terlar commented Aug 20, 2020

I will close this in favor of the other one. I have yet to test that, but I think it is wise to go with the more generic approach.

@terlar terlar closed this Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants