-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
10 changed files
with
1,152 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.