Commit f8c26d66 authored by Daniel García Moreno's avatar Daniel García Moreno

libgepub_internals as subproject dep

parent ecca0e1e
......@@ -15,3 +15,5 @@ libtool
*.lo
.deps
.libs
_build/
#!/bin/bash
# configure script adapter for Meson
# Based on build-api: https://github.com/cgwalters/build-api
# Copyright 2010, 2011, 2013 Colin Walters <walters@verbum.org>
# Copyright 2016, 2017 Emmanuele Bassi
# Copyright 2017 Iñigo Martínez <inigomartinez@gmail.com>
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
# Build API variables:
# Little helper function for reading args from the commandline.
# it automatically handles -a b and -a=b variants, and returns 1 if
# we need to shift $3.
read_arg() {
# $1 = arg name
# $2 = arg value
# $3 = arg parameter
local rematch='^[^=]*=(.*)$'
if [[ $2 =~ $rematch ]]; then
read "$1" <<< "${BASH_REMATCH[1]}"
else
read "$1" <<< "$3"
# There is no way to shift our callers args, so
# return 1 to indicate they should do it instead.
return 1
fi
}
sanitycheck() {
# $1 = arg name
# $1 = arg command
# $2 = arg alternates
local cmd=$( which $2 2>/dev/null )
if [ -x "$cmd" ]; then
read "$1" <<< "$cmd"
return 0
fi
test -z $3 || {
for alt in $3; do
cmd=$( which $alt 2>/dev/null )
if [ -x "$cmd" ]; then
read "$1" <<< "$cmd"
return 0
fi
done
}
echo -e "\e[1;31mERROR\e[0m: Command '$2' not found"
exit 1
}
checkoption() {
# $1 = arg
option="${1#*--}"
action="${option%%-*}"
name="${option#*-}"
if [ ${default_options[$name]+_} ]; then
case "$action" in
enable) meson_options[$name]=true;;
disable) meson_options[$name]=false;;
*) echo -e "\e[1;33mINFO\e[0m: Ignoring unknown action '$action'";;
esac
else
echo -e "\e[1;33mINFO\e[0m: Ignoring unknown option '$option'"
fi
}
echooption() {
# $1 = option
if [ ${meson_options[$1]+_} ]; then
echo ${meson_options[$1]}
elif [ ${default_options[$1]+_} ]; then
echo ${default_options[$1]}
fi
}
sanitycheck MESON 'meson'
sanitycheck MESONTEST 'mesontest'
sanitycheck NINJA 'ninja' 'ninja-build'
declare -A default_options=(
['introspection']=true
)
declare -A meson_options
while (($# > 0)); do
case "${1%%=*}" in
--prefix) read_arg prefix "$@" || shift;;
--bindir) read_arg bindir "$@" || shift;;
--sbindir) read_arg sbindir "$@" || shift;;
--libexecdir) read_arg libexecdir "$@" || shift;;
--datarootdir) read_arg datarootdir "$@" || shift;;
--datadir) read_arg datadir "$@" || shift;;
--sysconfdir) read_arg sysconfdir "$@" || shift;;
--libdir) read_arg libdir "$@" || shift;;
--mandir) read_arg mandir "$@" || shift;;
--includedir) read_arg includedir "$@" || shift;;
*) checkoption $1;;
esac
shift
done
# Defaults
test -z ${prefix} && prefix="/usr/local"
test -z ${bindir} && bindir=${prefix}/bin
test -z ${sbindir} && sbindir=${prefix}/sbin
test -z ${libexecdir} && libexecdir=${prefix}/bin
test -z ${datarootdir} && datarootdir=${prefix}/share
test -z ${datadir} && datadir=${datarootdir}
test -z ${sysconfdir} && sysconfdir=${prefix}/etc
test -z ${libdir} && libdir=${prefix}/lib
test -z ${mandir} && mandir=${prefix}/share/man
test -z ${includedir} && includedir=${prefix}/include
# The source directory is the location of this file
srcdir=$(dirname $0)
# The build directory is the current location
builddir=`pwd`
# If we're calling this file from the source directory then
# we automatically create a build directory and ensure that
# both Meson and Ninja invocations are relative to that
# location
if [[ -f "${builddir}/meson.build" ]]; then
mkdir -p _build
builddir="${builddir}/_build"
NINJA_OPT="-C ${builddir}"
fi
# Wrapper Makefile for Ninja
cat > Makefile <<END
# Generated by configure; do not edit
all:
CC="\$(CC)" CXX="\$(CXX)" ${NINJA} ${NINJA_OPT}
install:
DESTDIR="\$(DESTDIR)" ${NINJA} ${NINJA_OPT} install
check:
${MESONTEST} ${NINJA_OPT}
END
echo "
libgepub
========
meson: ${MESON}
ninja: ${NINJA}
prefix: ${prefix}
compiler: ${CC}
global flags: ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
introspection: $(echooption introspection)
Now type '${NINJA} -C ${builddir}' to build
"
cmd_options=""
for key in "${!meson_options[@]}"; do
cmd_options="$cmd_options -D${key/\-/_}=${meson_options[$key]}"
done
exec ${MESON} \
--prefix=${prefix} \
--libdir=${libdir} \
--libexecdir=${libexecdir} \
--datadir=${datadir} \
--sysconfdir=${sysconfdir} \
--bindir=${bindir} \
--includedir=${includedir} \
--mandir=${mandir} \
${cmd_options} \
${builddir} \
${srcdir}
......@@ -31,6 +31,7 @@ libversion = '@0@.@1@.@2@'.format(soversion, current, revision)
cc = meson.get_compiler('c')
gepub_deps = [
dependency('gepub_internals', fallback: ['libgepub_internals', 'libgepub_internals_dep']),
dependency('webkit2gtk-4.0'),
dependency('libsoup-2.4'),
dependency('glib-2.0'),
......
[package]
name = "gepub_internals"
version = "0.0.1"
authors = ["Daniel Garcia Moreno <danigm@wadobo.com>"]
[dependencies]
libc = "0.2"
epub = "1.1.1"
glib = "0.5.0"
[lib]
name = "gepub_internals"
crate-type = ["staticlib"]
project(
'libgepub_internals', 'rust',
version: '3.29.6',
license: 'GPLv3',
)
libgepub_internals_version = meson.project_version()
version_array = libgepub_internals_version.split('.')
libgepub_internals_major_version = version_array[0].to_int()
libgepub_internals_minor_version = version_array[1].to_int()
libgepub_internals_version_micro = version_array[2].to_int()
libgepub_internals_prefix = get_option('prefix')
cargo = find_program('cargo', required: true)
cargo_vendor = find_program('cargo-vendor', required: false)
cargo_script = find_program('scripts/cargo.sh')
grabber = find_program('scripts/grabber.sh')
cargo_release = find_program('scripts/release.sh')
c = run_command(grabber)
sources = c.stdout().strip().split('\n')
cargo_build = custom_target('cargo-build',
build_by_default: true,
input: sources,
output: ['libgepub_internals'],
install: false,
command: [cargo_script, '@CURRENT_SOURCE_DIR@', '@OUTPUT@'])
#gen = generator(cargo_script,
# arguments: ['@CURRENT_SOURCE_DIR@', '@OUTPUT@'],
# output: '@BASENAME@.a')
#libfiles = gen.process('libgepub_internals')
libgepub_internals_lib = static_library('epub_internals', cargo_build)
cc = meson.get_compiler('c')
libdir = meson.current_build_dir()
#libgepub_internals_lib = cc.find_library('gepub_internals', dirs: [libdir], required: false)
libgepub_internals_dep = declare_dependency(
link_with: libgepub_internals_lib,
)
#!/bin/sh
if [[ $DEBUG = true ]]
then
echo "DEBUG MODE"
cargo build --manifest-path $1/Cargo.toml && cp $1/target/debug/libepub_internals.a $2
else
echo "RELEASE MODE"
cargo build --manifest-path $1/Cargo.toml --release && cp $1/target/release/libepub_internals.a $2.a
fi
#!/bin/sh
find libgepub_internals -name *.rs
#!/bin/sh
VERSION=$1
DEST=${MESON_BUILD_ROOT}
DIST=$DEST/dist/$VERSION
cd "${MESON_SOURCE_ROOT}"
mkdir -p $DIST
# copying files
cp -rf fractal-gtk $DIST
cp -rf fractal-matrix-api $DIST
cp Cargo.toml $DIST
cp Cargo.lock $DIST
cp meson.build $DIST
cp fractal.doap $DIST
cp LICENSE.txt $DIST
cp README.md $DIST
cp -rf scripts $DIST
# cargo vendor
mkdir $DIST/.cargo
cargo vendor | sed 's/^directory = ".*"/directory = "vendor"/g' > $DIST/.cargo/config
cp -rf vendor $DIST/
# packaging
cd $DEST/dist
tar -cJvf $VERSION.tar.xz $VERSION
// TODO: manage errors, remove all unwraps
extern crate glib;
extern crate libc;
extern crate epub;
use std::mem;
use epub::doc::EpubDoc;
use self::glib::translate::*;
pub struct EpubResources {
elements: Vec<(String, String, String)>,
}
#[no_mangle]
pub extern "C" fn epub_new(path: *const libc::c_char) -> *mut EpubDoc {
let my_path = unsafe { &String::from_glib_none(path) };
let doc = EpubDoc::new(my_path);
let doc = doc.unwrap();
Box::into_raw(Box::new(doc))
}
#[no_mangle]
pub unsafe extern "C" fn epub_destroy(raw_doc: *mut EpubDoc) {
assert!(!raw_doc.is_null());
let _ = Box::from_raw(raw_doc);
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_resource(doc: *mut EpubDoc,
path: *const libc::c_char,
size: *mut i32)
-> *mut u8 {
assert!(!doc.is_null());
let my_path = &String::from_glib_none(path);
let mut v = (*doc).get_resource_by_path(my_path).unwrap();
*size = v.len() as i32;
v.shrink_to_fit();
let ptr = v.as_mut_ptr();
mem::forget(v);
ptr
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_resources(doc: *mut EpubDoc)
-> *mut EpubResources {
assert!(!doc.is_null());
let mut res: EpubResources = EpubResources {
elements: vec![],
};
for (k, v) in (*doc).resources.iter() {
res.elements.push((k.clone(), v.0.clone(), v.1.clone()));
}
Box::into_raw(Box::new(res))
}
#[no_mangle]
pub unsafe extern "C" fn epub_resources_get_length(er: *mut EpubResources)
-> usize {
(*er).elements.len()
}
#[no_mangle]
pub unsafe extern "C" fn epub_resources_get_id(er: *mut EpubResources, i: usize)
-> *const libc::c_char {
let ref ret = (*er).elements[i].0;
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_resources_get_path(er: *mut EpubResources, i: usize)
-> *const libc::c_char {
let ref ret = (*er).elements[i].1;
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_resources_get_mime(er: *mut EpubResources, i: usize)
-> *const libc::c_char {
let ref ret = (*er).elements[i].2;
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_resource_by_id(doc: *mut EpubDoc,
id: *const libc::c_char,
size: *mut i32)
-> *mut u8 {
assert!(!doc.is_null());
let my_id = &String::from_glib_none(id);
let mut v = (*doc).get_resource(my_id).unwrap();
*size = v.len() as i32;
v.shrink_to_fit();
let ptr = v.as_mut_ptr();
mem::forget(v);
ptr
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_metadata(doc: *mut EpubDoc,
mdata: *const libc::c_char)
-> *const libc::c_char {
assert!(!doc.is_null());
let mut ret = String::from("");
let my_mdata = &String::from_glib_none(mdata);
if let Some(mdata) = (*doc).mdata(my_mdata) {
ret = mdata.clone();
}
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_resource_mime(doc: *mut EpubDoc,
path: *const libc::c_char)
-> *const libc::c_char {
assert!(!doc.is_null());
let mut ret = String::from("");
let my_path = &String::from_glib_none(path);
if let Ok(m) = (*doc).get_resource_mime_by_path(my_path) {
ret = m.clone();
}
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_resource_mime_by_id(doc: *mut EpubDoc,
id: *const libc::c_char)
-> *const libc::c_char {
assert!(!doc.is_null());
let mut ret = String::from("");
let my_id = &String::from_glib_none(id);
if let Ok(m) = (*doc).get_resource_mime(my_id) {
ret = m.clone();
}
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_current_mime(doc: *mut EpubDoc) -> *const libc::c_char {
assert!(!doc.is_null());
let mut ret = String::from("");
if let Ok(m) = (*doc).get_current_mime() {
ret = m.clone();
}
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_current(doc: *mut EpubDoc, size: *mut i32) -> *mut u8 {
assert!(!doc.is_null());
let mut v = (*doc).get_current().unwrap();
*size = v.len() as i32;
v.shrink_to_fit();
let ptr = v.as_mut_ptr();
mem::forget(v);
ptr
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_current_with_epub_uris(doc: *mut EpubDoc,
size: *mut i32)
-> *mut u8 {
assert!(!doc.is_null());
let mut v = (*doc).get_current_with_epub_uris().unwrap();
*size = v.len() as i32;
v.shrink_to_fit();
let ptr = v.as_mut_ptr();
mem::forget(v);
ptr
}
#[no_mangle]
pub unsafe extern "C" fn epub_set_page(doc: *mut EpubDoc, n: usize) {
let _ = (*doc).set_current_page(n);
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_num_pages(doc: *mut EpubDoc) -> usize {
(*doc).get_num_pages()
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_page(doc: *mut EpubDoc) -> usize {
(*doc).get_current_page()
}
#[no_mangle]
pub unsafe extern "C" fn epub_next_page(doc: *mut EpubDoc) -> bool {
match (*doc).go_next() {
Ok(_) => return true,
Err(_) => return false,
}
}
#[no_mangle]
pub unsafe extern "C" fn epub_prev_page(doc: *mut EpubDoc) -> bool {
match (*doc).go_prev() {
Ok(_) => return true,
Err(_) => return false,
}
}
#[no_mangle]
pub unsafe extern "C" fn epub_get_cover(doc: *mut EpubDoc) -> *const libc::c_char {
let mut ret = String::from("");
if let Ok(cid) = (*doc).get_cover_id() {
if let Some(m) = (*doc).resources.get(&cid) {
ret = m.0.clone();
}
}
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_resource_path(doc: *mut EpubDoc,
id: *const libc::c_char)
-> *const libc::c_char {
let my_id = &String::from_glib_none(id);
let mut ret = String::from("");
if let Some(m) = (*doc).resources.get(my_id) {
ret = m.0.clone();
}
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_current_path(doc: *mut EpubDoc) -> *const libc::c_char {
let mut ret = String::from("");
if let Ok(m) = (*doc).get_current_path() {
ret = m.clone();
}
ret.to_glib_full()
}
#[no_mangle]
pub unsafe extern "C" fn epub_current_id(doc: *mut EpubDoc) -> *const libc::c_char {
let mut ret = String::from("");
if let Ok(m) = (*doc).get_current_id() {
ret = m.clone();
}
ret.to_glib_full()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment