#
# Strn makefile
#
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=Strncpy.o Strncat.o Strntok.o Strnpcpy.o Strnpcat.o strtokc.o version.o
SOBJS=Strncpy.so Strncat.so Strntok.so Strnpcpy.so Strnpcat.so strtokc.so version.so

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

static: $(LIB)

$(LIB): Strncpy.o Strncat.o Strntok.o Strnpcpy.o Strnpcat.o strtokc.o version.o
	ar rv $(LIB) Strncpy.o Strncat.o Strntok.o Strnpcpy.o Strnpcat.o strtokc.o version.o
	chmod 644 "$(LIB)"
	-ranlib "$(LIB)"
	-@/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)" "$(SOLIB)" $(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)" "$(PREFIX)/lib/$(LIB)"
	cp Strn.h "$(PREFIX)/include/Strn.h"
	-chmod 664 "$(PREFIX)/include/Strn.h" "$(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=Makefile Strncpy.c Strncat.c Strnpcpy.c Strnpcat.c Strntok.c strtokc.c Strn.h Strn.3 tester.c version.c

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)

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
