diff Makefile @ 0:d541e748cfd8

Initial revision
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Tue, 10 Feb 2015 11:29:54 +0100
parents
children e1309515d111
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Tue Feb 10 11:29:54 2015 +0100
@@ -0,0 +1,176 @@
+#
+# 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
+
+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_GETENTROPY ?=	0
+  HAVE_SYS_TREE_H ?=	0
+else ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly),)
+  HAVE_ARC4RANDOM ?=	1
+  HAVE_ENDIAN_H ?=	0
+  HAVE_SYS_ENDIAN_H ?=	1
+  HAVE_GETENTROPY ?=	0
+  HAVE_SYS_TREE_H ?=	1
+else ifeq ($(OS_NAME),NetBSD)
+  HAVE_ARC4RANDOM ?=	1
+  HAVE_ENDIAN_H ?=	0
+  HAVE_SYS_ENDIAN_H ?=	1
+  HAVE_GETENTROPY ?=	0
+  HAVE_SYS_TREE_H ?=	1
+else ifeq ($(OS_NAME),OpenBSD)
+  HAVE_ARC4RANDOM ?=	1
+  HAVE_ENDIAN_H ?=	0
+  HAVE_SYS_ENDIAN_H ?=	1
+  HAVE_GETENTROPY ?=	1
+  HAVE_SYS_TREE_H ?=	1
+else ifeq ($(OS_NAME),SunOS)
+  HAVE_ARC4RANDOM ?=	0
+  HAVE_ENDIAN_H ?=	0
+  HAVE_SYS_ENDIAN_H ?=	0
+  HAVE_GETENTROPY ?=	0
+  HAVE_SYS_TREE_H ?=	0
+else
+  HAVE_ARC4RANDOM ?=	0
+  HAVE_ENDIAN_H ?=	0
+  HAVE_SYS_ENDIAN_H ?=	0
+  HAVE_GETENTROPY ?=	0
+  HAVE_SYS_TREE_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))
+
+OBJS =			$(LIBPWS_OBJS)
+
+.DEFAULT_TARGET = all
+
+.PHONY: all clean clobber dist install
+
+all: $(LIBPWS_LIB)
+
+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
+endif
+ifeq ($(HAVE_GETENTROPY),1)
+  XCPPFLAGS +=	-DHAVE_GETENTROPY
+else
+  LIBPWS_OBJS += compat/getentropy.o
+endif
+ifeq ($(HAVE_SYS_TREE_H),1)
+  XCPPFLAGS +=	-DHAVE_SYS_TREE_H
+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)
+
+%.o: %.c
+	$(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
+	$(COMPILE.c) -o $@ $<
+
+(%): %
+	$(AR) $(ARFLAGS) $@ $<
+	$(RANLIB) $@
+
+install:
+	for header in include/*.h; do \
+	    $(INSTALL.data) $${header} \
+	        "$(DESTDIR)$(includedir)/$(PACKAGE)/$${header##*/}"; \
+	done
+	$(INSTALL.lib) $(LIBPWS_LIB) \
+	    "$(DESTDIR)$(libdir)/$(notdir $(LIBPWS_LIB))"
+
+clean:
+	rm -f $(LIBPWS_LIB) $(LIBPWS_OBJS)
+
+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 $(patsubst %.o,%.d,$(OBJS))