view Makefile @ 13:2bb1bbac1d0a default tip

Added tag version-1.0.0 for changeset 1926dfc9feb0
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Sun, 04 Aug 2019 21:37:56 +0200
parents 0feba0fea9d0
children
line wrap: on
line source

#
# Copyright (C) 2015 Guido Berhoerster <guido+libpws@berhoerster.name>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

PACKAGE =	libpws
VERSION =	1.0.0
DISTNAME :=	$(PACKAGE)-$(VERSION)

# gcc, clang, icc, Sun/Solaris Studio
CC :=		$(CC) -std=c99
COMPILE.c =	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(TARGET_ARCH) -c
# gcc, clang, icc
MAKEDEPEND.c =	$(CC) -MM $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
# Sun/Solaris Studio
#MAKEDEPEND.c =	$(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
# X makedepend
#MAKEDEPEND.c =	makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
LINK.c =	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
LINK.o =	$(CC) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
AR :=		ar
RANLIB :=	ranlib
INSTALL :=	install
INSTALL.exec :=	$(INSTALL) -D -m 0755
INSTALL.lib :=	$(INSTALL) -D -m 0644
INSTALL.data :=	$(INSTALL) -D -m 0644
PAX :=		pax
GZIP :=		gzip
SED :=		sed
XSLTPROC :=	xsltproc
DOCBOOK5_MANPAGES_STYLESHEET =	http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
DOCBOOK5_MANPAGES_FLAGS =	--stringparam funcsynopsis.style 'ansi' \
				--stringparam man.authors.section.enabled 0 \
				--stringparam man.copyright.section.enabled 0
DOCBOOK5_XHTML_STYLESHEET =	http://docbook.sourceforge.net/release/xsl-ns/current/xhtml/docbook.xsl
DOCBOOK5_XHTML_FLAGS =		--stringparam funcsynopsis.style 'ansi' \
				--stringparam generate.consistent.ids 1 \
				--stringparam refentry.generate.name 1 \
				--stringparam refentry.generate.title 0 \
				--stringparam refentry.xref.manvolnum 1 \
				--stringparam generate.id.attributes 1 \
				--stringparam make.valid.html 1 \
				--stringparam make.clean.html 1 \
				--stringparam html.cleanup 1 \
				--stringparam html.longdesc 0 \
				--stringparam ulink.target '' \
				--stringparam docbook.css.source '' \
				--stringparam css.decoration 0 \
				--stringparam default.table.width '100%'

TESTS_OUTPUT_PATH = ./tests/output

define generate-manpage-rule =
$(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl
	$$(XSLTPROC) \
	    --xinclude \
	    --stringparam package $$(PACKAGE) \
	    --stringparam version $$(VERSION) \
	    docbook-update-source-data.xsl $$< | \
	    $$(XSLTPROC) \
	    --xinclude \
	    --output $(firstword $1) \
	    $$(DOCBOOK5_MANPAGES_FLAGS) \
	    $$(DOCBOOK5_MANPAGES_STYLESHEET) \
	    -
	$$(SED) 's,^\.HP \\w.*$$$$,.HP 4n,' $$@ >$$(@).tmp && mv $$(@).tmp $$@
	for alias in $(wordlist 2,$(words $1),$1); do \
	    ln -sf $(notdir $(firstword $1)) $$$$alias; \
	done
endef

DESTDIR ?=
prefix ?=	/usr/local
bindir ?=	$(prefix)/bin
libdir ?=	$(prefix)/lib
includedir ?=	$(prefix)/include
datadir ?=	$(prefix)/share

OS_NAME :=	$(shell uname -s)
OS_RELEASE :=	$(shell uname -r)

ifeq ($(OS_NAME),Linux)
  HAVE_ARC4RANDOM ?=	0
  HAVE_ENDIAN_H ?=	1
  HAVE_SYS_ENDIAN_H ?=	0
  HAVE_ERR_H ?=		1
  HAVE_GETENTROPY ?=	0
  HAVE_GETLINE ?=	0
  HAVE_SETPROGNAME ?=	0
  HAVE_READPASSPHRASE_H ?= 0
  HAVE_SYS_TREE_H ?=	0
  HAVE_VIS_H ?=		0
else ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly),)
  HAVE_ARC4RANDOM ?=	1
  HAVE_ENDIAN_H ?=	0
  HAVE_SYS_ENDIAN_H ?=	1
  HAVE_ERR_H ?=		1
  HAVE_GETENTROPY ?=	0
  HAVE_GETLINE ?=	1
  HAVE_SETPROGNAME ?=	1
  HAVE_READPASSPHRASE_H ?= 1
  HAVE_SYS_TREE_H ?=	1
  HAVE_VIS_H ?=		1
else ifeq ($(OS_NAME),NetBSD)
  HAVE_ARC4RANDOM ?=	1
  HAVE_ENDIAN_H ?=	0
  HAVE_SYS_ENDIAN_H ?=	1
  HAVE_ERR_H ?=		1
  HAVE_GETENTROPY ?=	0
  HAVE_GETLINE ?=	1
  HAVE_SETPROGNAME ?=	1
  HAVE_READPASSPHRASE_H ?= 0
  HAVE_SYS_TREE_H ?=	1
  HAVE_VIS_H ?=		1
else ifeq ($(OS_NAME),OpenBSD)
  HAVE_ARC4RANDOM ?=	1
  HAVE_ENDIAN_H ?=	0
  HAVE_SYS_ENDIAN_H ?=	1
  HAVE_ERR_H ?=		1
  HAVE_GETENTROPY ?=	1
  HAVE_GETLINE ?=	1
  HAVE_SETPROGNAME ?=	1
  HAVE_READPASSPHRASE_H ?= 1
  HAVE_SYS_TREE_H ?=	1
  HAVE_VIS_H ?=		1
else ifeq ($(OS_NAME),SunOS)
  HAVE_ARC4RANDOM ?=	0
  HAVE_ENDIAN_H ?=	0
  HAVE_SYS_ENDIAN_H ?=	0
  HAVE_GETENTROPY ?=	0
  ifeq ($(OS_RELEASE),5.10)
    HAVE_ERR_H ?=	0
    HAVE_GETLINE ?=	0
  else
    HAVE_ERR_H ?=	1
    HAVE_GETLINE ?=	1
  endif
  HAVE_SETPROGNAME ?=	0
  HAVE_READPASSPHRASE_H ?= 0
  HAVE_SYS_TREE_H ?=	0
  HAVE_VIS_H ?=		0
else
  HAVE_ARC4RANDOM ?=	0
  HAVE_ENDIAN_H ?=	0
  HAVE_SYS_ENDIAN_H ?=	0
  HAVE_ERR_H ?=		0
  HAVE_GETENTROPY ?=	0
  HAVE_GETLINE ?=	0
  HAVE_SETPROGNAME ?=	0
  HAVE_READPASSPHRASE_H ?= 0
  HAVE_SYS_TREE_H ?=	0
  HAVE_VIS_H ?=		0
endif

LIBPWS_OBJS =		pws.o \
			pws-file.o \
			pws-record.o \
			pws-field.o \
			pws-random.o
LIBPWS_LIB =		$(PACKAGE).a
LIBPWS_LIB_MEMBERS =	$(LIBPWS_OBJS:%.o=$(LIBPWS_LIB)(%.o))

PWSDUMP_BIN =		pwsdump
PWSDUMP_OBJS =		pwsdump.o

OBJS =			$(LIBPWS_OBJS) $(PWSDUMP_OBJS)

LIBPWS_MANPAGES =	libpws.3

PWS_INIT_MANPAGES =	pws_init.3 \
			pws_finalize.3 \
			pws_set_alloc_functions.3 \
			pws_generate_uuid.3

PWS3_FILE_CREATE_MANPAGES = pws3_file_create.3 \
			pws3_file_destroy.3 \
			pws3_file_get_error_code.3 \
			pws3_file_get_error_message.3 \
			pws3_file_read_mem.3 \
			pws3_file_read_stream.3 \
			pws3_file_write_mem.3 \
			pws3_file_write_stream.3 \
			pws3_file_set_header_field.3 \
			pws3_file_get_header_field.3 \
			pws3_file_remove_header_field.3 \
			pws3_file_insert_empty_group.3 \
			pws3_file_get_empty_group.3 \
			pws3_file_remove_empty_group.3 \
			pws3_file_first_empty_group.3 \
			pws3_file_last_empty_group.3 \
			pws3_file_next_empty_group.3 \
			pws3_file_prev_empty_group.3 \
			pws3_file_insert_record.3 \
			pws3_file_get_record.3 \
			pws3_file_remove_record.3 \
			pws3_file_first_record.3 \
			pws3_file_last_record.3 \
			pws3_file_next_record.3 \
			pws3_file_prev_record.3 \
			pws3_field_create.3 \
			pws3_field_destroy.3 \
			pws3_field_is_header.3 \
			pws3_field_get_type.3 \
			pws3_field_get_data_type.3 \
			pws3_field_set_uuid.3 \
			pws3_field_set_text.3 \
			pws3_field_set_time.3 \
			pws3_field_set_uint8.3 \
			pws3_field_set_uint16.3 \
			pws3_field_set_uint32.3 \
			pws3_field_set_bytes.3 \
			pws3_field_get_uuid.3 \
			pws3_field_get_text.3 \
			pws3_field_get_time.3 \
			pws3_field_get_uint8.3 \
			pws3_field_get_uint16.3 \
			pws3_field_get_uint32.3 \
			pws3_field_get_bytes.3 \
			pws3_record_create.3 \
			pws3_record_destroy.3 \
			pws3_record_set_field.3 \
			pws3_record_get_field.3 \
			pws3_record_remove_field.3

MANPAGES =		$(LIBPWS_MANPAGES) \
			$(PWS_INIT_MANPAGES) \
			$(PWS3_FILE_CREATE_MANPAGES)

XHTML_DOCUMENTATION =	$(addsuffix .xhtml,$(firstword $(LIBPWS_MANPAGES)) \
			$(firstword $(PWS_INIT_MANPAGES)) \
			$(firstword $(PWS3_FILE_CREATE_MANPAGES)))

.DEFAULT_TARGET = all

.PHONY: all clean clobber dist install check

all: $(PWSDUMP_BIN) $(LIBPWS_LIB) $(MANPAGES)

doc: $(MANPAGES) $(XHTML_DOCUMENTATION)

XCPPFLAGS = -Iinclude
ifeq ($(HAVE_ARC4RANDOM),1)
  XCPPFLAGS +=	-DHAVE_ARC4RANDOM
endif
ifeq ($(HAVE_ENDIAN_H),1)
  XCPPFLAGS +=	-DHAVE_ENDIAN_H
else ifeq ($(HAVE_SYS_ENDIAN_H),1)
  XCPPFLAGS +=	-DHAVE_SYS_ENDIAN_H
else
  LIBPWS_OBJS += compat/endian.o
  PWSDUMP_OBJS += compat/endian.o
endif
ifeq ($(HAVE_ERR_H),1)
  XCPPFLAGS +=	-DHAVE_ERR_H
else
  PWSDUMP_OBJS += compat/err.o
endif
ifeq ($(HAVE_GETENTROPY),1)
  XCPPFLAGS +=	-DHAVE_GETENTROPY
else
  LIBPWS_OBJS += compat/getentropy.o
endif
ifeq ($(HAVE_GETLINE),1)
  XCPPFLAGS +=	-DHAVE_GETLINE
else
  PWSDUMP_OBJS += compat/getline.o
endif
ifeq ($(HAVE_READPASSPHRASE_H),1)
  XCPPFLAGS +=	-DHAVE_READPASSPHRASE_H
else
  PWSDUMP_OBJS += compat/readpassphrase.o
endif
ifeq ($(HAVE_SETPROGNAME),1)
  XCPPFLAGS +=	-DHAVE_SETPROGNAME
else
  PWSDUMP_OBJS += compat/setprogname.o
endif
ifeq ($(HAVE_SYS_TREE_H),1)
  XCPPFLAGS +=	-DHAVE_SYS_TREE_H
endif
ifeq ($(HAVE_VIS_H),1)
  XCPPFLAGS +=	-DHAVE_VIS_H
else
  PWSDUMP_OBJS += compat/vis.o compat/unvis.o
endif
ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
  XCPPFLAGS +=	-I/usr/local/include
  XLDFLAGS +=	-L/usr/local/lib
else ifeq ($(OS_NAME),NetBSD)
  XCPPFLAGS +=	-I/usr/pkg/include
  XLDFLAGS +=	-L/usr/pkg/lib
endif
ifeq ($(OS_NAME),SunOS)
  XCPPFLAGS +=	-I/usr/xpg4/include -D__EXTENSIONS__
  XLDFLAGS +=	-L/usr/xpg4/lib -R/usr/xpg4/lib
endif
ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
  XCPPFLAGS +=	-D_XOPEN_SOURCE=600
endif

$(LIBPWS_LIB): $(LIBPWS_LIB_MEMBERS)

$(eval $(call generate-manpage-rule,$(LIBPWS_MANPAGES)))

$(eval $(call generate-manpage-rule,$(PWS_INIT_MANPAGES)))

$(eval $(call generate-manpage-rule,$(PWS3_FILE_CREATE_MANPAGES)))

$(PWSDUMP_BIN): $(PWSDUMP_OBJS) $(LIBPWS_LIB) -lnettle

%.o: %.c
	$(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
	$(COMPILE.c) -o $@ $<

(%): %
	$(AR) $(ARFLAGS) $@ $<
	$(RANLIB) $@

%.xhtml: %.xml docbook-update-source-data.xsl
	$(XSLTPROC) \
	    --xinclude \
	    --stringparam package $(PACKAGE) \
	    --stringparam version $(VERSION) \
	    docbook-update-source-data.xsl $< | \
	    $(XSLTPROC) \
	    --xinclude \
	    --output $@ \
	    $(DOCBOOK5_XHTML_FLAGS) \
	    $(DOCBOOK5_XHTML_STYLESHEET) \
	    -

install:
	for header in include/*.h; do \
	    $(INSTALL.data) $${header} \
	        "$(DESTDIR)$(includedir)/$${header##*/}"; \
	done
	$(INSTALL.lib) $(LIBPWS_LIB) \
	    "$(DESTDIR)$(libdir)/$(notdir $(LIBPWS_LIB))"
	for manpage in $(MANPAGES); do \
	    if [ -L $${manpage} ]; then \
	        $(INSTALL.link) $${manpage} \
	            "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
	    else \
	        $(INSTALL.data) $${manpage} \
	            "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
	    fi \
	done

check: $(PWSDUMP_BIN)
	rm -rf $(TESTS_OUTPUT_PATH); \
	SHELL=$(SHELL) PWSDUMP=$(PWSDUMP_BIN) \
	    TESTS_OUTPUT_PATH=$(TESTS_OUTPUT_PATH) $(SHELL) tests/run-tests.sh

clean:
	rm -f $(LIBPWS_LIB) $(PWSDUMP_BIN) $(OBJS) $(MANPAGES) \
	    $(XHTML_DOCUMENTATION)
	rm -rf $(TESTS_OUTPUT_PATH)

clobber: clean
	rm -f $(patsubst %.o,%.d,$(OBJS))

dist: clobber
	$(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
	    -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
	    $(GZIP) > $(DISTNAME).tar.gz

-include local.mk

-include $(patsubst %.o,%.d,$(OBJS))