2021-04-10 14:00:52 +02:00
|
|
|
|
#
|
2021-05-30 13:10:44 +02:00
|
|
|
|
# Makefile for PDFio.
|
2021-04-10 14:00:52 +02:00
|
|
|
|
#
|
2023-02-04 02:39:04 +01:00
|
|
|
|
# Copyright © 2021-2023 by Michael R Sweet.
|
2021-04-10 14:00:52 +02:00
|
|
|
|
#
|
|
|
|
|
# Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
# information.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# POSIX makefile
|
|
|
|
|
.POSIX:
|
|
|
|
|
|
2022-08-02 15:41:13 +02:00
|
|
|
|
# Build silently
|
|
|
|
|
.SILENT:
|
|
|
|
|
|
|
|
|
|
# Variables
|
2021-04-10 14:00:52 +02:00
|
|
|
|
AR = ar
|
|
|
|
|
ARFLAGS = cr
|
|
|
|
|
CC = cc
|
|
|
|
|
CFLAGS =
|
|
|
|
|
CODESIGN_IDENTITY = Developer ID
|
2021-11-29 23:57:49 +01:00
|
|
|
|
COMMONFLAGS = -Os -g
|
|
|
|
|
#COMMONFLAGS = -O0 -g -fsanitize=address
|
2023-10-06 20:38:38 +02:00
|
|
|
|
CPPFLAGS =
|
2021-04-10 14:00:52 +02:00
|
|
|
|
DESTDIR = $(DSTROOT)
|
|
|
|
|
DSO = cc
|
2021-07-07 02:31:30 +02:00
|
|
|
|
DSOFLAGS =
|
2021-04-10 14:00:52 +02:00
|
|
|
|
DSONAME =
|
|
|
|
|
LDFLAGS =
|
2021-05-30 16:27:00 +02:00
|
|
|
|
LIBS = -lm -lz
|
2021-04-10 14:00:52 +02:00
|
|
|
|
RANLIB = ranlib
|
2023-10-02 11:06:33 +02:00
|
|
|
|
VERSION = 1.1.2
|
2021-04-10 14:00:52 +02:00
|
|
|
|
prefix = /usr/local
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Base rules
|
|
|
|
|
.SUFFIXES: .c .h .o
|
|
|
|
|
.c.o:
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Compiling $<...
|
2021-04-10 14:00:52 +02:00
|
|
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) $(COMMONFLAGS) -c $<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Files
|
2021-07-18 16:01:43 +02:00
|
|
|
|
PUBHEADERS = \
|
|
|
|
|
pdfio.h \
|
|
|
|
|
pdfio-content.h
|
|
|
|
|
PUBOBJS = \
|
2021-10-09 16:49:22 +02:00
|
|
|
|
pdfio-aes.o \
|
2021-04-17 02:41:46 +02:00
|
|
|
|
pdfio-array.o \
|
2021-04-10 14:00:52 +02:00
|
|
|
|
pdfio-common.o \
|
2021-05-25 01:33:40 +02:00
|
|
|
|
pdfio-content.o \
|
2021-10-05 03:13:01 +02:00
|
|
|
|
pdfio-crypto.o \
|
2021-04-17 02:41:46 +02:00
|
|
|
|
pdfio-dict.o \
|
|
|
|
|
pdfio-file.o \
|
2021-10-05 03:13:01 +02:00
|
|
|
|
pdfio-md5.o \
|
2021-04-17 02:41:46 +02:00
|
|
|
|
pdfio-object.o \
|
|
|
|
|
pdfio-page.o \
|
2021-10-05 03:13:01 +02:00
|
|
|
|
pdfio-rc4.o \
|
2021-10-09 00:55:25 +02:00
|
|
|
|
pdfio-sha256.o \
|
2021-04-17 02:41:46 +02:00
|
|
|
|
pdfio-stream.o \
|
2021-04-25 17:28:56 +02:00
|
|
|
|
pdfio-string.o \
|
2021-05-01 23:50:52 +02:00
|
|
|
|
pdfio-token.o \
|
2021-07-18 16:01:43 +02:00
|
|
|
|
pdfio-value.o
|
|
|
|
|
LIBOBJS = \
|
|
|
|
|
$(PUBOBJS) \
|
2021-06-17 16:18:55 +02:00
|
|
|
|
ttf.o
|
2021-04-10 14:00:52 +02:00
|
|
|
|
OBJS = \
|
|
|
|
|
$(LIBOBJS) \
|
2022-02-28 21:00:25 +01:00
|
|
|
|
pdfiototext.o \
|
2021-04-10 14:00:52 +02:00
|
|
|
|
testpdfio.o
|
|
|
|
|
TARGETS = \
|
|
|
|
|
$(DSONAME) \
|
|
|
|
|
libpdfio.a \
|
2022-02-28 21:00:25 +01:00
|
|
|
|
pdfiototext \
|
2021-04-10 14:00:52 +02:00
|
|
|
|
testpdfio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Make everything
|
|
|
|
|
all: $(TARGETS)
|
|
|
|
|
|
|
|
|
|
all-shared:
|
|
|
|
|
if test `uname` = Darwin; then \
|
|
|
|
|
$(MAKE) DSONAME="libpdfio.1.dylib" -$(MAKEFLAGS) all; \
|
2021-10-13 23:15:59 +02:00
|
|
|
|
else \
|
|
|
|
|
$(MAKE) COMMONFLAGS="-g -Os -fPIC" DSONAME="libpdfio.so.1" -$(MAKEFLAGS) all; \
|
2021-04-10 14:00:52 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2021-05-04 18:59:10 +02:00
|
|
|
|
debug:
|
2021-05-05 03:31:58 +02:00
|
|
|
|
$(MAKE) -$(MAKEFLAGS) COMMONFLAGS="-g -fsanitize=address -DDEBUG=1" clean all
|
2021-05-04 18:59:10 +02:00
|
|
|
|
|
2022-03-02 15:30:01 +01:00
|
|
|
|
macos:
|
2023-10-06 20:38:38 +02:00
|
|
|
|
$(MAKE) -$(MAKEFLAGS) COMMONFLAGS="-Os -mmacosx-version-min=11 -arch x86_64 -arch arm64" clean all
|
2022-03-02 15:30:01 +01:00
|
|
|
|
|
2021-04-10 14:00:52 +02:00
|
|
|
|
|
|
|
|
|
# Clean everything
|
|
|
|
|
clean:
|
|
|
|
|
rm -f $(TARGETS) $(OBJS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Install everything
|
|
|
|
|
install: $(TARGETS)
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Installing header files to $(DESTDIR)$(prefix)/include...
|
2021-04-10 14:00:52 +02:00
|
|
|
|
-mkdir -p $(DESTDIR)$(prefix)/include
|
2021-07-18 16:01:43 +02:00
|
|
|
|
cp $(PUBHEADERS) $(DESTDIR)$(prefix)/include
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Installing library files to $(DESTDIR)$(prefix)/lib...
|
2021-04-10 14:00:52 +02:00
|
|
|
|
-mkdir -p $(DESTDIR)$(prefix)/lib
|
|
|
|
|
cp libpdfio.a $(DESTDIR)$(prefix)/lib
|
|
|
|
|
$(RANLIB) $(DESTDIR)$(prefix)/lib/libpdfio.a
|
|
|
|
|
if test "x$(DSONAME)" = xlibpdfio.so.1; then \
|
|
|
|
|
cp $(DSONAME) $(DESTDIR)$(prefix)/lib; \
|
|
|
|
|
ln -sf libpdfio.so.1 $(DESTDIR)$(prefix)/lib/libpdfio.so; \
|
|
|
|
|
elif test "x$(DSONAME)" = xlibpdfio.1.dylib; then \
|
|
|
|
|
cp $(DSONAME) $(DESTDIR)$(prefix)/lib; \
|
|
|
|
|
codesign -s "$(CODESIGN_IDENTITY)" -o runtime --timestamp $(DESTDIR)$(prefix)/lib/libpdfio.1.dylib; \
|
|
|
|
|
ln -sf libpdfio.1.dylib $(DESTDIR)$(prefix)/lib/libpdfio.dylib; \
|
|
|
|
|
fi
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Installing pkg-config files to $(DESTDIR)$(prefix)/lib/pkgconfig...
|
2021-04-10 14:00:52 +02:00
|
|
|
|
-mkdir -p $(DESTDIR)$(prefix)/lib/pkgconfig
|
2021-05-30 13:10:44 +02:00
|
|
|
|
echo 'prefix="$(prefix)"' >$(DESTDIR)$(prefix)/lib/pkgconfig/pdfio.pc
|
|
|
|
|
echo 'Version: $(VERSION)' >>$(DESTDIR)$(prefix)/lib/pkgconfig/pdfio.pc
|
|
|
|
|
cat pdfio.pc.in >>$(DESTDIR)$(prefix)/lib/pkgconfig/pdfio.pc
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Installing documentation to $(DESTDIR)$(prefix)/share/doc/pdfio...
|
2021-04-10 14:06:37 +02:00
|
|
|
|
-mkdir -p $(DESTDIR)$(prefix)/share/doc/pdfio
|
2021-05-30 13:10:44 +02:00
|
|
|
|
cp doc/pdfio.html doc/pdfio-512.png LICENSE NOTICE $(DESTDIR)$(prefix)/share/doc/pdfio
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Installing man page to $(DESTDIR)$(prefix)/share/man/man3...
|
2021-04-10 14:00:52 +02:00
|
|
|
|
-mkdir -p $(DESTDIR)$(prefix)/share/man/man3
|
2021-05-30 13:10:44 +02:00
|
|
|
|
cp doc/pdfio.3 $(DESTDIR)$(prefix)/share/man/man3
|
2021-04-10 14:00:52 +02:00
|
|
|
|
|
|
|
|
|
install-shared:
|
|
|
|
|
if test `uname` = Darwin; then \
|
|
|
|
|
$(MAKE) DSONAME="libpdfio.1.dylib" -$(MAKEFLAGS) install; \
|
2022-06-09 06:33:53 +02:00
|
|
|
|
else \
|
2021-04-10 14:00:52 +02:00
|
|
|
|
$(MAKE) DSONAME="libpdfio.so.1" -$(MAKEFLAGS) install; \
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test everything
|
|
|
|
|
test: testpdfio
|
2023-10-07 18:05:18 +02:00
|
|
|
|
./testpdfio 2>test.log
|
2021-04-10 14:00:52 +02:00
|
|
|
|
|
2021-10-16 06:02:31 +02:00
|
|
|
|
valgrind: testpdfio
|
|
|
|
|
valgrind --leak-check=full ./testpdfio
|
|
|
|
|
|
2021-04-10 14:00:52 +02:00
|
|
|
|
|
|
|
|
|
# pdfio library
|
|
|
|
|
libpdfio.a: $(LIBOBJS)
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Archiving $@...
|
2021-04-10 14:00:52 +02:00
|
|
|
|
$(AR) $(ARFLAGS) $@ $(LIBOBJS)
|
|
|
|
|
$(RANLIB) $@
|
|
|
|
|
|
|
|
|
|
libpdfio.so.1: $(LIBOBJS)
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Linking $@...
|
2021-10-16 01:32:08 +02:00
|
|
|
|
$(CC) $(DSOFLAGS) $(COMMONFLAGS) -shared -o $@ -Wl,-soname,$@ $(LIBOBJS) $(LIBS)
|
2021-04-10 14:00:52 +02:00
|
|
|
|
|
|
|
|
|
libpdfio.1.dylib: $(LIBOBJS)
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Linking $@...
|
2021-04-10 14:00:52 +02:00
|
|
|
|
$(CC) $(DSOFLAGS) $(COMMONFLAGS) -dynamiclib -o $@ -install_name $(prefix)/lib/$@ -current_version $(VERSION) -compatibility_version 1.0 $(LIBOBJS) $(LIBS)
|
|
|
|
|
|
|
|
|
|
|
2021-07-26 17:18:36 +02:00
|
|
|
|
# pdfio1.def (Windows DLL exports file...)
|
|
|
|
|
#
|
|
|
|
|
# I'd love to use __declspec(dllexport) but MS puts it before the function
|
|
|
|
|
# declaration instead of after like everyone else, and it breaks Codedoc and
|
|
|
|
|
# other tools I rely on...
|
|
|
|
|
pdfio1.def: $(LIBOBJS) Makefile
|
|
|
|
|
echo Generating $@...
|
|
|
|
|
echo "LIBRARY pdfio1" >$@
|
|
|
|
|
echo "VERSION 1.0" >>$@
|
|
|
|
|
echo "EXPORTS" >>$@
|
2021-10-26 03:39:44 +02:00
|
|
|
|
nm $(LIBOBJS) 2>/dev/null | grep "T _" | awk '{print $$3}' | \
|
|
|
|
|
grep -v '^_ttf' | sed -e '1,$$s/^_//' | sort >>$@
|
2021-07-26 17:18:36 +02:00
|
|
|
|
|
|
|
|
|
|
2022-03-02 15:30:01 +01:00
|
|
|
|
# pdfio text extraction (demo, doesn't handle a lot of things yet)
|
2022-02-28 21:00:25 +01:00
|
|
|
|
pdfiototext: pdfiototext.o libpdfio.a
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Linking $@...
|
2022-02-28 21:00:25 +01:00
|
|
|
|
$(CC) $(LDFLAGS) $(COMMONFLAGS) -o $@ pdfiototext.o libpdfio.a $(LIBS)
|
|
|
|
|
|
|
|
|
|
|
2021-04-10 14:00:52 +02:00
|
|
|
|
# pdfio test program
|
2021-05-25 01:33:40 +02:00
|
|
|
|
testpdfio: testpdfio.o libpdfio.a
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Linking $@...
|
2021-04-10 14:00:52 +02:00
|
|
|
|
$(CC) $(LDFLAGS) $(COMMONFLAGS) -o $@ testpdfio.o libpdfio.a $(LIBS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Dependencies
|
2021-11-29 23:57:49 +01:00
|
|
|
|
$(OBJS): pdfio.h pdfio-private.h Makefile
|
2021-06-17 16:18:55 +02:00
|
|
|
|
pdfio-content.o: pdfio-content.h ttf.h
|
|
|
|
|
ttf.o: ttf.h
|
2021-04-10 14:00:52 +02:00
|
|
|
|
|
|
|
|
|
# Make documentation using Codedoc <https://www.msweet.org/codedoc>
|
|
|
|
|
DOCFLAGS = \
|
|
|
|
|
--author "Michael R Sweet" \
|
2023-10-06 20:38:38 +02:00
|
|
|
|
--copyright "Copyright (c) 2021-2023 by Michael R Sweet" \
|
2021-04-10 14:00:52 +02:00
|
|
|
|
--docversion $(VERSION)
|
|
|
|
|
|
2021-05-30 13:10:44 +02:00
|
|
|
|
.PHONY: doc
|
2021-04-10 14:00:52 +02:00
|
|
|
|
doc:
|
2022-08-02 15:41:13 +02:00
|
|
|
|
echo Generating documentation...
|
2021-07-18 16:01:43 +02:00
|
|
|
|
codedoc $(DOCFLAGS) --title "PDFio Programming Manual v$(VERSION)" $(PUBHEADERS) $(PUBOBJS:.o=.c) --body doc/pdfio.md --coverimage doc/pdfio-512.png pdfio.xml >doc/pdfio.html
|
2021-09-27 16:02:10 +02:00
|
|
|
|
codedoc $(DOCFLAGS) --title "PDFio Programming Manual v$(VERSION)" --body doc/pdfio.md --coverimage doc/pdfio-epub.png pdfio.xml --epub doc/pdfio.epub
|
2021-05-30 13:10:44 +02:00
|
|
|
|
codedoc $(DOCFLAGS) --title "pdf read/write library" --man pdfio --section 3 --body doc/pdfio.md pdfio.xml >doc/pdfio.3
|
2021-04-10 14:00:52 +02:00
|
|
|
|
rm -f pdfio.xml
|
2021-05-30 18:51:26 +02:00
|
|
|
|
|
|
|
|
|
|
2021-11-30 02:59:30 +01:00
|
|
|
|
# Fuzz-test the library <>
|
|
|
|
|
.PHONY: afl
|
|
|
|
|
afl:
|
2021-11-30 14:13:41 +01:00
|
|
|
|
$(MAKE) -$(MAKEFLAGS) CC="afl-clang-fast" COMMONFLAGS="-g" clean all
|
|
|
|
|
test afl-output || rm -rf afl-output
|
2021-11-30 02:59:30 +01:00
|
|
|
|
afl-fuzz -x afl-pdf.dict -i afl-input -o afl-output -V 600 -e pdf -t 5000 ./testpdfio @@
|
|
|
|
|
|
|
|
|
|
|
2021-05-30 18:51:26 +02:00
|
|
|
|
# Analyze code with the Clang static analyzer <https://clang-analyzer.llvm.org>
|
|
|
|
|
clang:
|
|
|
|
|
clang $(CPPFLAGS) --analyze $(OBJS:.o=.c) 2>clang.log
|
|
|
|
|
rm -rf $(OBJS:.o=.plist)
|
|
|
|
|
test -s clang.log && (echo "$(GHA_ERROR)Clang detected issues."; echo ""; cat clang.log; exit 1) || exit 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Analyze code using Cppcheck <http://cppcheck.sourceforge.net>
|
|
|
|
|
cppcheck:
|
|
|
|
|
cppcheck $(CPPFLAGS) --template=gcc --addon=cert.py --suppressions-list=.cppcheck $(OBJS:.o=.c) 2>cppcheck.log
|
|
|
|
|
test -s cppcheck.log && (echo "$(GHA_ERROR)Cppcheck detected issues."; echo ""; cat cppcheck.log; exit 1) || exit 0
|