PRGNAME_SSDK = libshssdk.la
PRGNAME_CSDK = libshcsdk.la
PRGNAME_SDK = libshsdk.la
CC	= gcc
AR = /usr/bin/ar
RANLIB = /usr/bin/ranlib
OS	= linux

NEON_DIR = libs/neon-0.29.5/src
CRYPT_DIR = libs/libmcrypt-2.5.7/lib

INCLUDES = -I. -I/user/local/include \
		   -Ilibs/libmcrypt-2.5.7/lib/ \
		   -Ilibs/neon-0.29.5/src/	#-Ilibs/neon-0.25.4/src/
LIBDIR = -L/usr/lib -L/usr/local/lib -fPIC
ifeq ($(FreeBSD), yes)
## FreeBSD 
DFLAGS_32BIT =
else
## 32Bit Linux System - large file support option(-DNE_LFS -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64)
DFLAGS_32BIT = -DNE_LFS -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
endif

DFLAGS_EXT = -D_NEWAUTH
ifeq ($(SPSDK), yes)
DFLAGS_EXT = -D_SP_SDK_
endif 

ifeq ($(LGU), yes)
## X-CDN
OUTPUT_SHARED=.libs_lgu
OUTPUT_STATIC=.libs_static_lgu

DFLAGS = ${DFLAGS_32BIT} -D_GNU_SOURCE -D_LGU \
	 ${DFLAGS_EXT}
else
## KT-ICS
OUTPUT_SHARED=.libs_kt
OUTPUT_STATIC=.libs_static_kt

DFLAGS = ${DFLAGS_32BIT} -D_GNU_SOURCE \
	${DFLAGS_EXT}
endif

OUTPUT_SHARED_MV=`mkdir -p ${OUTPUT_SHARED}; mv -f .libs/* ${OUTPUT_SHARED}/`
CLEAN_OUTPUT=${OUTPUT_SHARED}/* ${OUTPUT_STATIC}/*

CFLAGS = -fPIC -Wall -O -g3 ${DFLAGS} 
LIBS = ${CRYPT_DIR}/libmcrypt.la ${NEON_DIR}/libneon.la

STATIC_LIBS = ${CRYPT_DIR}/libmcrypt.la ${NEON_DIR}/libneon.la

LIBTOOL = ./libtool
LINK = ${LIBTOOL} --mode=link ${CC} ${CFLAGS} -o $@
LTCOMPILE = ${LIBTOOL} --mode=compile ${CC} ${INCLUDES} ${CFLAGS}

SSDK_SRC = SHSSDK.h auth.h main.h  solbox_util.c auth.c main.c
CSDK_SRC = solbox_util.c SHCSDK.cpp

SSDK_OBJ = solbox_util.Plo auth.Plo main.Plo
CSDK_OBJ = solbox_util.Plo SHCSDK.Plo

shssdk_OBJ = solbox_util.lo auth.lo main.lo
shcsdk_OBJ = solbox_util.lo SHCSDK.lo
shsdk_OBJ =  solbox_util.lo  auth.lo main.lo SHCSDK.lo

all : Makefile ${shssdk_OBJ} ${shcsdk_OBJ} libshssdk.a libshcsdk.a libshsdk.a
	${LINK} -rpath /usr/local/lib -version-info 0:1:0 -o ${PRGNAME_SSDK} ${shssdk_OBJ} ${LIBS}
	${LINK} -rpath /usr/local/lib -version-info 0:1:0 -o ${PRGNAME_CSDK} ${shcsdk_OBJ} ${LIBS}
	${LINK} -rpath /usr/local/lib -version-info 0:1:0 -o ${PRGNAME_SDK} ${shsdk_OBJ} ${LIBS}
	${OUTPUT_SHARED_MV}

libshssdk.a: ${shssdk_OBJ}
	rm -f $@
	rm -rf .obj
	mkdir -p .obj
	cp $(NEON_DIR)/.libs/libneon.a .obj
	cp $(CRYPT_DIR)/.libs/libmcrypt.a .obj
	cp ${shssdk_OBJ} .obj
	cd .obj; \
	$(AR) x libneon.a; \
	$(AR) x libmcrypt.a; \
	rm -f *.a; \
	$(AR) cru $@ *.lo *.o; \
	$(RANLIB) $@;
	mkdir -p $(OUTPUT_STATIC)
	cp .obj/libshssdk.a $(OUTPUT_STATIC)/libshssdk.a
	
#	$(AR) x $(NEON_DIR)/libneon.a .obj
#	$(AR) cru $@ $(shssdk_OBJ) $(NEON_DIR)/libneon.a $(HASH_DIR)/libmhash.a $(CRYPT_DIR)/libmcrypt.a
#	$(RANLIB) $@

libshcsdk.a: ${shcsdk_OBJ}
	rm -f $@
	rm -rf .obj
	mkdir -p .obj
	cp $(NEON_DIR)/.libs/libneon.a .obj
	cp $(CRYPT_DIR)/.libs/libmcrypt.a .obj
	cp ${shcsdk_OBJ} .obj
	cd .obj; \
	$(AR) x libneon.a; \
	$(AR) x libmcrypt.a; \
	rm -f *.a; \
	$(AR) cru $@ *.lo *.o; \
	$(RANLIB) $@;
	mkdir -p $(OUTPUT_STATIC)
	cp .obj/libshcsdk.a $(OUTPUT_STATIC)/libshcsdk.a

libshsdk.a: ${shssdk_OBJ} ${shcsdk_OBJ}
	rm -f $@
	rm -rf .obj
	mkdir -p .obj
	cp $(NEON_DIR)/.libs/libneon.a .obj
	cp $(CRYPT_DIR)/.libs/libmcrypt.a .obj
	cp ${shssdk_OBJ} .obj
	cp ${shcsdk_OBJ} .obj
	cd .obj; \
	$(AR) x libneon.a; \
	$(AR) x libmcrypt.a; \
	rm -f *.a; \
	$(AR) cru $@ *.lo *.o; \
	$(RANLIB) $@;
	mkdir -p $(OUTPUT_STATIC)
	cp .obj/libshsdk.a $(OUTPUT_STATIC)/libshsdk.a

### Elenoa: 2006. 12 18: hanatv test: START ###

test: test.o libshsdk.a
	g++ test.o -o test -I/user/db/pgsql/include -L./ -lc -lexpat -lshsdk

test.o: test.c
	${CC} -c -o $@ $<


### Elenoa: 2006. 12 18: hanatv test: END   ###

.SUFFIXES: .c .lo .o .obj

.c.lo:
	if $(LTCOMPILE) -MT $@ -MD -MP -MF "$*.Tpo" \
	   -c -o $@ `test -f '$<' || echo `$<; \
	then mv "$*.Tpo" "$*.Plo"; \
	else rm -f "$*.Tpo"; exit 1; \
	fi

.cpp.lo:
	if $(LTCOMPILE) -MT $@ -MD -MP -MF "$*.Tpo" \
	   -c -o $@ `test -f '$<' || echo `$<; \
	then mv "$*.Tpo" "$*.Plo"; \
	else rm -f "$*.Tpo"; exit 1; \
	fi

.c.o : ${CSDK_SRC} ${SSDK_SRC}
#${CC} ${CFLAGS} -c -o $@ $< ${INCLUDES} ${DFLAGS}
	${CC} ${CFLAGS} -o $@ -c $^ ${INCLUDES} ${DFLAGS}

.cpp.o : ${CSDK_SRC} ${SSDK_SRC}
#${CC} ${CFLAGS} -c -o $@ $< ${INCLUDES} ${DFLAGS} 
	${CC} ${CFLAGS}  -o $@ -c $^ ${INCLUDES} ${DFLAGS} 

clean :
	rm -f ${CSDK_OBJ} ${SSDK_OBJ} ${shcsdk_OBJ} ${shssdk_OBJ} ${PRGNAME_SSDK} ${PRGNAME_CSDK} ${PRGNAME_SDK} ${CLEAN_OUTPUT} *.log *.pid *.core *.o
