diff --git a/.gitignore b/.gitignore index ecc40e7..8218d96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,46 +1,8 @@ -# http://www.gnu.org/software/automake -Makefile.in - -# http://www.gnu.org/software/autoconf -/autom4te.cache -/aclocal.m4 -/compile -/depcomp -/install-sh -/missing -/stamp-h1 -/configure -/config.guess -/config.h.in -/config.rpath -/config.sub - -# generated by configure script -/config.h -/config.status -/Makefile - -# C-Objects -*.o +# generated files +build/ # special directories /po !/po/POTFILES.in !/po/LINGUAS !/po/Makevars -/m4 -src/.deps/ -src/.dirstamp - -# Log files -*.log - -# Documents -ABOUT-NLS -INSTALL - -# created by cmake -/build - -# Binaries -ptouch-print diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index ea1e03e..0000000 --- a/AUTHORS +++ /dev/null @@ -1,2 +0,0 @@ - -ptouch-print written by Dominic Radermacher diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d5318ae --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,65 @@ +cmake_minimum_required(VERSION 3.15) +project(ptouch-print C) + +# Configure CMake +set(CMAKE_C_STANDARD 11) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") + +# Configure required dependencies +find_package(Gettext REQUIRED) +find_package(GD REQUIRED) +find_package(PkgConfig REQUIRED) +find_package(Intl REQUIRED) + +pkg_check_modules(LIBUSB REQUIRED libusb-1.0) + +# Configure project executable +add_executable(ptouch-print) + +target_sources(ptouch-print PUBLIC + version.h + include/ptouch.h + include/gettext.h + src/libptouch.c + src/ptouch-print.c +) + +# Configure compiler +target_compile_options(ptouch-print PUBLIC + -g + -Wall + -Wextra + -Wunused + -O3 + -fPIC +) + +target_compile_definitions(ptouch-print PUBLIC + LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}" + USING_CMAKE=1 + PACKAGE="ptouch-print" +) + +target_include_directories(ptouch-print PUBLIC + include + ${GD_INCLUDE_DIR} + ${LIBUSB_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR} + ${Libintl_INCLUDE_DIRS} +) + +# Configure linker +target_link_libraries(ptouch-print + ${GD_LIBRARIES} + ${LIBUSB_LIBRARIES} + ${Libintl_LIBRARY} +) + +# Add a custom command that produces version.h, plus a dummy output that's +# not produced, in order to force gitversion.cmake to always be re-run +# before the build +ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/version.h + ${CMAKE_BINARY_DIR}/_version.h + COMMAND ${CMAKE_COMMAND} -P + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.cmake) diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index cdad11a..0000000 --- a/ChangeLog +++ /dev/null @@ -1,33 +0,0 @@ - -date ver description of changes - -2015-12-29 1.3.2 - added inital ptouch-gtk - it is WITHOUT function - for now. I just have somewhere to start... - -2015-11-12 1.3.1 - small bugfix - - now using autotools - -2015-02-13 1.3 - merged ptouch-printpng and ptouch-printtext to one - single tool so that multiple texts and images can be - printed in one single pass. - - added ptouch_cutmark() function - - added initial gettext() support - -2015-01-05 1.2.3 - fixed a bug that did cut off chars which go below the - font baseline (like g,q,j,...) - Seems that gdImageStringFT() interprets the y coord - as baseline of the font (is this the case for all - fonts??) instead of the bottom most pixel. - -2014-12-20 1.2.2 - added support for printing up to 4 lines of text - -2014-11-01 1.2.1 - added support for PT-1230PC printer (not tested) - -2014-10-1? 1.2 - added tool 'ptouch-printtext' which can print labels - with one or two lines of text - -2014-10-11 1.1 - easier adding of (yet) unsupported p-touch printers - and tape widths - - code cleanup - -2014-10-08 1.0 Initial release diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 1708425..0000000 --- a/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -AUTOMAKE_OPTIONS = subdir-objects -AM_CPPFLAGS= -DLOCALEDIR='"$(localedir)"' -AM_CFLAGS=-g -std=c11 -Wall -Wextra -Wunused -O3 -I$(top_srcdir)/include -fPIC -SUBDIRS = po -ACLOCAL_AMFLAGS = -I m4 -EXTRA_DIST = config.rpath m4/ChangeLog Makefile.old -bin_PROGRAMS=ptouch-print -noinst_HEADERS=include/ptouch.h include/gettext.h -ptouch_print_SOURCES=src/ptouch-print.c src/libptouch.c include/ptouch.h include/gettext.h -ptouch_print_LDFLAGS=-lusb-1.0 -lgd diff --git a/NEWS b/NEWS deleted file mode 100644 index 7bc97a6..0000000 --- a/NEWS +++ /dev/null @@ -1,2 +0,0 @@ - -See ChangeLog diff --git a/README b/README index 328f150..fc64c6c 100644 --- a/README +++ b/README @@ -1,13 +1,13 @@ About: -ptouch is a command line tool to print labels on Brother P-Touch +ptouch-print is a command line tool to print labels on Brother P-Touch printers on Linux. There is no need to install the printer via CUPS, the printer is accessed directly via libusb. -The tool was written for and tested with the PT-2430PC, but it should also -work with the PT-1230PC (untested so far). +The tool was written for and tested with the PT-2430PC, but meanwhile is also +used with others (see "ptouch-print --list-supported") Maybe others work too (please report USB VID and PID so I can include support for further models, too). @@ -16,9 +16,7 @@ https://familie-radermacher.ch/dominic/projekte/ptouch-print/ Compile instructions: -./autogen.sh -./configure --prefix=/usr -make +./build.sh Note: diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 7dcf161..0000000 --- a/autogen.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -rm -rf autom4te.cache configure config.* -autoreconf --install || exit 1 diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen deleted file mode 100755 index 23afd31..0000000 --- a/build-aux/git-version-gen +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -GIT_VERSION=$(git --no-pager describe --always --tags --dirty |sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//g') -echo -ne ${GIT_VERSION} diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..928809f --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +mkdir -p build && cd build && cmake ../ && make diff --git a/cmake/FindGD.cmake b/cmake/FindGD.cmake new file mode 100644 index 0000000..d9723a0 --- /dev/null +++ b/cmake/FindGD.cmake @@ -0,0 +1,121 @@ +# - Find GD +# Find the native GD includes and library +# This module defines +# GD_INCLUDE_DIR, where to find gd.h, etc. +# GD_LIBRARIES, the libraries needed to use GD. +# GD_FOUND, If false, do not try to use GD. +# also defined, but not for general use are +# GD_LIBRARY, where to find the GD library. +# GD_SUPPORTS_PNG, GD_SUPPORTS_JPEG, GD_SUPPORTS_GIF, test +# support for image formats in GD. + +FIND_PATH(GD_INCLUDE_DIR gd.h + /usr/local/include + /usr/include +) + +if(WIN32 AND NOT CYGWIN) + SET(GD_NAMES ${GD_NAMES} bgd) +else(WIN32) + SET(GD_NAMES ${GD_NAMES} gd) +endif(WIN32 AND NOT CYGWIN) + +FIND_LIBRARY(GD_LIBRARY + NAMES ${GD_NAMES} + PATHS /usr/lib64 /usr/lib /usr/local/lib +) + +IF (GD_LIBRARY AND GD_INCLUDE_DIR) + SET(GD_LIBRARIES ${GD_LIBRARY}) + SET(GD_FOUND "YES") +ELSE (GD_LIBRARY AND GD_INCLUDE_DIR) + SET(GD_FOUND "NO") +ENDIF (GD_LIBRARY AND GD_INCLUDE_DIR) +message("Found GD: ${GD_FOUND}") +IF (GD_FOUND) + IF (WIN32 AND NOT CYGWIN) + SET(GD_SUPPORTS_PNG ON) + SET(GD_SUPPORTS_JPEG ON) + SET(GD_SUPPORTS_GIF ON) + get_filename_component(GD_LIBRARY_DIR ${GD_LIBRARY} PATH) + ELSE (WIN32 AND NOT CYGWIN) + INCLUDE(CheckLibraryExists) + GET_FILENAME_COMPONENT(GD_LIB_PATH ${GD_LIBRARY} PATH) + GET_FILENAME_COMPONENT(GD_LIB ${GD_LIBRARY} NAME) + + CHECK_LIBRARY_EXISTS("${GD_LIBRARY}" "gdImagePng" "${GD_LIB_PATH}" GD_SUPPORTS_PNG) + IF (GD_SUPPORTS_PNG) + find_package(PNG) + IF (PNG_FOUND) + SET(GD_LIBRARIES ${GD_LIBRARIES} ${PNG_LIBRARIES}) + SET(GD_INCLUDE_DIR ${GD_INCLUDE_DIR} ${PNG_INCLUDE_DIR}) + ELSE (PNG_FOUND) + SET(GD_SUPPORTS_PNG "NO") + ENDIF (PNG_FOUND) + ENDIF (GD_SUPPORTS_PNG) + + CHECK_LIBRARY_EXISTS("${GD_LIBRARY}" "gdImageJpeg" "${GD_LIB_PATH}" GD_SUPPORTS_JPEG) + IF (GD_SUPPORTS_JPEG) + find_package(JPEG) + IF (JPEG_FOUND) + SET(GD_LIBRARIES ${GD_LIBRARIES} ${JPEG_LIBRARIES}) + SET(GD_INCLUDE_DIR ${GD_INCLUDE_DIR} ${JPEG_INCLUDE_DIR}) + ELSE (JPEG_FOUND) + SET(GD_SUPPORTS_JPEG "NO") + ENDIF (JPEG_FOUND) + ENDIF (GD_SUPPORTS_JPEG) + + CHECK_LIBRARY_EXISTS("${GD_LIBRARY}" "gdImageGif" "${GD_LIB_PATH}" GD_SUPPORTS_GIF) + + # Trim the list of include directories + SET(GDINCTRIM) + FOREACH(GD_DIR ${GD_INCLUDE_DIR}) + SET(GD_TMP_FOUND OFF) + FOREACH(GD_TRIMMED ${GDINCTRIM}) + IF ("${GD_DIR}" STREQUAL "${GD_TRIMMED}") + SET(GD_TMP_FOUND ON) + ENDIF ("${GD_DIR}" STREQUAL "${GD_TRIMMED}") + ENDFOREACH(GD_TRIMMED ${GDINCTRIM}) + IF (NOT GD_TMP_FOUND) + SET(GDINCTRIM "${GDINCTRIM}" "${GD_DIR}") + ENDIF (NOT GD_TMP_FOUND) + ENDFOREACH(GD_DIR ${GD_INCLUDE_DIR}) + SET(GD_INCLUDE_DIR ${GDINCTRIM}) + + SET(GD_LIBRARY_DIR) + + # Generate trimmed list of library directories and list of libraries + FOREACH(GD_LIB ${GD_LIBRARIES}) + GET_FILENAME_COMPONENT(GD_NEXTLIBDIR ${GD_LIB} PATH) + SET(GD_TMP_FOUND OFF) + FOREACH(GD_LIBDIR ${GD_LIBRARY_DIR}) + IF ("${GD_NEXTLIBDIR}" STREQUAL "${GD_LIBDIR}") + SET(GD_TMP_FOUND ON) + ENDIF ("${GD_NEXTLIBDIR}" STREQUAL "${GD_LIBDIR}") + ENDFOREACH(GD_LIBDIR ${GD_LIBRARIES}) + IF (NOT GD_TMP_FOUND) + SET(GD_LIBRARY_DIR "${GD_LIBRARY_DIR}" "${GD_NEXTLIBDIR}") + ENDIF (NOT GD_TMP_FOUND) + ENDFOREACH(GD_LIB ${GD_LIBRARIES}) + ENDIF (WIN32 AND NOT CYGWIN) +ENDIF (GD_FOUND) + +IF (GD_FOUND) + IF (NOT GD_FIND_QUIETLY) + MESSAGE(STATUS "Found GD: ${GD_LIBRARY}") + ENDIF (NOT GD_FIND_QUIETLY) +ELSE (GD_FOUND) + IF (GD_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find GD library") + ENDIF (GD_FIND_REQUIRED) +ENDIF (GD_FOUND) + +MARK_AS_ADVANCED( + GD_LIBRARY + GD_LIBRARIES + GD_INCLUDE_DIR + GD_LIBRARY_DIR + GD_SUPPORTS_PNG + GD_SUPPORTS_JPEG + GD_SUPPORTS_GIF +) diff --git a/cmake/gitversion.cmake b/cmake/gitversion.cmake new file mode 100644 index 0000000..5854a7f --- /dev/null +++ b/cmake/gitversion.cmake @@ -0,0 +1,50 @@ +# Get commit hash +execute_process(COMMAND git log --format='%H' -n 1 + OUTPUT_VARIABLE GIT_COMMIT_HASH + ERROR_QUIET) +# Check whether we got any revision (which isn't always the case, e.g. when +# someone downloaded a zip file instead of a checkout) +if ("${GIT_COMMIT_HASH}" STREQUAL "") + set(GIT_BRANCH "N/A") + set(GIT_COMMITS "") + set(GIT_COMMIT_HASH "N/A") + set(GIT_COMMIT_SHORT "N/A") + set(GIT_DIFF "") + set(GIT_TAG "N/A") +else() + execute_process(COMMAND + bash -c "git diff --quiet --exit-code || echo +" + OUTPUT_VARIABLE GIT_DIFF) + execute_process(COMMAND + bash -c "git describe --always --tags |cut -f1 -d'-'" + OUTPUT_VARIABLE GIT_TAG ERROR_QUIET) + execute_process(COMMAND + bash -c "git describe --always --tags |cut -f2 -d'-'" + OUTPUT_VARIABLE GIT_COMMITS ERROR_QUIET) + execute_process(COMMAND + git rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE GIT_BRANCH) + string(STRIP "${GIT_COMMIT_HASH}" GIT_COMMIT_HASH) + string(SUBSTRING "${GIT_COMMIT_HASH}" 1 7 GIT_COMMIT_SHORT) + string(STRIP "${GIT_BRANCH}" GIT_BRANCH) + string(STRIP "${GIT_COMMITS}" GIT_COMMITS) + string(STRIP "${GIT_DIFF}" GIT_DIFF) + string(STRIP "${GIT_TAG}" GIT_TAG) +endif() + +set(VERSION "const char* GIT_BRANCH=\"${GIT_BRANCH}\"; +const char* GIT_COMMIT=\"${GIT_COMMIT_SHORT}\"; +const char* GIT_COMMITS=\"${GIT_COMMITS}\"; +const char* GIT_TAG=\"${GIT_TAG}\"; +const char* VERSION=\"${GIT_TAG}-r${GIT_COMMITS}-g${GIT_COMMIT_SHORT}${GIT_DIFF}\"; +") + +message(DEBUG "Generated Version: \"${VERSION}\"") +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.h) + file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.h VERSION_) +else() + set(VERSION_ "") +endif() +if (NOT "${VERSION}" STREQUAL "${VERSION_}") + file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/version.h" "${VERSION}") +endif() diff --git a/configure.ac b/configure.ac deleted file mode 100644 index ddc2f3e..0000000 --- a/configure.ac +++ /dev/null @@ -1,52 +0,0 @@ -# -# ptouch-print - Print labels with images or text on a Brother P-Touch -# -# Copyright (C) 2015-2021 Dominic Radermacher -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 3 as -# published by the Free Software Foundation -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -AC_PREREQ([2.69]) -AC_INIT([ptouch], [m4_esyscmd_s([build-aux/git-version-gen])], [dominic@familie-radermacher.ch]) -AC_CONFIG_SRCDIR([src/libptouch.c]) -AC_CONFIG_HEADERS([config.h]) - -# Checks for programs. -AC_PROG_CC -AC_PROG_INSTALL -AM_INIT_AUTOMAKE -AM_GNU_GETTEXT([external]) -AM_GNU_GETTEXT_VERSION(0.19) - -# Checks for libraries. -AC_CHECK_LIB([gd], [gdImageStringFT]) -AC_CHECK_LIB([usb-1.0], [libusb_init]) - -# Checks for header files. -AC_CHECK_HEADERS([fcntl.h libintl.h stdint.h stdlib.h string.h]) -AC_CHECK_HEADERS([gd.h], [], [AC_MSG_ERROR([libgd headers missing - maybe you need to install package libgd-dev, gd-dev or gd-devel?])]) -AC_CHECK_HEADERS([libusb-1.0/libusb.h], [], [AC_MSG_ERROR([libusb headers missing - maybe you need to install package libusb-dev, libusb-devel or libusb-1.0-0-dev?])]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_TYPE_SSIZE_T -AC_TYPE_UINT8_T - -# Checks for library functions. -AC_FUNC_MALLOC -AC_CHECK_FUNCS([memset setlocale strpbrk strtol]) - -AC_CONFIG_FILES([Makefile po/Makefile.in]) -AC_OUTPUT diff --git a/src/libptouch.c b/src/libptouch.c index 1647628..51fa814 100644 --- a/src/libptouch.c +++ b/src/libptouch.c @@ -26,7 +26,7 @@ #include /* open() */ #include /* open() */ #include /* nanosleep(), struct timespec */ -#include "config.h" + #include "gettext.h" /* gettext(), ngettext() */ #include "ptouch.h" diff --git a/src/ptouch-print.c b/src/ptouch-print.c index 1e7ef5b..daff4ee 100644 --- a/src/ptouch-print.c +++ b/src/ptouch-print.c @@ -25,7 +25,10 @@ #include /* open() */ #include /* open() */ #include -#include "config.h" +#include +#include /* LC_ALL */ + +#include "version.h" #include "gettext.h" /* gettext(), ngettext() */ #include "ptouch.h" @@ -467,8 +470,8 @@ int main(int argc, char *argv[]) ptouch_dev ptdev=NULL; setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); + bindtextdomain("ptouch-print", "/usr/share/locale/"); + textdomain("ptouch-print"); i=parse_args(argc, argv); if (i != argc) { usage(argv[0]);