#
# Strn makefile
#
VER=2.2.0
PREFIX=@prefix@
MAN=@prefix@/man
SHELL=/bin/sh
.SUFFIXES: .c .o .so
LIB=libStrn.a
LIBSO=libStrn.so.1
LIBSOS=libStrn.so
CC=@CC@
CPPFLAGS=
#CFLAGS=-O2
CFLAGS=@CFLAGS@
DEFS=-DSTRNP_ZERO_PAD=0 -DSTRN_ZERO_PAD=1

OBJS=Dynscat.o Strncpy.o Strncat.o Strntok.o Strnpcpy.o Strnpcat.o strtokc.o version.o
SOBJS=Dynscat.so Strncpy.so Strncat.so Strntok.so Strnpcpy.so Strnpcat.so strtokc.so version.so

all: static
	-@echo "Done making Strn."

static: $(LIB)

$(LIB): $(OBJS)
	ar rv $(LIB) $(OBJS)
	chmod 644 "$(LIB)"
	-ranlib "$(LIB)"
	echo "$(VER)" > Strn.version
	-@/bin/ls -l "$(LIB)"

.c.o:
	$(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $< -c

.c.so:
	$(CC) -fpic $(CFLAGS) $(CPPFLAGS) $(DEFS) $*.c -c -o $*.so

dynamic: $(LIBSO)

shared: $(LIBSO)

so: $(LIBSO)

$(LIBSO): $(SOBJS)
	/bin/rm -f "$(LIBSO)"
	gcc -shared "-Wl,-soname,$(LIBSO)" -o "$(LIBSO)" $(SOBJS)
	/bin/ln -s "$(LIBSO)" "$(LIBSOS)"
	-@/bin/ls -l "$(LIBSOS)" "$(LIBSO)"

soinstall: $(LIBSO)
	cp "$(LIBSO)" "$(PREFIX)/lib/$(LIBSO)"
	( cd "$(PREFIX)/lib" ; /bin/ln -s "$(LIBSO)" "$(LIBSOS)" )
	cp Strn.h "$(PREFIX)/include/Strn.h"
	-chmod a+r "$(PREFIX)/lib/$(LIBSO)" "$(PREFIX)/include/Strn.h"

tester: $(LIB) tester.c
	$(CC) $(CFLAGS) tester.c -o tester -I. -L. -lStrn

clean:
	/bin/rm -f "$(LIB)" "$(LIBSO)" $(OBJS) $(SOBJS)

install:
	if test ! -d $(PREFIX)/include ; then mkdir -p "$(PREFIX)/include" ; fi
	if test ! -d $(PREFIX)/lib ; then mkdir -p "$(PREFIX)/lib" ; fi
	cp "$(LIB)" Strn.version "$(PREFIX)/lib"
	cp Strn.h "$(PREFIX)/include/Strn.h"
	-chmod 664 "$(PREFIX)/include/Strn.h" "$(PREFIX)/lib/Strn.version" "$(PREFIX)/lib/$(LIB)"
	-cp Strn.3 "$(MAN)/man3/Strn.3"
	-chmod 664 "$(MAN)/man3/Strn.3"
	-ln "$(MAN)/man3/Strn.3" "$(MAN)/man3/Strncpy.3"
	-ln "$(MAN)/man3/Strn.3" "$(MAN)/man3/Strncat.3"

uninstall:
	/bin/rm -f "$(PREFIX)/lib/$(LIB)" "$(PREFIX)/include/Strn.h"

PACKAGE=configure Makefile.in configure.in Strn.dsp Strn.dsw Dynscat.c Strncpy.c Strncat.c Strnpcpy.c Strnpcat.c Strntok.c strtokc.c Strn.h Strn.3 tester.c version.c Strn.version

TMPDIR=/tmp
TARDIR=Strn
TARFILE=$(TARDIR).tar
TGZFILE=$(TARDIR).tgz

tarcp:
	-@mkdir -p $(TMPDIR)/TAR/$(TARDIR)
	-@chmod ga+r $(PACKAGE)
	-@chmod 755 $(TMPDIR)/TAR/$(TARDIR)
	cp -pr $(PACKAGE) $(TMPDIR)/TAR/$(TARDIR)

tar: $(PACKAGE)
	-@mkdir $(TMPDIR)/TAR
	-@mkdir $(TMPDIR)/TAR/$(TARDIR)
	-@chmod ga+r $(PACKAGE)
	-@chmod 755 $(TMPDIR)/TAR/$(TARDIR)
	cp -pr $(PACKAGE) $(TMPDIR)/TAR/$(TARDIR)
	( cd $(TMPDIR)/TAR ; tar cf $(TARFILE) ./$(TARDIR) )
	cp $(TMPDIR)/TAR/$(TARFILE) .
	-@chmod 644 $(TARFILE)
	-@rm -rf $(TMPDIR)/TAR
	-@ls -l $(TARFILE)

gz: tar
	gzip -c $(TARFILE) > $(TGZFILE)
	-@rm $(TARFILE)
	-@chmod 644 $(TGZFILE)
	-@ls -l $(TGZFILE)

Dynscat.o: Dynscat.c Strn.h
Strncat.o: Strncat.c Strn.h
Strncpy.o: Strncpy.c Strn.h
Strnpcat.o: Strnpcat.c Strn.h
Strnpcpy.o: Strnpcpy.c Strn.h
Strntok.o: Strntok.c Strn.h
strtokc.o: strtokc.c Strn.h
version.o: version.c
