Commit 579185ab authored by Canek Peláez's avatar Canek Peláez
Browse files

Libraryfication.

parent 01d1cf25
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
glib-2.0
gio-2.0
gobject-2.0
gee-0.8
soup-2.4

data/commonmark.pc.in

0 → 100644
+13 −0
Original line number Diff line number Diff line
prefix=@prefix@
exec_prefix=${prefix}
libdir=@libdir@
datadir=@prefix@/share
includedir=@prefix@/include

Name: libgxml
Description: A Vala library for rendering Markdown
URL: https://aztlan.fciencias.unam.mx/gitlab/canek/commonmark
Version: @PROJECT_VERSION@
Requires: glib-2.0 >= 2.38 gio-2.0 >= 2.38 gobject-2.0 >= 2.38 gee-0.8 >= 0.20 soup-2.4 >= 2.4
Libs: -L${libdir} -lgxml
Cflags: -I${includedir}/gxml
+119 −31
Original line number Diff line number Diff line
@@ -2,6 +2,20 @@ project('commonmark', ['vala', 'c'],
        version: '0.1',
        license: 'GPL3')

PROJECT_NAME = meson.project_name()
PROJECT_VERSION = meson.project_version()
VERSIONED_PROJECT_NAME = PROJECT_NAME + '-' + PROJECT_VERSION
CAMEL_CASE_NAME = 'Commonmark'
VERSIONED_CAMEL_CASE_NAME = CAMEL_CASE_NAME + '-'+  PROJECT_VERSION

libcommonmark_deps = [ dependency('glib-2.0'),
                       dependency('gio-2.0'),
                       dependency('gee-0.8'),
                       dependency('libsoup-2.4') ]

VALADEPS = 'glib-2.0\ngio-2.0\ngobject-2.0\ngee-0.8\nsoup-2.4'
PCDEPS = 'glib-2.0 gio-2.0 gobject-2.0 gee-0.8 soup-2.4'

add_project_arguments(['--vapidir=.',
                       '--target-glib=2.38'],
                      language: 'vala')
@@ -13,22 +27,40 @@ add_project_arguments(['--std=c99',
                      language: 'c')

cc = meson.get_compiler('c')
math = cc.find_library('m', required: true)
glib = dependency('glib-2.0')
gio = dependency('gio-2.0')
gobject = dependency('glib-2.0')
gee = dependency('gee-0.8')
soup = dependency('libsoup-2.4')

# libtest (named check because of meson)
check_sources = [
  'lib/test/test-case.vala'
]
vapidir = join_paths(get_option('datadir'), 'vala', 'vapi')
GIR_NAME= VERSIONED_CAMEL_CASE_NAME + '.gir'
TYPELIB_NAME= VERSIONED_CAMEL_CASE_NAME + '.typelib'
VAPI_NAME = VERSIONED_PROJECT_NAME + '.vapi'

check = static_library('check', check_sources,
                       dependencies: [ gio, glib ])
conf = configuration_data()
conf.set('prefix', get_option('prefix'))
conf.set('libdir', '${exec_prefix}/' + get_option('libdir'))
conf.set('PCDEPS', PCDEPS)
conf.set('PROJECT_NAME', PROJECT_NAME)
conf.set('PROJECT_VERSION', PROJECT_VERSION)

check_includes = include_directories('lib/test')
configure_file(input : 'data/commonmark.pc.in',
    output : 'commonmark.pc',
    configuration : conf,
    install : true,
    install_dir : join_paths(get_option('libdir'), 'pkgconfig'))

configure_file(input : 'data/commonmark.deps.in',
    output : 'commonmark.deps',
    configuration : conf,
    install : true,
    install_dir : vapidir)

confh = configuration_data()
confh.set_quoted('PACKAGE_LOCALE_DIR', join_paths(get_option('prefix'), get_option('datadir'), 'locale'))
confh.set_quoted('GETTEXT_PACKAGE', 'Commonmark')
configure_file(output : 'config.h',
               configuration : confh)

configvapi = files('vapi/config.vapi')

valadoc = find_program('valadoc', required: false)

gnome = import('gnome')
resources = gnome.compile_resources(
@@ -36,7 +68,8 @@ resources = gnome.compile_resources(
  source_dir: 'data',
  c_name: 'resources')

commonmark_sources = [
libcommonmark_sources = [
  resources,
  'lib/commonmark/extension.vala',
  'lib/commonmark/internal/block-content.vala',
  'lib/commonmark/internal/block-continue-impl.vala',
@@ -155,23 +188,78 @@ commonmark_sources = [
  'lib/commonmark/util/linked-set.vala'
]

commonmark = static_library('commonmark', commonmark_sources,
                            dependencies: [ glib, gio, gobject, gee, soup ])
commonmark_includes = include_directories([
  'lib/commonmark',
  'lib/commonmark/parser',
  'lib/commonmark/node'
inc_rooth = include_directories('.')
inc_rooth_dep = declare_dependency(include_directories : inc_rooth)

inc_libh = include_directories('lib')
inc_libh_dep = declare_dependency(include_directories : inc_libh)

# LT_VERSION for ABI related changes
# From: https://autotools.io/libtool/version.html
# This rules applies to Meson 0.43 and newer
# Increase the current value whenever an interface has been added, removed or changed.
# Always increase revision value whenever an interface has been added, removed or changed.
# Increase the age value only if the changes made to the ABI are backward compatible.
# Set version to the value of subtract age from current
# Reset current and version to 1 and, age and version to 0 if library's name is changed
LT_CURRENT='3'
LT_REVISION='2'
LT_AGE='0'
LT_VERSION='2'
libcommonmark = library(
  VERSIONED_PROJECT_NAME,
  libcommonmark_sources + configvapi,
  version : LT_VERSION,
  soversion : LT_VERSION + '.' + LT_AGE + '.' + LT_REVISION,
  darwin_versions : [ LT_CURRENT.to_int() + 1,
                      '@0@.@1@'.format(LT_CURRENT.to_int() + 1,
                                       LT_REVISION) ],
  vala_header : PROJECT_NAME+'.h',
  vala_vapi : VAPI_NAME,
  vala_gir : GIR_NAME,
  dependencies : [ libcommonmark_deps, inc_libh_dep, inc_rooth_dep ],
  vala_args: [ '--abi-stability' ],
  c_args : [ '-include', meson.current_build_dir() + '/config.h', ],
  install : true,
  install_dir : [
    true,
    join_paths(get_option('includedir'), 'gxml', 'gxml'),
    vapidir,
    get_option('introspection')
  ])

cm_sources = [
  resources,
  'src/main.vala'
if valadoc.found()
  pkgs = [ 'config', 'glib-2.0', 'gio-2.0', 'gee-0.8',  'libsoup-2.4' ]
  docdir = 'doc'
  command_pkgs = []
  foreach pkg : pkgs
    command_pkgs = command_pkgs + [ '--pkg=' + pkg ]
  endforeach
  doc = custom_target('documentation',
                      output: docdir,
                      input: libcommonmark_sources,
                      command: [ valadoc,
                                 '--directory=@OUTPUT@',
                                 '--force',
                                 '--use-svg-images',
                                 '--package-name=' + meson.project_name(),
                                 '--package-version=' + meson.project_version(),
                                 '--target-glib=2.68',
                                 '--vapidir=' + vapidir ] +
                               command_pkgs +
                               ['@INPUT@'],
                      install: false)
endif

# libtest (named check because of meson)
check_sources = [
  'lib/test/test-case.vala'
]
executable(meson.project_name(), cm_sources,
           dependencies: [ math, gee, gio, soup ],
           include_directories: commonmark_includes,
           link_with: [ commonmark ],
           install: true)

check = static_library('check', check_sources,
                       dependencies: libcommonmark_deps)

check_includes = include_directories('lib/test')

# tests
check_parser_vala_sources = [ 'test/test-parser.vala' ]
@@ -182,6 +270,6 @@ check_parser_sources = [
]

check_parser = executable('test-parser', check_parser_sources,
                          dependencies: [ glib, gio, gee ],
                          link_with: [ check, commonmark ])
                          dependencies: libcommonmark_deps,
                          link_with: [ check, libcommonmark ])
test('Test parser', check_parser)

meson_options.txt

0 → 100644
+8 −0
Original line number Diff line number Diff line
option('introspection',
       type : 'boolean',
       value : true,
       description : 'Create GObject Introspection file definitions')
option('docs',
       type : 'boolean',
       value : true,
       description : 'Generate Vala Documentation')

src/main.vala

deleted100644 → 0
+0 −54
Original line number Diff line number Diff line
using Commonmark.Internal;
using Commonmark.Internal.Util;

namespace Commonmark {

    // public static string spaces(int n) {
    //     var sb = new GLib.StringBuilder();
    //     for (int i = 0; i < n; i++)
    //         sb.append(" ");
    //     return sb.str;
    // }

    // public static void traverse(Node.Node node, int level=0) {
    //     if (node == null)
    //         return;
    //     var sp = spaces(level);
    //     stderr.printf("%sNode: %s\n", sp, node.to_string());
    //     var n = node.first_child;
    //     while (n != null) {
    //         traverse(n, level + 4);
    //         n = n.next;
    //     }
    // }

    public static int main(string[] args) {
        /* Forcing static construct. */
        if (new Html5Entities().get_type().name() == args[0] ||
            new Escaping().get_type().name() == args[0] ||
            new DocumentParser.from().get_type().name() == args[0])
            GLib.error("Error forcing static construct");

        try {
            var file = GLib.File.new_for_path("./data/test.md");
            var dis = new GLib.DataInputStream(file.read());
            var sb = new StringBuilder();
            string line;
            while ((line = dis.read_line(null)) != null) {
                sb.append(line);
                sb.append("\n");
            }
            var content = sb.str;
            var parser = Parser.Parser.builder().build();
            var document = parser.parse(content);
            // traverse(document);
            var renderer = Renderer.Html.HtmlRenderer.builder().build();
            var html = renderer.render(document);
            stdout.printf("%s", html);
        } catch (GLib.Error error) {
            GLib.error ("%s", error.message);
        }

        return 0;
    }
}
Loading