Makefile-static-MacOsX and iOS for Spatialite tools

249 views
Skip to first unread message

Noli Sicad

unread,
Jul 18, 2011, 7:26:05 AM7/18/11
to SpatiaLite Users
Hi Sandro,

I am trying to run Spatialite Tools in jailbroken iPad 2 and iPhone now.

MobileTerminal is CLI for Spatialite in jailbroken iOS devices thru
Cydia (debian package manager).

I manage to compile Proj4 dynamic library (.dylib) and static library.
However, GEOS and Spatialite still have difficulties producing dynamic
libraries. In this case, I will rather use the static libraries to
compile:

spatialite_tool
shp_doctor
spatialite_osm_net
spatialite_gml
spatialite_osm_raw

How do use the Makefile-static-MacOsX?

I like to know how the Makefile-static-MacOsX can be used iOS?

Here build iOS script (below) that I am using to compile iOS.


Thanks in advance.

Noli

###########
# Disallow undefined variables
set -u


default_gcc_version=4.2
default_iphoneos_version=4.2
default_macos_version=10.6

GCC_VERSION="${GCC_VERSION:-$default_gcc_version}"
export IPHONEOS_DEPLOYMENT_TARGET="${IPHONEOS_DEPLOYMENT_TARGET:-$default_iphoneos_version}"
export MACOSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET:-$default_macos_version}"


usage ()
{
cat >&2 << EOF
Usage: ${0##*/} [-ht] [-p prefix] target [configure_args]
-h Print help message
-p Installation prefix (default: \$HOME/Developer/Platforms/...)
-t Use 16-bit Thumb instruction set (instead of 32-bit ARM)

The target must be "device" or "simulator". Any additional arguments
are passed to configure.

The following environment variables affect the build process:

GCC_VERSION (default: $default_gcc_version)
IPHONEOS_DEPLOYMENT_TARGET (default: $default_iphoneos_version)
MACOSX_DEPLOYMENT_TARGET (default: $default_macos_version)

EOF
}


while getopts ":hp:t" opt; do
case $opt in
h ) usage ; exit 0 ;;
p ) prefix="$OPTARG" ;;
t ) thumb_opt=thumb ;;
\? ) usage ; exit 2 ;;
esac
done
shift $(( $OPTIND - 1 ))

if (( $# < 1 )); then
usage
exit 2
fi

target=$1
shift

case $target in

device )
arch=armv7
platform=iPhoneOS
extra_cflags="-m${thumb_opt:-no-thumb} -mthumb-interwork"
;;

simulator )
arch=i386
platform=iPhoneSimulator
extra_cflags="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000"
;;

* )
usage
exit 2

esac


platform_dir="/Developer/Platforms/${platform}.platform/Developer"
platform_bin_dir="${platform_dir}/usr/bin"
platform_sdk_dir="${platform_dir}/SDKs/${platform}${IPHONEOS_DEPLOYMENT_TARGET}.sdk"
prefix="${prefix:-${HOME}${platform_sdk_dir}}"

export CC="${platform_bin_dir}/gcc-${GCC_VERSION}"
export CFLAGS="-arch ${arch} -pipe -Os -gdwarf-2 -isysroot
${platform_sdk_dir} ${extra_cflags}"
export LDFLAGS="-arch ${arch} -isysroot ${platform_sdk_dir}"
export CXX="${platform_bin_dir}/g++-${GCC_VERSION}"
export CXXFLAGS="${CFLAGS}"
export CPP="/Developer/usr/bin/cpp-${GCC_VERSION}"
export CXXCPP="${CPP}"


./configure \
--prefix="${prefix}" \
--host="${arch}-apple-darwin" \
--enable-shared \
--enable-static \
"$@" || exit

make install || exit

cat >&2 << EOF

Build succeeded! Files were installed in

$prefix

EOF

Noli Sicad

unread,
Jul 18, 2011, 7:52:32 AM7/18/11
to SpatiaLite Users
Sandro,

Your Makefile-static-Linux (below) resemble the iPad 2 file system.

I am viewing it with iFile app.

I can easily put all the libraries in the file system as you outlined.

How do I run this script?

I already installed gcc in my iPad 2.

Noli

##############################

# SandroFurieri (c) 2010
# Makefile SpatiaLite statically linked tools [Linux]

CFLAGS = -DSPATIALITE_AMALGAMATION

all: ./static_bin/spatialite ./static_bin/spatialite_tool \
./static_bin/spatialite_network ./static_bin/shp_doctor \
./static_bin/exif_loader ./static_bin/spatialite_osm_net \
./static_bin/spatialite_osm_map ./static_bin/spatialite_gml \
./static_bin/spatialite_osm_raw

./static_bin/spatialite: shell.o shapefiles.o
$(CC) shell.o shapefiles.o -o ./static_bin/spatialite \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
/usr/lib/libreadline.a \
/usr/lib/libncurses.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/spatialite

./static_bin/spatialite_tool: shapefiles.o spatialite_tool.o
$(CC) shapefiles.o spatialite_tool.o -o ./static_bin/spatialite_tool \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/spatialite_tool

./static_bin/spatialite_network: spatialite_network.o
$(CC) spatialite_network.o -o ./static_bin/spatialite_network \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/spatialite_network

./static_bin/shp_doctor: shp_doctor.o
$(CC) shp_doctor.o -o ./static_bin/shp_doctor \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr//lib/libgeos.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/shp_doctor

./static_bin/exif_loader: exif_loader.o
$(CC) exif_loader.o -o ./static_bin/exif_loader \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/exif_loader

./static_bin/spatialite_osm_net: spatialite_osm_net.o
$(CC) spatialite_osm_net.o -o ./static_bin/spatialite_osm_net \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/spatialite_osm_net

./static_bin/spatialite_osm_map: spatialite_osm_map.o
$(CC) spatialite_osm_map.o -o ./static_bin/spatialite_osm_map \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
/usr/lib/libexpat.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/spatialite_osm_map

./static_bin/spatialite_gml: spatialite_gml.o
$(CC) spatialite_gml.o -o ./static_bin/spatialite_gml \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
/usr/lib/libexpat.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/spatialite_gml

./static_bin/spatialite_osm_raw: spatialite_osm_raw.o
$(CC) spatialite_osm_raw.o -o ./static_bin/spatialite_osm_raw \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
/usr/lib/libexpat.a \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./static_bin/spatialite_osm_raw

Noli Sicad

unread,
Jul 18, 2011, 9:26:03 AM7/18/11
to SpatiaLite Users
OK.

I found it.

http://www.gaia-gis.it/spatialite/how_to_build_rasterlite.html

Now the question is, Mixing static and dynamic libraries.

How do it do mixing static and dynamic libraries linking?

Some of the libraries, I could not compile but available as dynamic
libraries (i.e. readline and ncurses) in Cydia.

For example,

./bin/spatialite: shell.o shapefiles.o
$(CC) shell.o shapefiles.o -o ./bin/spatialite \
/usr/local/lib/libspatialite.a \
/usr/lib/libproj.a \
/usr/lib/libgeos_c.a \
/usr/lib/libgeos.a \
/usr/lib/libreadline.6.0.dylib \
/usr/lib/libncurses.5.dylib \
-lstdc++ -lm -lpthread -ldl
strip --strip-all ./bin/spatialite

Would the above works?

Noli

a.fu...@lqt.it

unread,
Jul 18, 2011, 10:19:38 AM7/18/11
to spatiali...@googlegroups.com
Hi Noli,

basically a Makefile is intended to handle dependency
trees: each time you'll change a single source or
header file MAKE will then attempt to rebuild any
object file (or executable) urgently requiring to
be updated so to reflect such change.

and ./configure scripts simply are kind-of glorified
Makefile, so to support extended cross portability
on different platforms.

Anyway, using a Makefile or a ./configure script
isn't at all strictly required in order to build
your software: and sometimes it's really easiest
attempting to perform a "direct" build simply calling
gcc as required.

Just few hints:
====================================================
gcc alpha.c -o alpha

supposing you've some C source named "alpha.c",
this will build the corresponding "alpha" executable

anyway, may well be that "alpha.c" actually calls
some function supported by "gammalib": in this case
the above build will fail, because any linker symbol
supplied by gammalib will remain badly unresolved.

so you absolutely have to add "gammalib" to your build:
and you have at least three ways to do such a thing.

#1) gcc alpha.c -o alpha -lgamma

specifying a -lgamma directive you'll tell the linker
to locate and link "libgamma": the linker will then
search for some appropriate library into its own search
path.
Please Note Well: anyway, this way if the linker
actually found *both* a static- and a dynamic- libgamma,
the dynamic library will be invariably chosen.

and there is a further potential flaw: assuming you
have more versions of the same library, you cannot
be actually sure of which one will be chosen by
the linker.

gcc alpha.c -o alpha -L/somedir -lgamma

so you can usefully specify a -L/dir directive: the
linker will now understand that -lgamma has to be
searched into /somedir: anyway, this doesn't solves
the static- vs dynamic- dilemma.


#2) gcc alpha.c -o alpha /somedir/libgamma.la
gcc supports ".la" files: if a library has a corresponding
".la" file, the linker will parse such file in order to
identify the "physical" library to be linked.
Please Note: ".la" files simply are plain text files;
you can hack them at your risk. sometimes this is useful.


#3) gcc alpha.c -o alpha /somedir/libgamma.a

and finally you can directly specify the full path of
the static library: and in this case the linker will
surely link exactly this one.
(the same is obviously supported for the corresponding
dynamic library stub, if you absolutely require linking
the dynamic library)

=================
so you can use the most appropriate syntax: gcc is
flexible enough to support you in the most desperate
and improbable ways ;-)

I hope these sparse notes can be useful to you; I have
absolutely no experience about iOS, so I cannot say you
nothing more precise than this.

bye Sandro


P.S.: please read this document:
http://www.gaia-gis.it/mingw64_how_to.html

it's specifically intended to support Win 64 bit,
but may well be some infos can be valuable for iOS
as well


Noli Sicad

unread,
Jul 18, 2011, 10:23:54 PM7/18/11
to spatiali...@googlegroups.com
Hi Sandro,

Thanks for these notes about GCC.

I found this posting about static and dynamic libraries as well

http://gcc.gnu.org/ml/gcc/2001-07/msg01447.html

"Assuming you are using the GNU binutils, do

# gcc a.o -Wl,-Bstatic -lfoo -Wl,-Bdynamic -lbar

"

Now, the above info:

gcc shell.o shapefiles.o -o ./bin/spatialite
-W1 -Bstatic
-/usr/local/lib/libspatialite.a
-/usr/lib/libproj.a
-/usr/lib/libgeos_c.a
-/usr/lib/libgeos.a

-Wl,-Bdynamic
-/usr/lib/libreadline.6.0.dylib
-/usr/lib/libncurses.5.dylib


-lstdc++ -lm -lpthread -ldl
strip --strip-all ./bin/spatialite

Sandro, based on the info, would the above script be able to create
spatialite binary file in bin directory in iPad 2?

iOS uses gcc 4.2 as compiler and iOS file system is BSD - same as Mac
OS X. The only difference is, it is uses arm cpu - arm6 and arm7 (iPad
2 and iPhone 4), not x86.

Anybody like to get your iPhone / iPad as a development environment,
visit this site below.

http://ios-hacks.blogspot.com/2011/02/turning-your-ipad-or-iphone-into.html

Thanks.

Noli

> --
> You received this message because you are subscribed to the Google Groups
> "SpatiaLite Users" group.
> To post to this group, send email to spatiali...@googlegroups.com.
> To unsubscribe from this group, send email to
> spatialite-use...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/spatialite-users?hl=en.
>
>

a.furieri

unread,
Jul 19, 2011, 2:46:21 AM7/19/11
to SpatiaLite Users
Hi Noli,

now I understand better what iOS build-system really is.
a) you can use the Apple cross-compiler based on MacOsX
b) alternatively you can directly use "native" GCC /Cydia

Approach (a) is presumably much more complex, as any
cross-compiler based approach implies.

On the other side approach (b) seems to be quite straight
and smooth: so I'll expect (theoretically) that compiling
and linking on Cydia should be (more or less) the same
than building on Linux, MinGW and any other GCC-based
environment.

-------------------------
-Wl,-Bstatic
-/usr/local/lib/libspatialite.a
-/usr/lib/libproj.a
-/usr/lib/libgeos_c.a
-/usr/lib/libgeos.a

this is absolutely redundant, because specifying
.a suffixed libraries already implies "static".

-Wl,-Bstatic -lspatialite -lproj -lgeos_c -lgeos
seems to be a smartest expression (and the same
is for -Wl,-Bdynamic)

Please note: if I intend well, your attempts to
build shared libs on iOS failed. This practically
means that in your local file-system you simply
have "static" libs, and "dynamic" one are missing
at all.
And accordingly to this, GCC must load anyway "static",
because this one is the unique possible solution on
your platform.


----------
I see a possible error here:
strip -strip-all ./bin/spatialite

strip supports the -strip-all on Linux and MinGW,
but not on MacOsX
the Mac specific syntax is:
strip ./bin/spatialite

and I suppose the same is for iOS
Anyway, the "strip" utilities simply removes
debugging symbols from the executable, saving
some disk space. but isn't at all mandatory.

-----
impossible to guess if some syntax will actually
be accepted by Cydia not having the "iron" on
my hands: questions of this kind absolutely
require first hand direct experience. :-)

Just as a personal approach of my own, I'll
probably first test this one:

gcc shell.o shapefile.o \
-o ./bin/spatialite \
-lspatialite -lproj -lgeos_c -lgeos \
-lreadline -lncurses -lstdc++ \
-lm -lpthread -ldl 2>error_log

very probably this will raise several errors:
but reading the error_log you'll quite easily
identify which libraries are missing, and/or
why they cannot be actually linked and so on

So after few iterations "by trial and error"
your attempts will be finally successful.
And all this surely will cause you a severe
headache, but a strong self satisfaction as well ;-)

bye Sandro
Reply all
Reply to author
Forward
0 new messages