1
0
mirror of https://git.familie-radermacher.ch/linux/ptouch-print.git synced 2025-05-13 15:22:56 +00:00

merge with branch cmake - build system is now cmake

This commit is contained in:
Dominic Radermacher 2021-10-11 10:18:49 +02:00
commit e3c0073466
15 changed files with 251 additions and 155 deletions

42
.gitignore vendored
View File

@ -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

View File

@ -1,2 +0,0 @@
ptouch-print written by Dominic Radermacher <dominic@familie-radermacher.ch>

65
CMakeLists.txt Normal file
View File

@ -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)

View File

@ -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

View File

@ -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

2
NEWS
View File

@ -1,2 +0,0 @@
See ChangeLog

10
README
View File

@ -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:

View File

@ -1,3 +0,0 @@
#!/bin/sh
rm -rf autom4te.cache configure config.*
autoreconf --install || exit 1

View File

@ -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}

2
build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
mkdir -p build && cd build && cmake ../ && make

121
cmake/FindGD.cmake Normal file
View File

@ -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
)

50
cmake/gitversion.cmake Normal file
View File

@ -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()

View File

@ -1,52 +0,0 @@
#
# ptouch-print - Print labels with images or text on a Brother P-Touch
#
# Copyright (C) 2015-2021 Dominic Radermacher <dominic@familie-radermacher.ch>
#
# 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

View File

@ -26,7 +26,7 @@
#include <sys/stat.h> /* open() */
#include <fcntl.h> /* open() */
#include <time.h> /* nanosleep(), struct timespec */
#include "config.h"
#include "gettext.h" /* gettext(), ngettext() */
#include "ptouch.h"

View File

@ -25,7 +25,10 @@
#include <sys/stat.h> /* open() */
#include <fcntl.h> /* open() */
#include <gd.h>
#include "config.h"
#include <libintl.h>
#include <locale.h> /* 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]);