#
#          File: Makefile
#         Title: File to create libax C library
#
# Last Modified: 2023-01-02 19:26:03
#
# Copyright (C) 2000-2023, Keith Edwin Smith
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of Keith Edwin Smith nor the
#       names of its contributors may be used to endorse or promote products
#       derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY Keith Edwin Smith ''AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Keith Edwin Smith BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
HFILES= \
	local.h

#scanback.o \

OFILES=    \
	argvindex.o \
	base64.o \
	config.o \
	expand.o \
	fdreadln.o \
	gethostname.o \
	log.o\
	makepath.o \
	memicmp.o \
	rdchk.o \
	readline.o \
	strargs.o \
	strcpos.o \
	stricmp.o \
	strincmp.o \
	strpack.o \
	strupr.o \
	substr.o \
	tcp_open.o

CFLAGS= -O -Werror -I ./

CC= gcc -g -DGCC

SHELL= /bin/sh

#ARFLAGS=    ruvl
ARFLAGS=    srvl

libax.a: $(HFILES) $(OFILES)
	ar $(ARFLAGS) libax.a $(OFILES)
	-ranlib libax.a
	chmod 0664 libax.a
	touch libax-build

install: libax-build
	cp -va libax.a /usr/lib/libax.a
	cat local.h > /usr/include/local.h

remove:
	rm -f /usr/include/local.h
	rm -f /usr/lib/libax.a

$(OFILES):    $(HFILES)

clean:
	-rm -f *.o a.out tcp_open tpack

distclean: clean
	rm -f libax.a libax-build

base64: base64.c
	$(CC) -DSTANDALONE base64.c -o base64 -lax
	chmod 0775 base64

base64-install:
	rm -f /usr/local/bin/base64
	rm -f /usr/local/bin/base64_decode
	rm -f /usr/local/bin/base64_encode
	strip base64
	mv base64 /usr/local/bin
	ln /usr/local/bin/base64 /usr/local/bin/base64_decode
	ln /usr/local/bin/base64 /usr/local/bin/base64_encode


tcp_open: tcp_open.c
	$(CC) tcp_open.c -o tcp_open

tar: clean
	cd .. ; tar cvf - libax | gzip > libax-`date +%Y-%m-%d`.tar.gz
	chmod 0664 ../libax-`date +%Y-%m-%d`.tar.gz
