restructured source code and build dynamic library

This commit is contained in:
Pedro 2015-12-23 16:01:08 +01:00
parent 53ce86f524
commit 5046c6477f
36 changed files with 73 additions and 90 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
build/ build/
utils/ utils/
bin/
lib-test/
# Compiled Object files # Compiled Object files
*.slo *.slo

View File

@ -1,24 +1,51 @@
#
# make source (build the source code into build/)
#
# make library
#
#
#
#
# directories
BIN = bin
SRC = src
SRCSQL = src/lib/sql
SRCPARSER = src/parser
# files
PARSERFILES = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp
LIBCPP = $(shell find $(SRC)/ -name '*.cpp' -not -path "$(SRCPARSER)/*") $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp
LIBOBJ = $(LIBCPP:%.cpp=%.o)
LIBHEADERS = $(shell find $(SRCSQL)/ -name '*.h') $(SRC)/SQLParser.h
# compile & link flages
CC = g++
CFLAGS = -std=c++11 -Wall -fPIC
LIBFLAGS = -shared
TARGET = libsqlparser.so
all: library
test: FORCE
@echo "\nCompiling the SQL parser and the tests...\n"
@make clean -C src/ >/dev/null || exit 1
@make tests -C src/ >/dev/null || exit 1
@make grammar_test -C src/ >/dev/null || exit 1
@echo "Running tests..."
@./bin/grammar_test -f "src/tests/valid_queries.sql"
@./bin/tests
build: FORCE library: $(LIBOBJ)
@echo "\nBuilding the SQL parser... (Run tests with 'make test')" $(CC) $(LIBFLAGS) -o $(TARGET) $(LIBOBJ)
@echo "Build directory: build/\n"
make -C src/
docs: FORCE %.o: %.cpp $(PARSERFILES)
doxygen docs/doxy.conf $(CC) $(CFLAGS) -c -o $@ $<
$(SRCPARSER)/bison_parser.cpp: parser
$(SRCPARSER)/flex_lexer.cpp: parser
parser:
make -C $(SRCPARSER)/
clean:
find $(SRC) -type f -name '*.o' -delete
cleanparser:
make -C $(SRCPARSER)/ clean
FORCE: FORCE:

2
bin/.gitignore vendored
View File

@ -1,2 +0,0 @@
*
!.gitignore

8
src/.gitignore vendored
View File

@ -1,8 +0,0 @@
build/
flex_lexer.c*
flex_lexer.h
bison_parser.c*
bison_parser.h
*.o
*.output
copy*.sh

View File

@ -1,41 +0,0 @@
BUILD_DIR = ../build/
BIN_DIR = ../bin
CC = g++
CFLAGS = -O3 -I./ -Ilib/ -Ilib/statements/ -Iparser/ -std=c++11 -pthread -Wall -g
LIB_HEADERS = $(shell find lib/ -name '*.h') parser/bison_parser.h parser/flex_lexer.h parser/SQLParser.h parser/parser_typedef.h
LIB_SOURCES = $(shell find lib/ -name '*.cpp') parser/bison_parser.cpp parser/flex_lexer.cpp parser/SQLParser.cpp
TEST_SOURCES = $(shell find tests/ -name '*.cpp')
build: clean
make -C parser/
mkdir $(BUILD_DIR)
cp $(LIB_SOURCES) $(BUILD_DIR)
cp $(LIB_HEADERS) $(BUILD_DIR)
grammar_test: $(LIB_SOURCES) sql_grammar_test.cpp
$(CC) $(CFLAGS) $(LIB_SOURCES) sql_grammar_test.cpp -o $(BIN_DIR)/grammar_test
tests: $(LIB_SOURCES) $(TEST_SOURCES) sql_tests.cpp
$(CC) $(CFLAGS) $(LIB_SOURCES) $(TEST_SOURCES) sql_tests.cpp -o $(BIN_DIR)/tests
parser/bison_parser.cpp:
make -C parser/
clean:
rm -f *.o *~ $(BIN_DIR)/analysis $(TESTS_BIN) $(BIN_DIR)/grammar_test $(BIN_DIR)/tests
rm -rf $(BUILD_DIR)
make clean -C parser/
test: tests grammar_test
@./$(BIN_DIR)/grammar_test -f ../test/valid_queries.sql
@./$(BIN_DIR)/tests

View File

@ -1,6 +1,7 @@
#include "SQLParser.h" #include "SQLParser.h"
#include "bison_parser.h" #include "parser/bison_parser.h"
#include "flex_lexer.h" #include "parser/flex_lexer.h"
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>

View File

@ -1,8 +1,7 @@
#ifndef __SQLPARSER_H_ #ifndef __SQLPARSER_H_
#define __SQLPARSER_H_ #define __SQLPARSER_H_
#include "sqllib.h" #include "sqltypes.h"
#include "bison_parser.h"
namespace hsql { namespace hsql {

View File

@ -1,16 +0,0 @@
#ifndef __SQLLIB_H__
#define __SQLLIB_H__
typedef unsigned int uint;
#include "SelectStatement.h"
#include "ImportStatement.h"
#include "CreateStatement.h"
#include "InsertStatement.h"
#include "UpdateStatement.h"
#include "DeleteStatement.h"
#include "DropStatement.h"
#include "PrepareStatement.h"
#include "ExecuteStatement.h"
#endif

View File

@ -0,0 +1,5 @@
flex_lexer.c*
flex_lexer.h
bison_parser.c*
bison_parser.h
*.output

View File

@ -8,4 +8,4 @@ flex_lexer.cpp: flex_lexer.l
flex flex_lexer.l flex flex_lexer.l
clean: clean:
rm -f bison_parser.cpp flex_lexer.cpp bison_parser.h flex_lexer.h rm -f bison_parser.cpp flex_lexer.cpp bison_parser.h flex_lexer.h *.output

View File

@ -11,7 +11,7 @@
** Section 1: C Declarations ** Section 1: C Declarations
*********************************/ *********************************/
#include "sqllib.h" #include "../sqltypes.h"
#include "bison_parser.h" #include "bison_parser.h"
#include "flex_lexer.h" #include "flex_lexer.h"

View File

@ -10,7 +10,7 @@
***************************/ ***************************/
%{ %{
#include "sqllib.h" #include "../sqltypes.h"
#include "bison_parser.h" #include "bison_parser.h"
#include <stdio.h> #include <stdio.h>

View File

@ -3,7 +3,7 @@
#define __SQLHELPER_H__ #define __SQLHELPER_H__
#include "sqllib.h" #include "sqltypes.h"
namespace hsql { namespace hsql {

16
src/sqltypes.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __SQLLIB_H__
#define __SQLLIB_H__
typedef unsigned int uint;
#include "sql/SelectStatement.h"
#include "sql/ImportStatement.h"
#include "sql/CreateStatement.h"
#include "sql/InsertStatement.h"
#include "sql/UpdateStatement.h"
#include "sql/DeleteStatement.h"
#include "sql/DropStatement.h"
#include "sql/PrepareStatement.h"
#include "sql/ExecuteStatement.h"
#endif