|
1 | | -# Ported from https://github.com/NixOS/nixpkgs/blob/807e9154dcb16384b1b765ebe9cd2bba2ac287fd/pkgs/misc/cups/drivers/canon/default.nix |
| 1 | +/* |
| 2 | + Port of the canon-cups-ufr2 package from nixpkgs for personal use. |
| 3 | +
|
| 4 | + Changelog: |
| 5 | + * Sat Nov 2 19:32:00 UTC 2024 polykernel - 0-1 |
| 6 | + - Initial port from upstream |
| 7 | + * Sun Feb 23 21:44:00 UTC 2025 polykernel - 0-2 |
| 8 | + - Port fix for build failure due to dangling symlinks[^1] |
| 9 | + from upstream PR[^2] which is in turn based on the |
| 10 | + cnrdrvcups-lb AUR package |
| 11 | +
|
| 12 | + [^1]: https://github.com/NixOS/nixpkgs/issues/380572#issuecomment-2646162619 |
| 13 | + [^2]: https://github.com/NixOS/nixpkgs/pull/381315 |
| 14 | +*/ |
2 | 15 |
|
3 | 16 | { |
4 | 17 | dream2nix, |
|
10 | 23 | let |
11 | 24 | inherit (config.deps) stdenv; |
12 | 25 |
|
| 26 | + l = lib // builtins; |
| 27 | + |
13 | 28 | system = |
14 | 29 | if stdenv.hostPlatform.system == "x86_64-linux" then |
15 | 30 | "intel" |
|
24 | 39 | suffix = "02"; |
25 | 40 |
|
26 | 41 | ld64 = "${stdenv.cc}/nix-support/dynamic-linker"; |
27 | | - libs = lib.makeLibraryPath config.mkDerivation.buildInputs; |
| 42 | + libs = l.makeLibraryPath config.mkDerivation.buildInputs; |
28 | 43 |
|
29 | | - versionNoDots = builtins.replaceStrings [ "." ] [ "" ] version; |
| 44 | + versionNoDots = l.replaceStrings [ "." ] [ "" ] version; |
30 | 45 |
|
31 | 46 | src_canon = config.deps.fetchurl { |
32 | 47 | url = "https://gdlp01.c-wss.com/gds/${dl}/linux-UFRII-drv-v${versionNoDots}-${region}-${suffix}.tar.gz"; |
33 | 48 | hash = "sha256-lktesKcGsHOUMgmeq04KYck6qai/tS/ZN2ptB8F/n4s="; |
34 | 49 | }; |
| 50 | + |
| 51 | + convertSpec = config.deps.writeTextFile { |
| 52 | + name = "convert-spec.awk"; |
| 53 | + checkPhase = "awk -f $target < /dev/null"; |
| 54 | + text = '' |
| 55 | + $1 == "%" phase { inPhase = 1; next } |
| 56 | + inPhase && /^%/ { exit } |
| 57 | + inPhase { |
| 58 | + gsub("[$]{RPM_BUILD_DIR}", "$srcRoot"); |
| 59 | + gsub("[$]{RPM_BUILD_ROOT}", ""); |
| 60 | + gsub("%{nobuild}", "0"); |
| 61 | + gsub("%{_builddir}", "$srcRoot"); |
| 62 | + gsub("%{_prefix}", "$out"); |
| 63 | + gsub("%{_libsarch}", "libs64/${system}"); |
| 64 | + gsub("%{_libdir}", "$out/lib"); |
| 65 | + gsub("%{locallibs}", "$out/lib"); |
| 66 | + gsub("%{_bindir}", "$out/bin"); |
| 67 | + gsub("%{_includedir}", "$out/include"); |
| 68 | + gsub("%{_cflags}", ""); |
| 69 | + gsub("%{_machine_type}", "MACHINETYPE=${stdenv.hostPlatform.parsed.cpu.name}"); |
| 70 | + gsub("%{common_dir}", "cnrdrvcups-common-${version}"); |
| 71 | + gsub("%{driver_dir}", "cnrdrvcups-lb-${version}"); |
| 72 | + gsub("%{utility_dir}", "cnrdrvcups-utility-${version}"); |
| 73 | + gsub("%{b_lib_dir}", "$srcRoot/lib"); |
| 74 | + gsub("%{b_include_dir}", "$srcRoot/include"); |
| 75 | + gsub("-m 4755", "-m 755"); # no setuid |
| 76 | + if (/%/) { |
| 77 | + print "error: variable not replaced:", $0 > "/dev/stderr" |
| 78 | + print "exit 1" |
| 79 | + exit 1 |
| 80 | + } |
| 81 | + print |
| 82 | + } |
| 83 | + ''; |
| 84 | + }; |
| 85 | + |
| 86 | + configureScript = config.deps.writeScript "canon-cups-ufr2-configure" '' |
| 87 | + set -eu |
| 88 | + # Update old automake files |
| 89 | + for dir in \ |
| 90 | + cnrdrvcups-common-${version}/{backend,buftool,cngplp,cnjbig,rasterfilter} \ |
| 91 | + cnrdrvcups-lb-${version}/{cngplp/files,cngplp,cpca,pdftocpca} |
| 92 | + do |
| 93 | + echo autoreconf $dir |
| 94 | + pushd "$dir" |
| 95 | + # For some reason, autoreconf fails to create ltmain.sh on first run. |
| 96 | + autoreconf --force --install --warnings=none || autoreconf --force --install --warnings=none |
| 97 | + popd |
| 98 | + done |
| 99 | + awk -f ${convertSpec} -v phase=setup cnrdrvcups-lb.spec | bash -eux |
| 100 | + ''; |
35 | 101 | in |
36 | 102 | { |
37 | 103 | imports = [ |
|
50 | 116 | fetchurl |
51 | 117 | pkg-config |
52 | 118 | makeWrapper |
| 119 | + writeTextFile |
| 120 | + writeScript |
53 | 121 | unzip |
54 | 122 | autoconf |
55 | 123 | automake |
|
72 | 140 | mkDerivation = { |
73 | 141 | src = src_canon; |
74 | 142 |
|
| 143 | + # we can't let patchelf remove unnecessary RPATHs because the driver uses dlopen to load libjpeg and libgcrypt |
| 144 | + dontPatchELF = true; |
| 145 | + |
75 | 146 | nativeBuildInputs = with config.deps; [ |
76 | 147 | makeWrapper |
77 | 148 | unzip |
|
95 | 166 | ]; |
96 | 167 |
|
97 | 168 | postUnpack = '' |
| 169 | + # make a new variable instead of shadowing `sourceRoot` |
| 170 | + export srcRoot=$PWD/$sourceRoot |
| 171 | +
|
98 | 172 | ( |
99 | 173 | cd $sourceRoot |
100 | 174 | tar -xf Sources/cnrdrvcups-lb-${version}-1.${suffix}.tar.xz |
101 | | - sed -ie "s@_prefix=/usr@_prefix=$out@" cnrdrvcups-common-${version}/allgen.sh |
102 | | - sed -ie "s@_libdir=/usr/lib@_libdir=$out/lib@" cnrdrvcups-common-${version}/allgen.sh |
103 | | - sed -ie "s@_bindir=/usr/bin@_bindir=$out/bin@" cnrdrvcups-common-${version}/allgen.sh |
104 | | - sed -ie "s@/usr@$out@" cnrdrvcups-common-${version}/{{backend,rasterfilter}/Makefile.am,rasterfilter/cnrasterproc.h} |
105 | | - sed -ie "s@etc/cngplp@$out/etc/cngplp@" cnrdrvcups-common-${version}/cngplp/Makefile.am |
106 | | - sed -ie "s@usr/share/cngplp@$out/usr/share/cngplp@" cnrdrvcups-common-${version}/cngplp/src/Makefile.am |
107 | | - patchShebangs cnrdrvcups-common-${version} |
108 | | -
|
109 | | - sed -ie "s@_prefix=/usr@_prefix=$out@" cnrdrvcups-lb-${version}/allgen.sh |
110 | | - sed -ie "s@_libdir=/usr/lib@_libdir=$out/lib@" cnrdrvcups-lb-${version}/allgen.sh |
111 | | - sed -ie "s@_bindir=/usr/bin@_bindir=$out/bin@" cnrdrvcups-lb-${version}/allgen.sh |
112 | | - sed -ie '/^cd \.\.\/cngplp/,/^cd files/{/^cd files/!{d}}' cnrdrvcups-lb-${version}/allgen.sh |
113 | | - sed -ie "s@cd \.\./pdftocpca@cd pdftocpca@" cnrdrvcups-lb-${version}/allgen.sh |
114 | | - sed -ie "s@/usr@$out@" cnrdrvcups-lb-${version}/pdftocpca/Makefile.am |
115 | | - sed -i "/CNGPLPDIR/d" cnrdrvcups-lb-${version}/Makefile |
116 | | - patchShebangs cnrdrvcups-lb-${version} |
117 | 175 | ) |
118 | 176 | ''; |
119 | 177 |
|
120 | | - installPhase = '' |
121 | | - runHook preInstall |
| 178 | + patches = [ |
| 179 | + ./0001-replace-incorrect-int-with-char.patch |
| 180 | + ]; |
122 | 181 |
|
123 | | - ( |
124 | | - cd cnrdrvcups-common-${version} |
125 | | - ./allgen.sh |
126 | | - make install |
127 | | - ) |
128 | | - ( |
129 | | - cd cnrdrvcups-common-${version}/Rule |
130 | | - mkdir -p $out/share/cups/usb |
131 | | - install -m 644 *.usb-quirks $out/share/cups/usb |
132 | | - ) |
133 | | - ( |
134 | | - cd cnrdrvcups-lb-${version} |
135 | | - ./allgen.sh |
136 | | - make install |
| 182 | + postPatch = '' |
| 183 | + substituteInPlace $(find cnrdrvcups-lb-${version}/cngplp -name Makefile.am) \ |
| 184 | + --replace-quiet /usr/include/libxml2/ ${config.deps.libxml2.dev}/include/libxml2/ |
| 185 | + substituteInPlace \ |
| 186 | + cnrdrvcups-common-${version}/{{backend,cngplp/src,rasterfilter}/Makefile.am,rasterfilter/cnrasterproc.h} \ |
| 187 | + cnrdrvcups-lb-${version}/{cngplp/files,pdftocpca}/Makefile.am \ |
| 188 | + --replace-fail /usr "$out" |
| 189 | + substituteInPlace cnrdrvcups-common-${version}/cngplp/Makefile.am \ |
| 190 | + --replace-fail /etc/cngplp "$out/etc/cngplp" |
| 191 | + patchShebangs cnrdrvcups-common-${version} |
| 192 | + patchShebangs cnrdrvcups-lb-${version} |
| 193 | + ''; |
137 | 194 |
|
138 | | - mkdir -p $out/share/cups/model |
139 | | - install -m 644 ppd/*.ppd $out/share/cups/model/ |
140 | | - ) |
| 195 | + configureScript = configureScript.outPath; |
141 | 196 |
|
142 | | - ( |
143 | | - cd lib |
144 | | - mkdir -p $out/lib |
145 | | - install -m 755 libs64/${system}/libColorGearCufr2.so.2.0.0 $out/lib |
146 | | - install -m 755 libs64/${system}/libcaepcmufr2.so.1.0 $out/lib |
147 | | - install -m 755 libs64/${system}/libcaiocnpkbidir.so.1.0.0 $out/lib |
148 | | - install -m 755 libs64/${system}/libcaiousb.so.1.0.0 $out/lib |
149 | | - install -m 755 libs64/${system}/libcaiowrapufr2.so.1.0.0 $out/lib |
150 | | - install -m 755 libs64/${system}/libcanon_slimufr2.so.1.0.0 $out/lib |
151 | | - install -m 755 libs64/${system}/libcanonufr2r.so.1.0.0 $out/lib |
152 | | - install -m 755 libs64/${system}/libcnaccm.so.1.0 $out/lib |
153 | | - install -m 755 libs64/${system}/libcnlbcmr.so.1.0 $out/lib |
154 | | - install -m 755 libs64/${system}/libcnncapcmr.so.1.0 $out/lib |
155 | | - install -m 755 libs64/${system}/libufr2filterr.so.1.0.0 $out/lib |
156 | | -
|
157 | | - install -m 755 libs64/${system}/cnpdfdrv $out/bin |
158 | | - install -m 755 libs64/${system}/cnpkbidir $out/bin |
159 | | - install -m 755 libs64/${system}/cnpkmoduleufr2r $out/bin |
160 | | - install -m 755 libs64/${system}/cnrsdrvufr2 $out/bin |
161 | | - install -m 755 libs64/${system}/cnsetuputil2 $out/bin/cnsetuputil2 |
162 | | -
|
163 | | - mkdir -p $out/share/cnpkbidir |
164 | | - install -m 644 libs64/${system}/cnpkbidir_info* $out/share/cnpkbidir |
165 | | -
|
166 | | - mkdir -p $out/share/ufr2filter |
167 | | - install -m 644 libs64/${system}/ThLB* $out/share/ufr2filter |
168 | | - ) |
| 197 | + buildPhase = '' |
| 198 | + runHook preBuild |
| 199 | +
|
| 200 | + awk -f ${convertSpec} -v phase=build cnrdrvcups-lb.spec | bash -eux |
| 201 | +
|
| 202 | + runHook postBuild |
| 203 | + ''; |
| 204 | + |
| 205 | + installPhase = '' |
| 206 | + runHook preInstall |
| 207 | +
|
| 208 | + awk -f ${convertSpec} -v phase=install cnrdrvcups-lb.spec | bash -eux |
169 | 209 |
|
170 | 210 | ( |
171 | 211 | cd $out/lib |
172 | 212 |
|
173 | | - ln -sf libColorGearCufr2.so.2.0.0 libColorGearCufr2.so |
174 | | - ln -sf libColorGearCufr2.so.2.0.0 libColorGearCufr2.so.2 |
175 | | - ln -sf libcaepcmufr2.so.1.0 libcaepcmufr2.so |
176 | | - ln -sf libcaepcmufr2.so.1.0 libcaepcmufr2.so.1 |
177 | | - ln -sf libcaiocnpkbidir.so.1.0.0 libcaiocnpkbidir.so |
178 | | - ln -sf libcaiocnpkbidir.so.1.0.0 libcaiocnpkbidir.so.1 |
179 | | - ln -sf libcaiowrapufr2.so.1.0.0 libcaiowrapufr2.so |
180 | | - ln -sf libcaiowrapufr2.so.1.0.0 libcaiowrapufr2.so.1 |
181 | | - ln -sf libcanon_slimufr2.so.1.0.0 libcanon_slimufr2.so |
182 | | - ln -sf libcanon_slimufr2.so.1.0.0 libcanon_slimufr2.so.1 |
183 | | - ln -sf libcanonufr2r.so.1.0.0 libcanonufr2r.so |
184 | | - ln -sf libcanonufr2r.so.1.0.0 libcanonufr2r.so.1 |
185 | | - ln -sf libcnlbcmr.so.1.0 libcnlbcmr.so |
186 | | - ln -sf libcnlbcmr.so.1.0 libcnlbcmr.so.1 |
187 | | - ln -sf libufr2filterr.so.1.0.0 libufr2filterr.so |
188 | | - ln -sf libufr2filterr.so.1.0.0 libufr2filterr.so.1 |
189 | | - ln -sf libuictlufr2r.so.1.0.0 libuictlufr2r.so |
190 | | - ln -sf libuictlufr2r.so.1.0.0 libuictlufr2r.so.1 |
191 | | -
|
192 | | - patchelf --set-rpath "$(cat $NIX_CC/nix-support/orig-cc)/lib:${libs}:${stdenv.cc.cc.lib}/lib64:${stdenv.cc.libc}/lib64:$out/lib" libcanonufr2r.so.1.0.0 |
193 | | - patchelf --set-rpath "$(cat $NIX_CC/nix-support/orig-cc)/lib:${libs}:${stdenv.cc.cc.lib}/lib64:${stdenv.cc.libc}/lib64" libcaepcmufr2.so.1.0 |
194 | | - patchelf --set-rpath "$(cat $NIX_CC/nix-support/orig-cc)/lib:${libs}:${stdenv.cc.cc.lib}/lib64:${stdenv.cc.libc}/lib64" libColorGearCufr2.so.2.0.0 |
| 213 | + patchelf --set-rpath "$(cat $NIX_CC/nix-support/orig-cc)/lib:${libs}:${l.getLib stdenv.cc.cc}/lib64:${stdenv.cc.libc}/lib64:$out/lib" libcanonufr2r.so.1.0.0 |
| 214 | + patchelf --set-rpath "$(cat $NIX_CC/nix-support/orig-cc)/lib:${libs}:${l.getLib stdenv.cc.cc}/lib64:${stdenv.cc.libc}/lib64" libcaepcmufr2.so.1.0 |
| 215 | + patchelf --set-rpath "$(cat $NIX_CC/nix-support/orig-cc)/lib:${libs}:${l.getLib stdenv.cc.cc}/lib64:${stdenv.cc.libc}/lib64" libColorGearCufr2.so.2.0.0 |
195 | 216 | ) |
196 | 217 |
|
197 | 218 | ( |
198 | 219 | cd $out/bin |
199 | | - patchelf --set-interpreter "$(cat ${ld64})" --set-rpath "${libs}:${stdenv.cc.cc.lib}/lib64:${stdenv.cc.libc}/lib64" cnsetuputil2 cnpdfdrv |
200 | | - patchelf --set-interpreter "$(cat ${ld64})" --set-rpath "${libs}:${stdenv.cc.cc.lib}/lib64:${stdenv.cc.libc}/lib64:$out/lib" cnpkbidir cnrsdrvufr2 cnpkmoduleufr2r cnjbigufr2 |
| 220 | + patchelf --set-interpreter "$(cat ${ld64})" --set-rpath "${l.makeLibraryPath config.mkDerivation.buildInputs}:${l.getLib stdenv.cc.cc}/lib64:${stdenv.cc.libc}/lib64" cnsetuputil2 cnpdfdrv |
| 221 | + patchelf --set-interpreter "$(cat ${ld64})" --set-rpath "${l.makeLibraryPath config.mkDerivation.buildInputs}:${l.getLib stdenv.cc.cc}/lib64:${stdenv.cc.libc}/lib64:$out/lib" cnpkbidir cnrsdrvufr2 cnpkmoduleufr2r cnjbigufr2 |
201 | 222 |
|
202 | 223 | wrapProgram $out/bin/cnrsdrvufr2 \ |
203 | 224 | --prefix LD_LIBRARY_PATH ":" "$out/lib" \ |
|
209 | 230 | --set NIX_REDIRECTS /usr/share/cnsetuputil2=$out/usr/share/cnsetuputil2 |
210 | 231 | ) |
211 | 232 |
|
212 | | - ( |
213 | | - cd lib/data/ufr2 |
214 | | - mkdir -p $out/share/caepcm |
215 | | - install -m 644 *.ICC $out/share/caepcm |
216 | | - install -m 644 *.icc $out/share/caepcm |
217 | | - install -m 644 *.PRF $out/share/caepcm |
218 | | - install -m 644 CnLB* $out/share/caepcm |
219 | | - ) |
220 | | -
|
221 | | - ( |
222 | | - cd cnrdrvcups-utility-${version}/data |
223 | | - mkdir -p $out/usr/share/cnsetuputil2 |
224 | | - install -m 644 cnsetuputil* $out/usr/share/cnsetuputil2 |
225 | | - ) |
226 | | -
|
227 | 233 | makeWrapper "${config.deps.ghostscript}/bin/gs" "$out/bin/gs" \ |
228 | 234 | --prefix LD_LIBRARY_PATH ":" "$out/lib" \ |
229 | 235 | --prefix PATH ":" "$out/bin" |
|
0 commit comments