Skip to content

Commit

Permalink
Global refactor
Browse files Browse the repository at this point in the history
All pre-built binaries removed from the project.

Building is now done with CMake.

PPDs are have to be built from shipped driver sources (however couple
of defaults are still placed in sources as a fallback).

CMake also includes install instructions (so after build 'sudo make
install' will give you working solution both on Linux and on Mac Os).
  • Loading branch information
klirichek committed Mar 28, 2019
1 parent f60bb29 commit 68c0572
Show file tree
Hide file tree
Showing 10 changed files with 1,152 additions and 453 deletions.
78 changes: 53 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required ( VERSION 3.12 )
cmake_minimum_required ( VERSION 3.0 )

# set default build type to Release (if nothing else provided from outside yet)
IF ( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
Expand All @@ -9,27 +9,29 @@ ENDIF ()

project ( rastertozj C )

#set ( CMAKE_INSTALL_PREFIX "/usr" CACHE FILEPATH "force install to /usr" FORCE )

function( DIAG VARR )
message ( STATUS "${VARR} -> ${${VARR}}" )
endfunction()

# build the filter binary
# requirements to build the filter binary
find_package ( Cups REQUIRED )
find_library ( CUPSIMAGELIB NAMES cupsimage )
mark_as_advanced ( CUPSIMAGELIB )

set ( DEBUGFILE "/tmp/debugraster.txt" CACHE STRING "File where to make debug output if DEBUGP is set" )
option ( DEBUGP "Whetner to output debug info" ON )

add_executable ( rastertozj rastertozj.c )
target_compile_options ( rastertozj PRIVATE -Wall -fPIC )
target_include_directories ( rastertozj PRIVATE ${CUPS_INCLUDE_DIR} )
target_link_libraries ( rastertozj PRIVATE ${CUPS_LIBRARIES} ${CUPSIMAGELIB} )

if ( DEBUGP )
target_compile_definitions ( rastertozj PRIVATE DEBUGP DEBUGFILE="${DEBUGFILE}")
if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
target_compile_definitions ( rastertozj PRIVATE DEBUGP )
if ( APPLE )
target_compile_definitions ( rastertozj PRIVATE SAFEDEBUG )
message ( STATUS "On Mac OSX log is saved in sandbox, as /private/var/spool/cups/tmp" )
elseif ( UNIX )
set ( DEBUGFILE "/tmp/debugraster.txt" CACHE STRING "File where to make debug output if we build ad Debug" )
target_compile_definitions ( rastertozj PRIVATE DEBUGFILE="${DEBUGFILE}" )
endif ()
endif ()

# build ppds
Expand All @@ -38,37 +40,63 @@ if ( NOT DEFINED PPDC )
endif ()
mark_as_advanced( PPDC )

set ( PPDS "" )
if ( PPDC )
set ( ENV{LANG} c )
execute_process (
COMMAND "${PPDC}" -d "${CMAKE_CURRENT_BINARY_DIR}" "zj-58.drv"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE _CONTENT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE )
set ( DRVSRC "${CMAKE_CURRENT_SOURCE_DIR}/zjdrv.drv")
set ( PPDDIR "${CMAKE_CURRENT_BINARY_DIR}/ppd" )
list (APPEND PPDS "${PPDDIR}/zj58.ppd" )
list (APPEND PPDS "${PPDDIR}/xp58.ppd" )
list (APPEND PPDS "${PPDDIR}/tm20.ppd" )
list (APPEND PPDS "${PPDDIR}/zj80.ppd" )
ADD_CUSTOM_COMMAND ( OUTPUT ${PPDS}
COMMAND LANG=c ${PPDC} ${DRVSRC}
MAIN_DEPENDENCY ${DRVSRC}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Building PPDs"
VERBATIM
)
ADD_CUSTOM_TARGET ( ppds ALL DEPENDS ${PPDS} )
else()
message (STATUS "No ppdc found; fall back to defaultly shipped ZJ-58.ppd")
list ( APPEND PPDS "${CMAKE_CURRENT_SOURCE_DIR}/zj58.ppd" )
list ( APPEND PPDS "${CMAKE_CURRENT_SOURCE_DIR}/zj80.ppd" )
endif()

# installation stuff

# this one works if you perform 'make install'
set ( CMAKE_INSTALL_PREFIX "/usr" CACHE FILEPATH "this is forced to /usr" FORCE )

# this one works if you perform 'make package' - it is kind of root for all packaging
# Set both installation prefixes to /
set ( CMAKE_INSTALL_PREFIX "/" CACHE FILEPATH "this is forced to /" FORCE )
set ( CPACK_PACKAGING_INSTALL_PREFIX "/" )
set ( CPACK_PACKAGE_CONTACT "Alexey N. Vinogradov ([email protected])" )


include ( GNUInstallDirs )
set ( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON )
set ( CPACK_DEBIAN_PACKAGE_PREDEPENDS "libcups2-dev, libcupsimage2-dev" )
set ( CPACK_DEBIAN_PACKAGE_SECTION "libs" )
set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/klirichek/zj-58")

if ( APPLE )
set ( FILTERPATH "usr/libexec/cups/filter" )
set ( PPDPATH "Library/Printers/PPDs/Contents/Resources")
set ( OWNER "root:wheel")
install ( CODE "EXECUTE_PROCESS(COMMAND sudo launchctl stop org.cups.cupsd)" )
install ( TARGETS rastertozj DESTINATION ${FILTERPATH} )
# this line sets correct target permissions, due to CUPS requirements
# However as a side effect you'll need either fakeroot, either sudo to even perform 'make package' because of it.
install ( CODE "EXECUTE_PROCESS(COMMAND chown ${OWNER} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${FILTERPATH}/rastertozj\")" )
install ( FILES ${PPDS} DESTINATION "${PPDPATH}" )
install ( CODE "EXECUTE_PROCESS(COMMAND sudo launchctl start org.cups.cupsd)" )
elseif ( UNIX )
set ( FILTERPATH "usr/lib/cups/filter" )
set ( PPDPATH "usr/share/cups/model/zjiang/" )
set ( OWNER "root:root")
install ( CODE "EXECUTE_PROCESS(COMMAND /etc/init.d/cups stop)" )
install ( TARGETS rastertozj DESTINATION ${FILTERPATH} )
# this line sets correct target permissions, due to CUPS requirements
# However as a side effect you'll need either fakeroot, either sudo to even perform 'make package' because of it.
install ( CODE "EXECUTE_PROCESS(COMMAND chown ${OWNER} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${FILTERPATH}/rastertozj\")" )
install ( FILES ${PPDS} DESTINATION "${PPDPATH}" )
install ( CODE "EXECUTE_PROCESS(COMMAND /etc/init.d/cups start)" )
endif()

install ( TARGETS rastertozj DESTINATION ${FILTERPATH} )
install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/zj58.ppd DESTINATION "${PPDPATH}" )
include (CPack)

17 changes: 0 additions & 17 deletions Makefile

This file was deleted.

60 changes: 49 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
zj-58
CUPS driver for thermal receipt printers (was: zj-58)
=====================================================

CUPS filter for thermal receipt printers for rolls 58 and 80mm.

Originally it was filter for Zijiang zj-58 with specific PPD,
but later it is revealed that it actually works with many other cheap 58mm printers, like
Xprinter XP-58, etc. Also support for 80mm printers added.

Printing is performed from cups-raster using ESC/POS sequence 'GS v 0 <x> <y>'.
Empty (zero) lines feeded as 'feed' command (to avoid send empty raster).

Also 2 Cash Drawers supported, with tunable impulse length for 'on' and 'off.'

Build
=====

CUPS filter for thermal printer Zjiang ZJ-58
You need toolchain, CMake and cups-devel.

It may be achieved, say (as example) by running
```
sudo apt install build-essential cmake libcups2-dev libcupsimage2-dev
```

After it the filter could be built by the sequence of commands:

```
mkdir build && cd build && cmake ..
make
```


Installation
============

Need administrative rights!

```
sudo make install
```

'Sudo' is necessary to stop/restart cups service before operation, and also to place files with necessary rights.


Debian packaging
================

The linux driver provided on Zjiang site unfortunately doesn't work.
First, it is 32-bit binary (and so, on x64 system need some x86 libs to be installed).
Second, it's PPD is not correct - it just doesn't show any advanced settings because of it.
Finally, raster filter just crashes on any try to run it!
But even if you run it, you'll see that it's working with printer is not optimal: for example, if it sees a blank line, it will send the blank raster to print (instead of just use 'feeding' command, which is definitely faster!)
For simplicity done with the same script as installation, so also need adminstrative rights.
```
sudo cpack -G DEB
```

This is the solution:
PPD is fixed and works.
Filter is provided as src (you can found a list of packages need to be installed in order to build it in the header of source).
Also, printing of blank lines is optimized.
That will stop/start cups as a side effect, however that is not critical.
117 changes: 0 additions & 117 deletions ZJ-58.ppd

This file was deleted.

3 changes: 3 additions & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Installs zj-58 driver
# Tested as working under Ubuntu 14.04

# Deprecated. Don't use this script;
# use build with cmake and then 'make install' instead

/etc/init.d/cups stop
cp rastertozj /usr/lib/cups/filter/
mkdir -p /usr/share/cups/model/zjiang
Expand Down
Loading

0 comments on commit 68c0572

Please sign in to comment.