COMPMID-556: Revert COMPMID-652

Revert back to static linkage for android as dynamic linkage causes
error within libc++

Change-Id: I448dd5ff4e527b81d702e331bd070101431fb7de
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/111995
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com <bsgcomp@arm.com>
diff --git a/SConscript b/SConscript
index 3637858..2544d1f 100644
--- a/SConscript
+++ b/SConscript
@@ -231,17 +231,16 @@
     shared_graph_objects = [arm_compute_env.SharedObject(f) for f in graph_files]
     static_graph_objects = [arm_compute_env.StaticObject(f) for f in graph_files]
 
-    #FIXME OpenCL can't be linked statically: revisit when we can have a NEON only build of the graph library
-    #arm_compute_graph_a = build_library('arm_compute_graph-static', static_graph_objects, static=True, libs = [ arm_compute_a ])
-    #Export('arm_compute_graph_a')
+    arm_compute_graph_a = build_library('arm_compute_graph-static', static_graph_objects, static=True, libs = [ arm_compute_a ])
+    Export('arm_compute_graph_a')
 
     arm_compute_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
     arm_compute_graph_so = build_library('arm_compute_graph', shared_graph_objects, static=False, libs = [ "arm_compute", "arm_compute_core", "OpenCL" ])
-    Depends(arm_compute_graph_so, [ arm_compute_so, opencl])
+    Depends(arm_compute_graph_so, arm_compute_so)
+    Depends(arm_compute_graph_so, opencl)
     Export('arm_compute_graph_so')
 
-   #graph_alias = arm_compute_env.Alias("arm_compute_graph", [arm_compute_graph_a, arm_compute_graph_so])
-    graph_alias = arm_compute_env.Alias("arm_compute_graph", [arm_compute_graph_so])
+    graph_alias = arm_compute_env.Alias("arm_compute_graph", [arm_compute_graph_a, arm_compute_graph_so])
     Default(graph_alias)
 
 if env['standalone']:
diff --git a/SConstruct b/SConstruct
index e750422..9f772f4 100644
--- a/SConstruct
+++ b/SConstruct
@@ -188,7 +188,7 @@
 
 if env['os'] == 'android':
     env.Append(CPPDEFINES = ['ANDROID'])
-    env.Append(LINKFLAGS = ['-pie'])
+    env.Append(LINKFLAGS = ['-pie', '-static-libstdc++'])
 elif env['os'] == 'bare_metal':
     env.Append(LINKFLAGS = ['-static'])
     env.Append(LINKFLAGS = ['-specs=rdimon.specs'])
diff --git a/docs/00_introduction.dox b/docs/00_introduction.dox
index 9d478e0..bf43b3a 100644
--- a/docs/00_introduction.dox
+++ b/docs/00_introduction.dox
@@ -609,24 +609,24 @@
 To cross compile a NEON example:
 
 	#32 bit:
-	arm-linux-androideabi-clang++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute -larm_compute_core -L. -o neon_convolution_arm -pie
+	arm-linux-androideabi-clang++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute-static -larm_compute_core-static -L. -o neon_convolution_arm -static-libstdc++ -pie
 	#64 bit:
-	aarch64-linux-android-g++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute -larm_compute_core -L. -o neon_convolution_aarch64 -pie
+	aarch64-linux-android-g++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute-static -larm_compute_core-static -L. -o neon_convolution_aarch64 -static-libstdc++ -pie
 
 To cross compile an OpenCL example:
 
 	#32 bit:
-	arm-linux-androideabi-clang++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute -larm_compute_core -L. -o cl_convolution_arm -pie -lOpenCL -DARM_COMPUTE_CL
+	arm-linux-androideabi-clang++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute-static -larm_compute_core-static -L. -o cl_convolution_arm -static-libstdc++ -pie -lOpenCL -DARM_COMPUTE_CL
 	#64 bit:
-	aarch64-linux-android-g++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute -larm_compute_core -L. -o cl_convolution_aarch64 -pie -lOpenCL -DARM_COMPUTE_CL
+	aarch64-linux-android-g++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute-static -larm_compute_core-static -L. -o cl_convolution_aarch64 -static-libstdc++ -pie -lOpenCL -DARM_COMPUTE_CL
 
 To cross compile the examples with the Graph API, such as graph_lenet.cpp, you need to link the library arm_compute_graph also.
 (notice the compute library has to be built with both neon and opencl enabled - neon=1 and opencl=1)
 
 	#32 bit:
-	arm-linux-androideabi-clang++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp -I. -Iinclude -std=c++11 -larm_compute_graph -larm_compute -larm_compute_core -L. -o graph_lenet_arm -pie -Wl,--allow-shlib-undefined
+	arm-linux-androideabi-clang++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp -I. -Iinclude -std=c++11 -larm_compute_graph-static -larm_compute-static -larm_compute_core -static-L. -o graph_lenet_arm -static-libstdc++ -pie -lOpenCL -DARM_COMPUTE_CL
 	#64 bit:
-	aarch64-linux-android-g++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp -I. -Iinclude -std=c++11 -larm_compute_graph -larm_compute -larm_compute_core -L. -o graph_lenet_aarch64 -pie -Wl,--allow-shlib-undefined
+	aarch64-linux-android-g++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp -I. -Iinclude -std=c++11 -larm_compute_graph-static -larm_compute-static -larm_compute_core-static -L. -o graph_lenet_aarch64 -static-libstdc++ -pie -lOpenCL -DARM_COMPUTE_CL
 
 @note Due to some issues in older versions of the Mali OpenCL DDK (<= r13p0), we recommend to link arm_compute statically on Android.
 
diff --git a/examples/SConscript b/examples/SConscript
index e002d11..3357cca 100644
--- a/examples/SConscript
+++ b/examples/SConscript
@@ -42,7 +42,7 @@
 # Build examples
 utils = examples_env.Object("../utils/Utils.cpp")
 
-if env['os'] in ['bare_metal'] or env['standalone']:
+if env['os'] in ['android', 'bare_metal'] or env['standalone']:
     Import('arm_compute_a')
     Import('arm_compute_core_a')
     arm_compute_libs = [ arm_compute_a, arm_compute_core_a ]
@@ -59,16 +59,28 @@
         Depends(prog, [arm_compute_dependency, opencl])
         alias = examples_env.Alias(example, prog)
         Default(alias)
-    Import('arm_compute_graph_so')
-    arm_compute_graph_libs = ["arm_compute_graph", "arm_compute", "arm_compute_core"]
-    graph_dependency = arm_compute_graph_so
+    if env['os'] == 'android':
+        Import('arm_compute_graph_a')
+        Import('arm_compute_core_a')
+        Import('arm_compute_a')
+        arm_compute_graph_libs = [ arm_compute_graph_a, arm_compute_a, arm_compute_core_a, "OpenCL"]
+        graph_dependency = arm_compute_graph_a
+    else:
+        Import('arm_compute_graph_so')
+        arm_compute_graph_libs = ["arm_compute_graph", "arm_compute", "arm_compute_core"]
+        graph_dependency = arm_compute_graph_so
 
     graph_utils = examples_env.Object("../utils/GraphUtils.cpp")
     for file in Glob("./graph_*.cpp"):
         example = os.path.basename(os.path.splitext(str(file))[0])
-        #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
-        prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
-        Depends(prog, graph_dependency)
+        prog = None
+        if env['os'] == 'android':
+            prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = arm_compute_graph_libs + ["OpenCL"])
+            Depends(prog, [graph_dependency, opencl])
+        else:
+            #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
+            prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
+            Depends(prog, graph_dependency)
         alias = examples_env.Alias(example, prog)
         Default(alias)
 
diff --git a/examples/graph_alexnet.cpp b/examples/graph_alexnet.cpp
index 2d2ba6b..534ee45 100644
--- a/examples/graph_alexnet.cpp
+++ b/examples/graph_alexnet.cpp
@@ -21,7 +21,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-
 #include "arm_compute/graph/Graph.h"
 #include "arm_compute/graph/Nodes.h"
 #include "support/ToolchainSupport.h"
diff --git a/examples/graph_googlenet.cpp b/examples/graph_googlenet.cpp
index e116633..b7ff4e4 100644
--- a/examples/graph_googlenet.cpp
+++ b/examples/graph_googlenet.cpp
@@ -21,7 +21,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-
 #include "arm_compute/graph/Graph.h"
 #include "arm_compute/graph/Nodes.h"
 #include "arm_compute/graph/SubGraph.h"
diff --git a/examples/graph_lenet.cpp b/examples/graph_lenet.cpp
index f6af14c..ad4a4e0 100644
--- a/examples/graph_lenet.cpp
+++ b/examples/graph_lenet.cpp
@@ -21,7 +21,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-
 #include "arm_compute/graph/Graph.h"
 #include "arm_compute/graph/Nodes.h"
 #include "support/ToolchainSupport.h"
diff --git a/examples/graph_mobilenet.cpp b/examples/graph_mobilenet.cpp
index 2b2da9e..081fae6 100644
--- a/examples/graph_mobilenet.cpp
+++ b/examples/graph_mobilenet.cpp
@@ -21,7 +21,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-
 #include "arm_compute/graph/Graph.h"
 #include "arm_compute/graph/Nodes.h"
 #include "support/ToolchainSupport.h"
diff --git a/examples/graph_squeezenet.cpp b/examples/graph_squeezenet.cpp
index 51c4de0..1743509 100644
--- a/examples/graph_squeezenet.cpp
+++ b/examples/graph_squeezenet.cpp
@@ -21,7 +21,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-
 #include "arm_compute/graph/Graph.h"
 #include "arm_compute/graph/Nodes.h"
 #include "arm_compute/graph/SubGraph.h"
diff --git a/examples/graph_vgg19.cpp b/examples/graph_vgg19.cpp
index 61bb9a5..a39e255 100644
--- a/examples/graph_vgg19.cpp
+++ b/examples/graph_vgg19.cpp
@@ -21,7 +21,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-
 #include "arm_compute/graph/Graph.h"
 #include "arm_compute/graph/Nodes.h"
 #include "support/ToolchainSupport.h"
diff --git a/tests/SConscript b/tests/SConscript
index 240a8fb..336ec5e 100644
--- a/tests/SConscript
+++ b/tests/SConscript
@@ -50,7 +50,7 @@
 
 Help(new_options.GenerateHelpText(test_env))
 
-if env['os'] in ['bare_metal'] or env['standalone']:
+if env['os'] in ['android', 'bare_metal'] or env['standalone']:
     Import("arm_compute_a")
     Import("arm_compute_core_a")
     test_env.Append(LIBS = [arm_compute_a, arm_compute_core_a])