From 033b21e782db35bb6baab898f0c319e27906fedb Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Fri, 19 Jul 2024 23:08:38 +0100 Subject: [PATCH] magicard-cups-driver: init at 1.4.0 --- nix/pkgs/default.nix | 1 + nix/pkgs/magicard-cups-driver/CMakeLists.txt | 203 +++++++++++++++++++ nix/pkgs/magicard-cups-driver/default.nix | 36 ++++ 3 files changed, 240 insertions(+) create mode 100644 nix/pkgs/magicard-cups-driver/CMakeLists.txt create mode 100644 nix/pkgs/magicard-cups-driver/default.nix diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index c5c1ab1110..014a6c0cef 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -84,4 +84,5 @@ freeswitch-sounds = pkgs.callPackage ./freeswitch-sounds.nix { }; lukegb-vscode = pkgs.vscode; + magicard-cups-driver = pkgs.callPackage ./magicard-cups-driver { }; } // (import ./heptapod-runner args) diff --git a/nix/pkgs/magicard-cups-driver/CMakeLists.txt b/nix/pkgs/magicard-cups-driver/CMakeLists.txt new file mode 100644 index 0000000000..077da4e62e --- /dev/null +++ b/nix/pkgs/magicard-cups-driver/CMakeLists.txt @@ -0,0 +1,203 @@ +cmake_minimum_required(VERSION 3.10) + +include(CMakePushCheckState) +include(CheckIncludeFile) + +## Git version +find_program(GIT_EXE git) +if(EXISTS ${GIT_EXE}) + execute_process(COMMAND ${GIT_EXE} describe --dirty --always --tag + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_VERSION + RESULT_VARIABLE GIT_DESCRIBE_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT ${GIT_DESCRIBE_RESULT} EQUAL 0) + set(GIT_VERSION unknown) + endif(NOT ${GIT_DESCRIBE_RESULT} EQUAL 0) +else(EXISTS ${GIT_EXE}) + set(GIT_VERSION unknown) +endif(EXISTS ${GIT_EXE}) + +# set the project name +project(Magicard-CUPS-driver + DESCRIPTION "CUPS driver for Magicard Printers" + HOMEPAGE_URL "http://www.magicard.com" + LANGUAGES C) + +## Configure CUPS +# https://github.com/pdewacht/brlaser/blob/master/CMakeLists.txt + +find_program(CUPS_CONFIG NAMES cups-config) +if(NOT CUPS_CONFIG) + message(FATAL_ERROR "cups-config command not found. Are the CUPS development packages installed?") +endif() + +if(NOT CUPS_DATA_DIR) + execute_process( + COMMAND "${CUPS_CONFIG}" --datadir + OUTPUT_VARIABLE CUPS_DATA_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() +if(NOT CUPS_SERVER_BIN) + execute_process( + COMMAND "${CUPS_CONFIG}" --serverbin + OUTPUT_VARIABLE CUPS_SERVER_BIN + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() +if(NOT CUPS_CFLAGS) + execute_process( + COMMAND "${CUPS_CONFIG}" --cflags + OUTPUT_VARIABLE CUPS_CFLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() +if(NOT CUPS_LDFLAGS) + execute_process( + COMMAND "${CUPS_CONFIG}" --ldflags + OUTPUT_VARIABLE CUPS_LDFLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() +if(NOT CUPS_LIBS) + execute_process( + COMMAND "${CUPS_CONFIG}" --image --libs + OUTPUT_VARIABLE CUPS_LIBS + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() + + +cmake_push_check_state() +set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${CUPS_CFLAGS}") +check_include_file(cups/raster.h HAVE_CUPS_RASTER_H) +cmake_pop_check_state() +if(NOT HAVE_CUPS_RASTER_H) + message(SEND_ERROR " header not found. Are the CUPS development packages installed?") +endif() + +#add_subdirectory(src) +set (PROJ_BUILD_FLAGS "\ +-Wall \ +-Wextra \ +-Wpedantic \ +-Werror \ +-Wno-error=deprecated \ +-Wno-error=deprecated-declarations \ +-fPIC \ +") + + + +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG") +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PROJ_BUILD_FLAGS}") + +# add the executable +add_executable(rastertoultra src/rastertoultra.c + src/colour-profiles/magiox.c + src/colour-profiles/magir2x.c + src/colour-profiles/magiry.c + src/colrmtch.c + src/crc32.c + src/magencd.c + src/rp2mag.c + src/utils.c + src/rp2mag_encode.c + src/command_helper.c + src/commandmb1.c) + +target_compile_options(rastertoultra PRIVATE ${CUPS_CFLAGS}) +target_link_libraries(rastertoultra ${CUPS_LIBS}) +target_link_libraries(rastertoultra ${CUPS_LDFLAGS}) +target_link_libraries(rastertoultra m) + + +add_executable(cmdtoultra src/cmdtoultra.c + src/crc32.c) + +target_link_libraries(cmdtoultra PRIVATE ${CUPS_LIBS}) + +## INSTALL +file(GLOB PPD_FILES LIST_DIRECTORIES false ppd/*.ppd) +install( + TARGETS rastertoultra cmdtoultra + DESTINATION "${CUPS_SERVER_BIN}/filter") +install(FILES ${PPD_FILES} DESTINATION "${CUPS_DATA_DIR}/model/ultra") + +## Package + +set(CPACK_PACKAGE_VERSION "${GIT_VERSION}") + +if (APPLE) + set(CPACK_GENERATOR "productbuild") +else() + # DEB + set(CPACK_GENERATOR "DEB") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Magicard Ltd") +endif() + +# Source TGZ +# TODO: This isn't yet complete. +set(CPACK_SOURCE_GENERATOR "TGZ") +set(CPACK_SOURCE_IGNORE_FILES + .clang-format + \\.git/ + .gitmodules + .gitignore + .vim/ + ".*~$" + ".*\.cmake$" + /bin/ + /build/ + /build_temp/ + /build_tools/ + /CMakeFiles/ + /_CPack_Packages/ + /deb/ + /debian/ + /install/ + /output/ + bitbucket-pipelines.yml + CMakeCache.txt + cmdtoultra + install_manifest.txt + jenkinsfile + Makefile + rastertoultra + readme.md + "Magicard-CUPS-driver-.*-Source.*" + ".*\.deb" + ) +set(CPACK_VERBATIM_VARIABLES YES) +include(CPack) + +## TESTS + +#add_subdirectory(test/unity EXCLUDE_FROM_ALL) +#add_executable(test_rp2_mag EXCLUDE_FROM_ALL test/test_rp2_mag.c +# src/rp2mag.c +# src/rp2mag_encode.c +# src/utils.c) +#target_compile_definitions(test_rp2_mag PRIVATE TEST) +#target_include_directories(test_rp2_mag PRIVATE src) +#target_link_libraries(test_rp2_mag unity) +# +#add_executable(test_dpi EXCLUDE_FROM_ALL test/test_dpi.c +# src/rastertoultra.c +# src/utils.c +# src/crc32.c +# src/rp2mag.c +# src/colrmtch.c +# src/rp2mag_encode.c +# src/magencd.c +# src/colour-profiles/magir2x.c +# src/colour-profiles/magiox.c +# src/colour-profiles/magiry.c) +#target_include_directories(test_dpi PRIVATE src) +#target_compile_definitions(test_dpi PRIVATE TEST) +#target_compile_options(test_dpi PRIVATE -Wno-unused-function) +#target_link_libraries(test_dpi unity m ${CUPS_LIBS}) +# +#enable_testing() +#add_test(test_rp2_mag test_rp2_mag) +#add_test(test_dpi test_dpi) +# +## Autotools-style "make check" command +#add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) +#add_dependencies(check test_rp2_mag test_dpi) diff --git a/nix/pkgs/magicard-cups-driver/default.nix b/nix/pkgs/magicard-cups-driver/default.nix new file mode 100644 index 0000000000..8fd49f62fc --- /dev/null +++ b/nix/pkgs/magicard-cups-driver/default.nix @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2024 Luke Granger-Brown +# +# SPDX-License-Identifier: Apache-2.0 + +{ stdenv +, lib +, fetchurl +, fetchFromGitHub +, cmake +, cups +}: + +stdenv.mkDerivation rec { + pname = "magicard-cups-driver"; + version = "1.4.0"; + + src = fetchurl { + url = "https://f08ddbe93aa02eaf9a6c-f08cd513e3a8c914f4f8f62af1786149.ssl.cf3.rackcdn.com/magicard_ltd-linux_driver-1.4.0.tar.gz"; + hash = "sha256-OAdpxnGMqVcf3bEtYQ9PACZFJvq8gzhGxuBBnliwoso="; + }; + + postPatch = '' + cp ${./CMakeLists.txt} ./CMakeLists.txt + + substituteInPlace ppd/*.ppd \ + --replace-fail 'rastertoultra' "$out/lib/cups/filter/rastertoultra" \ + --replace-fail 'cmdtoultra' "$out/lib/cups/filter/cmdtoultra" + ''; + + cmakeFlags = [ + "-DCUPS_DATA_DIR=share/cups" + "-DCUPS_SERVER_BIN=lib/cups" + ]; + + nativeBuildInputs = [ cmake cups ]; +}