pdfio/Makefile

169 lines
4.4 KiB
Makefile
Raw Normal View History

2021-04-10 14:00:52 +02:00
#
# Makefile for PDFio.
2021-04-10 14:00:52 +02:00
#
# Copyright © 2021 by Michael R Sweet.
#
# Licensed under Apache License v2.0. See the file "LICENSE" for more
# information.
#
# POSIX makefile
.POSIX:
# Variables...
AR = ar
ARFLAGS = cr
CC = cc
CFLAGS =
CODESIGN_IDENTITY = Developer ID
COMMONFLAGS = -Os -g
2021-07-07 02:31:30 +02:00
CPPFLAGS = '-DPDFIO_VERSION="$(VERSION)"'
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
2021-07-24 19:08:46 +02:00
VERSION = 1.0b1
2021-04-10 14:00:52 +02:00
prefix = /usr/local
# Base rules
.SUFFIXES: .c .h .o
.c.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(COMMONFLAGS) -c $<
# Files
2021-07-18 16:01:43 +02:00
PUBHEADERS = \
pdfio.h \
pdfio-content.h
PUBOBJS = \
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-04-17 02:41:46 +02:00
pdfio-dict.o \
pdfio-file.o \
pdfio-object.o \
pdfio-page.o \
pdfio-stream.o \
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) \
ttf.o
2021-04-10 14:00:52 +02:00
OBJS = \
$(LIBOBJS) \
testpdfio.o
TARGETS = \
$(DSONAME) \
libpdfio.a \
testpdfio
# Make everything
all: $(TARGETS)
all-shared:
if test `uname` = Darwin; then \
$(MAKE) DSONAME="libpdfio.1.dylib" -$(MAKEFLAGS) all; \
else
$(MAKE) DSONAME="libpdfio.so.1" -$(MAKEFLAGS) all; \
fi
debug:
$(MAKE) -$(MAKEFLAGS) COMMONFLAGS="-g -fsanitize=address -DDEBUG=1" clean all
2021-04-10 14:00:52 +02:00
# Clean everything
clean:
rm -f $(TARGETS) $(OBJS)
# Install everything
install: $(TARGETS)
-mkdir -p $(DESTDIR)$(prefix)/include
2021-07-18 16:01:43 +02:00
cp $(PUBHEADERS) $(DESTDIR)$(prefix)/include
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
-mkdir -p $(DESTDIR)$(prefix)/lib/pkgconfig
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
-mkdir -p $(DESTDIR)$(prefix)/share/doc/pdfio
cp doc/pdfio.html doc/pdfio-512.png LICENSE NOTICE $(DESTDIR)$(prefix)/share/doc/pdfio
2021-04-10 14:00:52 +02:00
-mkdir -p $(DESTDIR)$(prefix)/share/man/man3
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; \
else
$(MAKE) DSONAME="libpdfio.so.1" -$(MAKEFLAGS) install; \
fi
# Test everything
test: testpdfio
./testpdfio
# pdfio library
libpdfio.a: $(LIBOBJS)
$(AR) $(ARFLAGS) $@ $(LIBOBJS)
$(RANLIB) $@
libpdfio.so.1: $(LIBOBJS)
$(CC) $(DSOFLAGS) $(COMMONFLAGS) -shared -o $@ -Wl,soname,$@ $(LIBOBJS) $(LIBS)
libpdfio.1.dylib: $(LIBOBJS)
$(CC) $(DSOFLAGS) $(COMMONFLAGS) -dynamiclib -o $@ -install_name $(prefix)/lib/$@ -current_version $(VERSION) -compatibility_version 1.0 $(LIBOBJS) $(LIBS)
# pdfio test program
2021-05-25 01:33:40 +02:00
testpdfio: testpdfio.o libpdfio.a
2021-04-10 14:00:52 +02:00
$(CC) $(LDFLAGS) $(COMMONFLAGS) -o $@ testpdfio.o libpdfio.a $(LIBS)
# Dependencies
2021-05-25 01:33:40 +02:00
$(OBJS): pdfio.h Makefile
$(LIBOBJS): pdfio-private.h
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" \
--copyright "Copyright (c) 2021 by Michael R Sweet" \
--docversion $(VERSION)
.PHONY: doc
2021-04-10 14:00:52 +02:00
doc:
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
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
# 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