# ---------------------------------------------------------------------
# Linux Makefile for FreeAdhocUDF
# This file is part of FreeAdhocUDF.
# ---------------------------------------------------------------------
# FreeAdhocUDF - copyright (c) 2004 - 2007 adhoc dataservice GmbH
# Christoph Theuring / Peter Mandrella / Georg Horn
# <http://www.udf.adhoc-data.de> eMail <udf@adhoc-data.de>
# based on FreeUDFLibC - copyright (c) 1999 Gregory Deatz
# changes by adhoc dataservice GmbH
# ---------------------------------------------------------------------
#
# ---------------------------------------------------------------------
# InterBase/FireBird Installation Directory
# uncomment your choice to point to your InterBase/FireBird installation directory
# copies the FreeAdhocUDF.so to the .../UDF directory
# only for "make install" 
# ---------------------------------------------------------------------
#DBDIR=/opt/firebird
#DBDIR=/opt/interbase

# ----------------------------------------------------------------------
# uncomment your choice of the DB-system
# for InterBase you can normally choose the newest version for all ib versions
# for FireBird 1.x you must choose firebird_1_5
# for FireBird 2.x you must choose firebird_2_1
# for FireBird64 2.x you must choose firebird_2_1_64  
# ----------------------------------------------------------------------
#DBSYSTEM=interbase_6_0_2
#DBSYSTEM=interbase_7_1
#DBSYSTEM=interbase_7_5
DBSYSTEM=interbase_2007
#DBSYSTEM=firebird_1_5
#DBSYSTEM=firebird_2_0
#DBSYSTEM=firebird_2_0_64
#DBSYSTEM=firebird_2_1
#DBSYSTEM=firebird_2_1_64

# ----------------------------------------------------------------------
# set the output name
# ----------------------------------------------------------------------
ifeq (interbase, $(findstring interbase, $(DBSYSTEM)))
  FAU=FreeAdhocUDF_ib.so
endif
ifeq (firebird_1_5, $(DBSYSTEM))
  FAU=FreeAdhocUDF_fb15.so
endif
ifeq (firebird_2_, $(findstring firebird_2_, $(DBSYSTEM)))
  ifeq (_64, $(findstring _64, $(DBSYSTEM)))
    FAU=FreeAdhocUDF_fb2x64.so
  else
    FAU=FreeAdhocUDF_fb2x.so
  endif 
endif
  
# ----------------------------------------------------------------------
# Location of header files and libraries
# ----------------------------------------------------------------------
# set the directory for the associated libraries
LIB=../linux/$(DBSYSTEM)/lib

# set the directory for the associated header files
INCLUDE=../linux/$(DBSYSTEM)/include

# ----------------------------------------------------------------------
# set compiler and linker options
# ----------------------------------------------------------------------
# set the associated clientlib to the DB-system
# gds for InterBase, fbclient for FireBird   
# ----------------------------------------------------------------------
ifeq (firebird, $(findstring firebird, $(DBSYSTEM)))		
  CLIENTLIB=fbclient
else 
  CLIENTLIB=gds
endif

# ----------------------------------------------------------------------
# potential set flag for a 32 bit FreeAdhocUDF compile on a 64 bit system
# ----------------------------------------------------------------------
# point to the 32bit libraries on a 64bit system
LIB32=/usr/lib32
ifneq ($(wildcard i*86), $(findstring $(wildcard i*86), $(shell uname -a)))
	SYSTEM='the system is 64bit'
  ifneq (_64, $(findstring _64, $(DBSYSTEM)))
    CF=-m32
    LF=-mi386linux -L$(LIB32)
	  FREEADHOCUDF='the FreeAdhocUDF is 32bit'
  else
    CF=-m64
    LF=
	  FREEADHOCUDF='the FreeAdhocUDF is 64bit'
  endif  
else
	SYSTEM='the system is 32bit'
  ifneq (_64, $(findstring _64, $(DBSYSTEM)))
	  FREEADHOCUDF='the FreeAdhocUDF is 32bit'
    CF=
    LF=    
  else
    $(error no 64bit compiling on a 32bit system!)
  endif
endif
 
# ---------------------------------------------------------------------
# Compiler and linker Defines
# ---------------------------------------------------------------------
CC=gcc
LINK=gcc
LIB_LINK=ld
CFLAGS=-DIB55 -fpic -O -c -w $(CF) -I$(INCLUDE)
LIB_LINK_FLAGS=-G -Bsymbolic $(LF) -L$(LIB) -lm -lc -lib_util 

# ---------------------------------------------------------------------
# Generic Compilation Rules
#
# Do NOT change anything below this point.
# ---------------------------------------------------------------------
.SUFFIXES: .o .c .e

# .e.c:
# 	$(GPRE) $< -d $(DB)

.c.o:
	$(CC) $< $(CFLAGS) -o $@

.o:
	$(LINK) -o $@ $< $(LINK_FLAGS)

# ---------------------------------------------------------------------
# The UDF objects
# ---------------------------------------------------------------------
UDF_OBJs = date_functions.o math_functions.o string_functions.o blob_functions.o md5c.o sysdep.o uuid.o uuid_functions.o const_functions.o conv_functions.o

all: clean $(FAU)

$(FAU): $(UDF_OBJs)
	$(LIB_LINK) $(UDF_OBJs) -o $@ $(LIB_LINK_FLAGS) -l$(CLIENTLIB)
  
clean:
	rm -f *.o *~
	@echo clean done
  
new:	clean $(FAU)
	@echo chosen $(DBSYSTEM)
	@echo libs are located $(LIB)
	@echo headers are located $(INCLUDE)
	@echo clientlib is $(CLIENTLIB)
	@echo $(SYSTEM)
	@echo $(FREEADHOCUDF)
	@echo libname is $(FAU)

install:
	cp $(FAU) $(DBDIR)/UDF/FreeAdhocUDF.so

date_functions.o: date_functions.h global.h
math_functions.o: math_functions.h global.h
string_functions.o: string_functions.h global.h md5_global.h md5.h
blob_functions.o: blob_functions.h global.h
md5c.o: md5.h md5_global.h
sysdep.o: sysdep.h
uuid.o: sysdep.h uuid.h
uuid_functions.o: global.h sysdep.h uuid.h date_functions.h uuid_functions.h
const_functions.o: const_functions.h
conv_functions.o: conv_functions.h global.h


