
#INC =  -Iinclude -Isqstdlib -I../myaxtls -I../discount -I/usr/include/postgresql -I/usr/lib/jvm/default-java/include -I/usr/lib/llvm-3.1/include -I../SquiLu-ext/threadObject -I..
#INC =  -Iinclude -Isqstdlib -I../myaxtls -I../discount -I..
INC =  -Iinclude -Isqstdlib -Isquirrel -I../myaxtls -I../discount \
    -I../gumbo -I.. -I../minizip \
    -I/usr/include/mysql -I/usr/include/postgresql -I../unql/src \
    -I../libffi-3.2.1/rpi/include
#CFLAGS =  -Wall -fno-strict-aliasing -DSQ_JIT_LLVM44=1 -D_DEBUG_DUMP33=1 -DWITH_DAD_EXTRAS=1 -DSQ_SUBLATIN=1 -DNEED_SUBLATIN_C2=1 -DSQUSEDOUBLE=1 -DSQUSEDECIMAL64x=1 -DNO_EXCEPTION_KEY_NOT_FOUND0=1 -D_SQ642=1 -DNO_GARBAGE_COLLECTOR00=1 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_DEFAULT_AUTOVACUUM=1 -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_ENABLE_EXTENSION_FUNCTIONS=1 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS=1 -DSQLITE_ENABLE_UNLOCK_NOTIFY=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_STAT3=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_OMIT_TCL_VARIABLE=1 -DSQLITE_USE_URI=1 -DSQLITE_SOUNDEX=1 -DNO_POPEN=1 -DNO_SSL_DL=1 -DHAVE_STDINT=1 -DUSE_AXTLS=1 -DUSE_AXTLS_ON_MEMORY=1 -D_FILE_OFFSET_BITS=64 -DSSL_STATIC_LIBRARY=1 -DPDF_USING_ZLIB=1 -DRS232_STATIC=1
CFLAGS = $(INC) -O3 -Wall -fno-strict-aliasing  \
    -DCONFIG_32=1 \
    -D_DEBUG_DUMP33=1 \
    -D_FILE_OFFSET_BITS=64 \
    -DHAS_UNIX_DOMAIN_SOCKETS=1 \
    -DHAVE_STDINT=1 \
    -DNDEBUG=1 \
    -DNEED_SUBLATIN_C2=1 \
    -DNO_EXCEPTION_KEY_NOT_FOUND0=1 \
    -DNO_GARBAGE_COLLECTOR00=1 \
    -DNO_POPEN=1 \
    -DNO_SSL_DL=1 \
    -DONLY_ASCII=1 \
    -DPDF_USING_ZLIB=1 \
    -DPROFILE_SQVM0=1 \
    -DRS232_STATIC=1 \
    -D_SQ64x=1 \
    -DSQ_JIT_LLVM44=1 \
    -DSQLITE_DEFAULT_AUTOVACUUM=1 \
    -DSQLITE_DEFAULT_FILE_FORMAT=4 \
    -DSQLITE_DEFAULT_FOREIGN_KEYS=1 \
    -DSQLITE_ENABLE_COLUMN_METADATA=1 \
    -DSQLITE_ENABLE_EXTENSION_FUNCTIONS=1 \
    -DSQLITE_ENABLE_FTS3_PARENTHESIS=1 \
    -DSQLITE_ENABLE_FTS4=1 \
    -DSQLITE_ENABLE_FTS5=1 \
    -DSQLITE_ENABLE_RTREE=1 \
    -DSQLITE_ENABLE_STAT4=1 \
    -DSQLITE_ENABLE_UNLOCK_NOTIFY=1 \
    -DSQLITE_HAS_CODEC=1 \
    -DSQLITE_OMIT_TCL_VARIABLE=1 \
    -DSQLITE_SOUNDEX=1 \
    -DSQLITE_USE_URI=1 \
	-DUSE_BITVECTOR=1 \
    -DSQLITE_OMIT_PREPARED=1 \
    -DSQLITE_ENABLE_JSON1=1 \
    -DSQLITE_USE_DECIMAL2=1 \
	-DSQLITE_ENABLE_SESSION=1 \
	-DSQLITE_ENABLE_PREUPDATE_HOOK=1 \
    -DSQ_SUBLATIN=1 \
    -DSQUSEDECIMAL64x=1 \
    -DSQUSEDOUBLE=1 \
    -DSSL_STATIC_LIBRARY=1 \
    -DTHREADSAFE=1 \
    -DUSE_AXTLS=1 \
    -DUSE_AXTLS_ON_MEMORY=1 \
    -DUSE_OPENSSL2=1 \
    -DUSE_SIGNAL_HANDLER=1 \
    -DWITH_DAD_EXTRAS=1 \
    -DWITH_MPDECIMAL=1 \
    -DWITH_MYSQL2=1 \
    -DWITH_POSTGRESQL2=1 \
    -DWITH_UUID=1 \
    -DSQ_USE_MKSTEMP=1 \
    -DSQ_USE_LOCALTIME_R=1 \
    -DSQ_ENABLE_INCLUDES=1 \
    -DWITH_FFI=1 \
    -DSQ_USE_EASYCURL=1 \
    -DSLAVE_VM_WITH_OS_THREADS=1

RESINC = 
#LIBDIR =  -Llib -L../myaxtls -L../mpdecimal -L../discount
LIBDIR =  -Llib -L../myaxtls -L../mpdecimal-2.4.1/libmpdec -L../discount -L../gumbo -L../minizip -L../unql
LIB =  -lm
#LDFLAGS =  -lpthread -lrt -ldl -laxtls -lmpdecimal -ldiscount -lz
#LDFLAGS =  -lpthread -lrt -ldl -luuid -laxtls -lmpdecimal -ldiscount -lgumbo -lminizip -lz -lunql
LDFLAGS =  -lpthread -ldl -laxtls -lmpdec -ldiscount -lgumbo -lminizip \
    -lz -lunql -luuid ../libffi-3.2.1/rpi/.libs/libffi.a
CC = gcc
CXX = g++ -std=c++11

SOURCES= \
    sqstdlib/sqstdaux.cpp  \
    sqstdlib/sqstdblob.cpp  \
    sqstdlib/sqstdio.cpp  \
    sqstdlib/sqstdmath.cpp  \
    sqstdlib/sqstdrex.cpp  \
    sqstdlib/sqstdstream.cpp  \
    sqstdlib/sqstdstring.cpp  \
    sqstdlib/sqstdsystem.cpp  \
    ../SquiLu-ext/dynamic_library.cpp  \
    ../SquiLu-ext/fpdf.cpp  \
    ../SquiLu-ext/lua_socket.cpp  \
    ../SquiLu-ext/mongoose.c  \
    ../SquiLu-ext/pdf-font.cpp  \
    ../SquiLu-ext/sq_axtls.c  \
    ../SquiLu-ext/sq_base64.cpp  \
    ../SquiLu-ext/sq_fpdf.cpp  \
    ../SquiLu-ext/sq_fs.cpp  \
    ../SquiLu-ext/sq_gumbo.cpp  \
    ../SquiLu-ext/sqlite3.c  \
    ../SquiLu-ext/sq_unql.c  \
    ../SquiLu-ext/sq_decimal.cpp  \
    ../SquiLu-ext/sq_libcurl.cpp  \
    ../SquiLu-ext/sq_markdown.cpp  \
    ../SquiLu-ext/sq_mix.cpp \
    ../SquiLu-ext/sq_mongoose.cpp  \
    ../SquiLu-ext/sq_mysql.cpp  \
    ../SquiLu-ext/sq_postgresql.cpp  \
    ../SquiLu-ext/sqratimport.cpp  \
    ../SquiLu-ext/sq_rs232.c  \
    ../SquiLu-ext/sq_slave_vm.cpp  \
    ../SquiLu-ext/sq_socket.cpp  \
    ../SquiLu-ext/sq_sqlite3.cpp  \
    ../SquiLu-ext/sq_bitvector.cpp  \
    ../SquiLu-ext/sq_tinyxml2.cpp  \
    ../SquiLu-ext/sq_zlib.cpp  \
    ../SquiLu-ext/tinyxml2.cpp \
    ../SquiLu-ext/dad_utils.cpp \
    ../SquiLu-ext/randombytes.c \
    ../SquiLu-ext/tweetnacl.c \
    ../SquiLu-ext/sq_tweetnacl.cpp \
    ../SquiLu-ext/sq_pack.cpp \
    ../SquiLu-ext/sq_ffi.cpp \
    squirrel/lua-regex.c  \
    squirrel/sqapi.cpp  \
    squirrel/sqbaselib.cpp  \
    squirrel/sqclass.cpp  \
    squirrel/sqcompiler.cpp  \
    squirrel/sqdebug.cpp  \
    squirrel/sqfuncstate.cpp  \
    squirrel/sqlexer.cpp  \
    squirrel/sq_lexer.cpp  \
    squirrel/sqmem.cpp  \
    squirrel/sqobject.cpp  \
    squirrel/sqstate.cpp  \
    squirrel/sqtable.cpp  \
    squirrel/sqvm.cpp  \
    squirrel/sublatin.c


SOURCES_PROG = sq/sq.c $(SOURCES)
	
#SOURCES += ../SquiLu-ext/sq_fltk.cpp  ../SquiLu-ext/sq_parsecsv.cpp \
#	../SquiLu-ext/sq_postgresql.cpp ../SquiLu-ext/sq_zmq3.cpp  

OBJECTS_C = $(SOURCES:.c=.o)
OBJECTS = $(OBJECTS_C:.cpp=.o)
OBJECTS_PROG_C = $(SOURCES_PROG:.c=.o)
OBJECTS_PROG = $(OBJECTS_PROG_C:.cpp=.o)

%.o: %.c
	$(CC) -c -o $@ $< $(CFLAGS)
	
%.o: %.cpp
	$(CXX) -c -o $@ $< $(CFLAGS)
	
squilu: $(OBJECTS_PROG) 
	$(CXX) $(CFLAGS) -o $@ $(OBJECTS_PROG) $(LIBDIR) $(LDFLAGS)
	$(AR) rcs libsquilu.a $(OBJECTS)
