@@ -0,0 +1,105 @@
1+{ stdenv, fetchurl, cups, perl, brgenml1lpr, debugLvl ? "0"}:
2+
3+/*
4+ [Setup instructions](http://support.brother.com/g/s/id/linux/en/instruction_prn1a.html).
5+
6+ URI example
7+ ~ `lpd://BRW0080927AFBCE/binary_p1`
8+
9+ Logging
10+ -------
11+
12+ `/tmp/br_cupswrapper_ml1.log` when `DEBUG > 0` in `brother_lpdwrapper_BrGenML1`.
13+ Note that when `DEBUG > 1` the wrapper stops performing its function. Better
14+ keep `DEBUG == 1` unless this is desirable.
15+
16+ Now activable through this package's `debugLvl` parameter whose value is to be
17+ used to establish `DEBUG`.
18+
19+ Issues
20+ ------
21+
22+ 1. > Error: /tmp/brBrGenML1rc_15642 :cannot open file !!
23+
24+ This is a non fatal issue. The job will still be printed. However, not sure
25+ what kind of information could be lost.
26+
27+ There should be a more elegant way to patch this.
28+
29+ 2. > touch: cannot touch '/tmp/BrGenML1_latest_print_info': Permission denied
30+
31+ TODO: Address.
32+
33+ 3. > perl: warning: Falling back to the standard locale ("C").
34+
35+ are supported and installed on your system.
36+ LANG = "en_US.UTF-8"
37+ LC_ALL = (unset),
38+ LANGUAGE = (unset),
39+ perl: warning: Please check that your locale settings:
40+ perl: warning: Setting locale failed.
41+
42+ TODO: Address.
43+*/
44+
45+stdenv.mkDerivation rec {
46+
47+ name = "brgenml1cupswrapper-3.1.0-1";
48+ src = fetchurl {
49+ url = "http://download.brother.com/welcome/dlf101125/${name}.i386.deb";
50+ sha256 = "0kd2a2waqr10kfv1s8is3nd5dlphw4d1343srdsbrlbbndja3s6r";
51+ };
52+
53+ unpackPhase = ''
54+ ar x $src
55+ tar xfvz data.tar.gz
56+ '';
57+
58+ buildInputs = [ cups perl brgenml1lpr ];
59+ buildPhase = ":";
60+
61+ patchPhase = ''
62+ WRAPPER=opt/brother/Printers/BrGenML1/cupswrapper/brother_lpdwrapper_BrGenML1
63+ PAPER_CFG=opt/brother/Printers/BrGenML1/cupswrapper/paperconfigml1
64+
65+ substituteInPlace $WRAPPER \
66+ --replace "basedir =~" "basedir = \"${brgenml1lpr}/opt/brother/Printers/BrGenML1\"; #" \
67+ --replace "PRINTER =~" "PRINTER = \"BrGenML1\"; #" \
68+ --replace "\$DEBUG=0;" "\$DEBUG=${debugLvl};"
69+
70+ # Fixing issue #2.
71+ substituteInPlace $WRAPPER \
72+ --replace "\`cp " "\`cp -p " \
73+ --replace "\$TEMPRC\`" "\$TEMPRC; chmod a+rw \$TEMPRC\`" \
74+ --replace "\`mv " "\`cp -p "
75+
76+ # This config script make this assumption that the *.ppd are found in a global location `/etc/cups/ppd`.
77+ substituteInPlace $PAPER_CFG \
78+ --replace "/etc/cups/ppd" "$out/share/cups/model"
79+ '';
80+
81+ installPhase = ''
82+ CUPSFILTER=$out/lib/cups/filter
83+ CUPSPPD=$out/share/cups/model
84+
85+ CUPSWRAPPER=opt/brother/Printers/BrGenML1/cupswrapper
86+ mkdir -p $out/$CUPSWRAPPER
87+ cp -rp $CUPSWRAPPER/* $out/$CUPSWRAPPER
88+
89+ mkdir -p $CUPSFILTER
90+ ln -s $out/$CUPSWRAPPER/brother_lpdwrapper_BrGenML1 $CUPSFILTER
91+
92+ mkdir -p $CUPSPPD
93+ ln -s $out/$CUPSWRAPPER/brother-BrGenML1-cups-en.ppd $CUPSPPD
94+ '';
95+
96+ dontPatchELF = true;
97+
98+ meta = {
99+ description = "Brother BrGenML1 CUPS wrapper driver";
100+ homepage = http://www.brother.com;
101+ platforms = stdenv.lib.platforms.linux;
102+ license = stdenv.lib.licenses.gpl2Plus;
103+ maintainers = with stdenv.lib.maintainers; [ jraygauthier ];
104+ };
105+}