# ------------------------------------------------------------------------------
# Makefile is a gmake file for libfbopenssl.a.
#
# usage: gmake [CFG=debug|release] [clean]
#
# Author: Frank Balluffi
#
# Copyright (C) 2002-2005 Frank Balluffi. All rights reserved.
# ------------------------------------------------------------------------------

# Define the environment variable OPENSSLDIR to point to OpenSSL.

# Use gss -fPIC with .so files.

CFLAGS = -ansi -fPIC

PLATFORM = $(shell uname)

ifndef CFG
    CFG = debug
endif

ifeq ($(CFG), debug)
    CFLAGS = -ansi -fPIC -g -O0
endif

ARCH = $(PLATFORM)-$(CFG)
DIRMADE = $(ARCH)-made

LIB = $(ARCH)/libfbopenssl.a
SLIB = $(ARCH)/libfbopenssl.so

# If OpenSSL has been installed, append /lib to OPENSSLDIR in the following
# statement (i.e., use $(OPENSSLDIR)/lib).

SSLLIB = -Wl,-R$(OPENSSLDIR) -L$(OPENSSLDIR) -lcrypto

OBJS = $(ARCH)/asn1help.o \
       $(ARCH)/filehelp.o \
       $(ARCH)/gssapi.o \
       $(ARCH)/krb5help.o \
       $(ARCH)/spnego.o \
       $(ARCH)/spnegohelp.o

all: $(LIB) $(SLIB)

$(LIB): $(OBJS)
	ar -r $(LIB) $(OBJS)

$(SLIB): $(OBJS)
	gcc -shared -o $(SLIB) $(OBJS) $(SSLLIB)

$(ARCH)/asn1help.o: src/asn1/asn1help.c
	gcc -c $(CFLAGS) src/asn1/asn1help.c -I$(OPENSSLDIR)/include -o $@

$(ARCH)/filehelp.o: src/file/filehelp.c
	gcc -c $(CFLAGS) src/file/filehelp.c -o $@

$(ARCH)/gssapi.o: src/gssapi/gssapi.c
	gcc -c $(CFLAGS) src/gssapi/gssapi.c -I$(OPENSSLDIR)/include -o $@

$(ARCH)/krb5help.o: src/krb5/krb5help.c
	gcc -c $(CFLAGS) src/krb5/krb5help.c -I$(OPENSSLDIR)/include -o $@

$(ARCH)/spnego.o: src/spnego/spnego.c
	gcc -c $(CFLAGS) src/spnego/spnego.c -I$(OPENSSLDIR)/include -o $@

$(ARCH)/spnegohelp.o: src/spnego/spnegohelp.c
	gcc -c $(CFLAGS) src/spnego/spnegohelp.c -I$(OPENSSLDIR)/include -o $@

$(OBJS): $(DIRMADE)

$(DIRMADE):
	if [ ! -d $(ARCH) ]; then mkdir $(ARCH); fi
	@-echo $(DIRMADE) > $(DIRMADE)

clean:
	rm $(OBJS) $(LIB) $(SLIB) $(DIRMADE)
	rmdir $(ARCH)
