view Makefile @ 19:0bd16b428fc0

Allow local makefile overrides in local.mk
author Guido Berhoerster <guido+sencrypt@berhoerster.name>
date Wed, 31 Jul 2019 11:21:59 +0200
parents b7309b030e8d
children 5f9dc8f3c53e
line wrap: on
line source

#
# Copyright (C) 2014 Guido Berhoerster <guido+sencrypt@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 =	sencrypt
VERSION =	2
DISTNAME :=	$(PACKAGE)-$(VERSION)
DECRYPT_ALIAS =	sdecrypt

# 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)
CP :=		cp
INSTALL :=	install
INSTALL.exec :=	$(INSTALL) -D -m 0755
INSTALL.data :=	$(INSTALL) -D -m 0644
INSTALL.link :=	$(CP) -f -P
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 man.authors.section.enabled 0 \
				--stringparam man.copyright.section.enabled 0

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) \
	    -
	for alias in $(wordlist 2,$(words $1),$1); do \
	    ln -sf $(notdir $(firstword $1)) $$$$alias; \
	done
endef

DESTDIR ?=
prefix ?=	/usr/local
bindir ?=	$(prefix)/bin
datadir ?=	$(prefix)/share
mandir ?=	$(datadir)/man

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

ifneq ($(findstring $(OS_NAME),Linux FreeBSD DragonFly NetBSD OpenBSD),)
  HAVE_ERR_H ?=	1
else ifeq ($(OS_NAME),SunOS)
  ifeq ($(OS_RELEASE),5.10)
    HAVE_ERR_H ?= 0
  else
    HAVE_ERR_H ?= 1
  endif
else ifeq ($(OS_NAME),AIX)
  HAVE_ERR_H ?=	0
endif

OBJS =		sencrypt.o

MANPAGES =	$(PACKAGE).1 $(DECRYPT_ALIAS).1

.DEFAULT_TARGET = all

.PHONY: all clean clobber dist install

all: $(PACKAGE) $(OBJS) $(MANPAGES)

$(PACKAGE): XCPPFLAGS =		-D_XOPEN_SOURCE=600 -DOPENSSL_LOAD_CONF
$(PACKAGE): XCFLAGS :=	$(shell getconf LFS_CFLAGS)
$(PACKAGE): LDLIBS :=	-lcrypto
$(PACKAGE): XLDFLAGS :=	$(shell getconf LFS_LDFLAGS)
ifeq ($(HAVE_ERR_H),1)
  $(PACKAGE): XCPPFLAGS +=	-DHAVE_ERR_H
else
  OBJS +=			err.o
endif
ifeq ($(OS_NAME),SunOS)
  $(PACKAGE): XCPPFLAGS +=	-I/usr/xpg4/include
  $(PACKAGE): XLDFLAGS +=	-L/usr/xpg4/lib -R/usr/xpg4/lib
endif
$(PACKAGE): $(OBJS)
	$(LINK.o) $^ $(LDLIBS) -o $@

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

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

install:
	$(INSTALL.exec) $(PACKAGE) "$(DESTDIR)$(bindir)/$(PACKAGE)"
	ln -f $(PACKAGE) "$(DESTDIR)$(bindir)/$(DECRYPT_ALIAS)"
	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

clean:
	rm -f $(PACKAGE) $(OBJS) $(MANPAGES)

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