# Makefile
# ex.  > make PLATFORM_BITS=64 LIB_PREFIX=/usr
#

NAME = socket
DATE_TAG:=`date +%Y%m%d`

LIB_PREFIX = /usr/local

CCOPT = -I.  
LDOPT =  -L$(LIB_PREFIX)/lib

CFLAGS = -Wall -O2 $(CCOPT)

AZ_CCOPT = -Wall -O2 $(CCOPT)
AZPC_LIBS = socket
AZ_LIB_EXT = $(LIB_PREFIX)/lib/azprolog/ext
AZ_LIB_OBJ = $(LIB_PREFIX)/lib/azprolog/obj

LDLIBS= -lssl -lcrypto
CC=gcc

EXEC_TARGETS = socket.so lib_socket.a socket_ssl.so lib_socket_ssl.a socket 

default: socket.so lib_socket.a socket_ssl.so lib_socket_ssl.a

socket.so: socket.c
	$(CC) $(CFLAGS) -fPIC -o socket.o -c socket.c
	$(CC) -shared -dynamiclib -o $@ socket.o
	rm -f socket.o
	chmod 644 socket.so

socket_ssl.so: socket_ssl.c
	$(CC) $(CFLAGS) -fPIC -o socket_ssl.o -c socket_ssl.c
	$(CC) -shared -dynamiclib -o $@ socket_ssl.o $(LDLIBS)
	rm -f socket_ssl.o
	chmod 644 socket_ssl.so

lib_socket.a: socket.c
	$(CC) $(CFLAGS) -o socket.o -c socket.c
	ar rv $@ socket.o
	ranlib $@
	chmod 644 lib_socket.a

lib_socket_ssl.a: socket_ssl.c
	$(CC) $(CFLAGS) -o socket_ssl.o -c socket_ssl.c
	ar rv $@ socket_ssl.o
	ranlib $@
	chmod 644 lib_socket_ssl.a

socket.o: socket.c
socket_ssl.o: socket_ssl.c

install:
	cp -p socket.so lib_socket.a $(AZ_LIB_EXT)
	cp -p socket_ssl.so lib_socket_ssl.a $(AZ_LIB_EXT)

clean:
	rm -f *~ .*~ *.o $(EXEC_TARGETS)
