Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 108 lines (94 sloc) 2.75 KB
#!/usr/bin/env bash
# Script for building OCaml+QML from cold start
RED='\033[0;31m'
NC='\033[0m' # No Color
echo "N.B. Don't forget to export right LD_LIBRARY_PATH and PKG_CONFIG_PATH for Qt5 before running this!"
function verlte() {
[ "$1" = "`printf "$1\n$2\n" | sort | head -n1`" ]
}
function maybe_exit() {
if [ $1 != 0 ]; then
printf "${RED}ERROR${NC}: $2\n"
exit 1
fi
}
ROOT_DIR=$PWD
# checking ocaml version
OCAML_VERSION_MIN="4.00.1"
OCAML_VERSION=`ocamlc -version`
maybe_exit $? "ocamlc executable not found"
if ! verlte $OCAML_VERSION_MIN $OCAML_VERSION ; then
echo "Minimal OCaml version is $OCAML_VERSION_MIN (your is $OCAML_VERSION)"
exit 1
else
echo "OCaml $OCAML_VERSION found."
fi
#TODO: maybe add g++ version checking
# checking for ocamlfind
OCAMLFIND_LOC=`which ocamlfind`
maybe_exit $? "ocamlfind not found"
echo "ocamlfind found."
#checking Qt installation
OCAMLFIND_LOC=`which qmake`
maybe_exit $? "qmake not found"
QT_VERSION=`qmake -query QT_VERSION`
echo "qmake found for Qt $QT_VERSION"
# in Qt 5 QtQuick2 was implemented
# in Qt 5.1 --- QtQuickControls
# Qt 5.2 --- bugfixes and QQmlApplicationEngine
QT_MIN_VERSION="5.2.0"
if ! verlte $QT_MIN_VERSION $QT_VERSION ; then
printf "${RED}Minimal Qt version is $QT_MIN_VERSION${NC} (your is $QT_VERSION)\n"
exit 1
fi
function compile_test() {
# tries to build test C++ application with Qt linking
echo "Compiling test C++&Qt application..."
cd /tmp
echo "#include <QtQuick/qquickview.h>
int main() {
QQuickView viewer;
viewer.show();
return 0;
}" > testQtDeclarative.cpp
g++ -std=c++11 -fPIC `pkg-config --cflags Qt5Quick` testQtDeclarative.cpp \
`pkg-config --libs Qt5Quick`
}
compile_test
if [ $? != 0 ]; then
echo "Building test C++&Qt application failed."
echo -e "N.B. If you are using Ubuntu 13.04 or precompiled Qt5 from website there is \
a possibility that file 'Qt5Core.pc' has bug. You can consider to substitute line\n\
Libs: -L\${libdir} -lQt5Core\n\
for\n\
Libs: -Wl,-rpath,\${libdir} -L\${libdir} -lQt5Core\n"
exit 1
else
echo "Test C++&Qt application is built successfully"
fi
cd $ROOT_DIR
ocamlfind query lablqml
if [ $? = 0 ]; then
printf "It seems that lablqml is ${RED}already installed${NC}.\n"
printf "It may cause ocamlfind issues and/or annoying warnings. Please remove it!\n"
fi
echo "Generating Makefile"
echo -e "\
.PHONY: all generator lib test\n\
all: generator lib \n\
\n\
generator:\n\
cd $ROOT_DIR/ppx && \$(MAKE) all\n\
lib:\n\
\$(MAKE) -C $ROOT_DIR/lib\n\
demos: generator lib\n\
cd $ROOT_DIR/demos/ && \$(MAKE)\n\
clean:\n\
\$(MAKE) -C $ROOT_DIR/demos clean\n\
\$(MAKE) -C $ROOT_DIR/lib clean\n\
\$(MAKE) -C $ROOT_DIR/src clean\n\
uninstall:\n\
ocamlfind remove lablqml\n\n\
\n\
" > Makefile
cat Makefile.install >> Makefile