-*- mode: org -*-
#+TITLE:       configuration meson
#+DESCRIPTION: documents - structuring, various output representations & search
#+FILETAGS:    :spine:hub:
#+AUTHOR:      Ralph Amissah
#+EMAIL:       [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]]
#+COPYRIGHT:   Copyright (C) 2015 - 2023 Ralph Amissah
#+LANGUAGE:    en
#+STARTUP:     content hideblocks hidestars noindent entitiespretty
#+PROPERTY:    header-args  :exports code
#+PROPERTY:    header-args+ :noweb yes
#+PROPERTY:    header-args+ :results no
#+PROPERTY:    header-args+ :cache no
#+PROPERTY:    header-args+ :padline no
#+PROPERTY:    header-args+ :mkdirp yes
#+OPTIONS:     H:3 num:nil toc:t \n:t ::t |:t ^:nil -:t f:t *:t

- [[./doc-reform.org][doc-reform.org]]  [[./][org/]]

* spine
** version info SET VERSION :version:set:project:
*** project SET VERSION

#+NAME: spine_version_set
#+BEGIN_SRC sh
0.12.0
#+END_SRC

*** subprojects

- d2sqlite3
  https://code.dlang.org/packages/d2sqlite3

#+NAME: d2sqlite3_version_set
#+BEGIN_SRC sh
0.19.1
#+END_SRC

- imageformats
  https://code.dlang.org/packages/imageformats

#+NAME: imageformats_version_set
#+BEGIN_SRC sh
7.0.2
#+END_SRC

- dyaml
  https://code.dlang.org/packages/dyaml

#+NAME: dyaml_version_set
#+BEGIN_SRC sh
0.8.3
#+END_SRC

- tinyendian
  https://code.dlang.org/packages/tinyendian

#+NAME: tinyendian_version_set
#+BEGIN_SRC sh
0.2.0
#+END_SRC

*** build tools if specified

- meson

#+NAME: meson_version_set
#+BEGIN_SRC sh
0.46
#+END_SRC

- soversion

#+NAME: soversion_version_set
#+BEGIN_SRC sh
0
#+END_SRC

** meson REVISIT :meson:build:
*** notes

https://mesonbuild.com/D.html
https://mesonbuild.com/Dependencies.html#Dub
- create and move to subdirectory
  rm -r build; mkdir build && cd build

- build

  - regular build (faster compile time):
    meson && ninja

  - optimized build (faster program run time):
    meson --buildtype=debugoptimized && ninja

  - time build
    time ( meson --buildtype=debugoptimized && ninja )

- other
  - flags
    DFLAGS= DC=ldc2 meson ..

**** projects :project:

ls -1 ./src/*/**/*.d
tree -fi ./src |rg "\.d$"
fdfind -e .d

tree -if src | rg ".+\.d$" > spine_sources.txt && \
for i in spine_sources.txt; do; \
sed -i "s/\(.\+\.d$\)/  '\1',/g" $i; done && \
cat spine_sources.txt

***** project meson.build :filelist:

#+HEADER: :tangle ../meson.build
#+HEADER: :noweb yes
#+BEGIN_SRC sh
project('spine', 'd',
  license: 'AGPL-3',
  version: '<<spine_version_set>>',
  meson_version: '>=<<meson_version_set>>'
)
#if meson.get_compiler('d').get_id() == 'gcc'
#    error('spine cannot be compiled with GDC at time. Sorry.')
#endif
spine_src = [
  'src/doc_reform/spine.d',
  'src/doc_reform/conf/compile_time_info.d',
  'src/doc_reform/io_in/paths_source.d',
  'src/doc_reform/io_in/read_config_files.d',
  'src/doc_reform/io_in/read_source_files.d',
  'src/doc_reform/io_out/cgi_sqlite_search_form.d',
  'src/doc_reform/io_out/create_zip_file.d',
  'src/doc_reform/io_out/defaults.d',
  'src/doc_reform/io_out/epub3.d',
  'src/doc_reform/io_out/html.d',
  'src/doc_reform/io_out/hub.d',
  'src/doc_reform/io_out/latex.d',
  'src/doc_reform/io_out/metadata.d',
  'src/doc_reform/io_out/odt.d',
  'src/doc_reform/io_out/package.d',
  'src/doc_reform/io_out/paths_output.d',
  'src/doc_reform/io_out/rgx.d',
  'src/doc_reform/io_out/source_pod.d',
  'src/doc_reform/io_out/sqlite.d',
  'src/doc_reform/io_out/xmls_css.d',
  'src/doc_reform/io_out/xmls.d',
  'src/doc_reform/meta/conf_make_meta_json.d',
  'src/doc_reform/meta/conf_make_meta_structs.d',
  'src/doc_reform/meta/conf_make_meta_yaml.d',
  'src/doc_reform/meta/defaults.d',
  'src/doc_reform/meta/doc_debugs.d',
  'src/doc_reform/meta/metadoc.d',
  'src/doc_reform/meta/metadoc_from_src.d',
  'src/doc_reform/meta/metadoc_curate.d',
  'src/doc_reform/meta/metadoc_curate_authors.d',
  'src/doc_reform/meta/metadoc_curate_topics.d',
  'src/doc_reform/meta/metadoc_object_setter.d',
  'src/doc_reform/meta/metadoc_show_config.d',
  'src/doc_reform/meta/metadoc_show_make.d',
  'src/doc_reform/meta/metadoc_show_metadata.d',
  'src/doc_reform/meta/metadoc_show_summary.d',
  'src/doc_reform/meta/package.d',
  'src/doc_reform/meta/rgx.d',
  'src/doc_reform/share/defaults.d',
]
source_root = meson.source_root()
src_dir = include_directories('src/')
# Dependencies
dep_tinyendian   = dependency('tinyendian',   version: '>= <<tinyendian_version_set>>',  fallback: ['tinyendian',   'tinyendian_dep'],   method: 'dub')
dep_dyaml        = dependency('dyaml',        version: '>= <<dyaml_version_set>>',  fallback: ['dyaml',        'dyaml_dep'],        method: 'dub')
dep_d2sqlite3    = dependency('d2sqlite3',    version: '>= <<d2sqlite3_version_set>>', fallback: ['d2sqlite3',    'd2sqlite3_dep'],    method: 'dub')
dep_imageformats = dependency('imageformats', version: '>= <<imageformats_version_set>>',  fallback: ['imageformats', 'imageformats_dep'], method: 'dub')
# Executable
spine_exe = executable('spine',
  [spine_src],
  include_directories : [src_dir],
  d_import_dirs: [include_directories('views')],
  dependencies : [
    dep_tinyendian,
    dep_dyaml,
    dep_d2sqlite3,
    dep_imageformats,
  ],
  install : true
)
#+END_SRC

*** meson subprojects [taken care of using dub] :subprojects:
**** README

#+HEADER: :tangle ../subprojects/README
#+BEGIN_SRC txt
- d2sqlite3
  - dub
    - https://code.dlang.org/packages/d2sqlite3
  - upstream
    - https://github.com/dlang-community/d2sqlite3
- dyaml
  - dub
    - https://code.dlang.org/packages/dyaml
  - upstream
    - https://github.com/dlang-community/D-YAML
  - upstream git clone
    - https://github.com/dlang-community/D-YAML.git
- imageformats
  - dub
    - https://code.dlang.org/packages/imageformats
  - upstream git clone
    - https://github.com/lgvz/imageformats
- tinyendian (dyaml dependency)
  - dub
    - https://code.dlang.org/packages/tinyendian
  - upstream git clone
    - https://github.com/dlang-community/tinyendian.git
#+END_SRC

**** d2sqlite3 :d2sqlite3:
*****  wrap

#+HEADER: :tangle ../subprojects/d2sqlite3.wrap
#+BEGIN_SRC sh
[wrap-git]
directory = d2sqlite3
url       = https://github.com/dlang-community/d2sqlite3.git
revision  = head
#+END_SRC

*****  meson.build

#+HEADER: :NO-tangle ../subprojects/d2sqlite3.meson.build
#+HEADER: :noweb yes
#+BEGIN_SRC sh
project('d2sqlite3', 'd',
  meson_version: '>=<<meson_version_set>>',
  license: 'BSL-1.0',
  version: '<<d2sqlite3_version_set>>'
)

project_soversion = '<<soversion_version_set>>'

src_dir = include_directories('source/')
pkgc = import('pkgconfig')

sqlite_dep = dependency('sqlite3')

d2sqlite3_src = [
  'source/d2sqlite3/database.d',
  'source/d2sqlite3/internal/memory.d',
  'source/d2sqlite3/internal/util.d',
  'source/d2sqlite3/library.d',
  'source/d2sqlite3/package.d',
  'source/d2sqlite3/results.d',
  'source/d2sqlite3/sqlite3.d',
  'source/d2sqlite3/statement.d',
]
install_subdir('source/d2sqlite3/', install_dir: 'include/d/d2sqlite3/')

d2sqlite3_lib = library('d2sqlite3',
  [d2sqlite3_src],
  include_directories: [src_dir],
  dependencies: [sqlite_dep],
  install: true,
  version: meson.project_version(),
  soversion: project_soversion
)

pkgc.generate(name: 'd2sqlite3',
  libraries: d2sqlite3_lib,
  subdirs: 'd/d2sqlite3/',
  version: meson.project_version(),
  requires: ['sqlite3'],
  description: 'A small wrapper around SQLite for the D programming language.'
)

# for use by others which embed this as subproject
d2sqlite3_dep = declare_dependency(
  link_with: [d2sqlite3_lib],
  dependencies: [sqlite_dep],
  include_directories: [src_dir]
)
#+END_SRC

**** dyaml :dyaml:
*****  wrap

#+HEADER: :tangle ../subprojects/dyaml.wrap
#+BEGIN_SRC sh
[wrap-git]
directory = dyaml
url       = https://github.com/dlang-community/D-YAML.git
revision  = head
#+END_SRC

*****  meson.build (provided by upstream)

Upstream provides meson.build

#+HEADER: :NO-tangle ../subprojects/D-YAML/meson.build
#+HEADER: :noweb yes
#+BEGIN_SRC sh
project('D-YAML', 'd',
    meson_version: '>=<<meson_version_set>>',
    subproject_dir: 'contrib',
    version: '<<dyaml_version_set>>'
)

project_soversion    = '<<soversion_version_set>>'

src_dir = include_directories('source/')
pkgc = import('pkgconfig')

dyaml_src = [
    'source/dyaml/composer.d',
    'source/dyaml/constructor.d',
    'source/dyaml/dumper.d',
    'source/dyaml/emitter.d',
    'source/dyaml/encoding.d',
    'source/dyaml/escapes.d',
    'source/dyaml/event.d',
    'source/dyaml/exception.d',
    'source/dyaml/linebreak.d',
    'source/dyaml/loader.d',
    'source/dyaml/node.d',
    'source/dyaml/package.d',
    'source/dyaml/parser.d',
    'source/dyaml/queue.d',
    'source/dyaml/reader.d',
    'source/dyaml/representer.d',
    'source/dyaml/resolver.d',
    'source/dyaml/scanner.d',
    'source/dyaml/serializer.d',
    'source/dyaml/style.d',
    'source/dyaml/tagdirective.d',
    'source/dyaml/test/common.d',
    'source/dyaml/test/compare.d',
    'source/dyaml/test/constructor.d',
    'source/dyaml/test/emitter.d',
    'source/dyaml/test/errors.d',
    'source/dyaml/test/inputoutput.d',
    'source/dyaml/test/reader.d',
    'source/dyaml/test/representer.d',
    'source/dyaml/test/resolver.d',
    'source/dyaml/test/tokens.d',
    'source/dyaml/token.d'
]
install_subdir('source/dyaml', install_dir: 'include/d/yaml/')

tinyendian_dep = dependency('tinyendian', version: '>=<<tinyendian_version_set>>', fallback: ['tinyendian', 'tinyendian_dep'])

dyaml_lib = library('dyaml',
        [dyaml_src],
        include_directories: [src_dir],
        dependencies: [tinyendian_dep],
        install: true,
        version: meson.project_version(),
        soversion: project_soversion
)
pkgc.generate(name: 'dyaml',
              libraries: dyaml_lib,
              subdirs: 'd/yaml/',
              version: meson.project_version(),
              description: 'YAML parser and emitter for the D programming language.'
)

# Make D-YAML easy to use as subproject
dyaml_dep = declare_dependency(
    link_with: dyaml_lib,
    include_directories: [src_dir],
    dependencies: [tinyendian_dep]
)
#+END_SRC

**** imageformats :imageformats:
*****  wrap

#+HEADER: :tangle ../subprojects/imageformats.wrap
#+BEGIN_SRC sh
[wrap-git]
directory = imageformats
url       = https://github.com/lgvz/imageformats.git
revision  = head
#+END_SRC

*****  meson.build

#+HEADER: :NO-tangle ../subprojects/imageformats.meson.build
#+HEADER: :noweb yes
#+BEGIN_SRC sh
project('imageformats', 'd',
  meson_version: '>=<<meson_version_set>>',
  license: 'BSL-1.0',
  version: '<<imageformats_version_set>>'
)

project_soversion = '<<soversion_version_set>>'

src_dir = include_directories('.')
pkgc = import('pkgconfig')

imageformats_src = [
  'imageformats/bmp.d',
  'imageformats/jpeg.d',
  'imageformats/package.d',
  'imageformats/png.d',
  'imageformats/tga.d'
]
install_subdir('imageformats/', install_dir: 'include/d/imageformats-d/')

imageformats_lib = library('imageformats-d',
  [imageformats_src],
  include_directories: [src_dir],
  install: true,
  version: meson.project_version(),
  soversion: project_soversion
)

pkgc.generate(name: 'imageformats-d',
  libraries: imageformats_lib,
  subdirs: 'd/imageformats-d/',
  version: meson.project_version(),
  description: 'Decoders for PNG, TGA, BMP, JPEG and encoders for PNG, TGA, BMP.'
)

# for use by others which embed this as subproject
imageformats_dep = declare_dependency(
    link_with: [imageformats_lib],
    include_directories: [src_dir]
)
#+END_SRC

**** tinyendian (dyaml dependency) :tinyendian:
*****  wrap

#+HEADER: :tangle ../subprojects/tinyendian.wrap
#+BEGIN_SRC sh
[wrap-git]
directory = tinyendian
url       = https://github.com/dlang-community/tinyendian.git
revision  = head
#+END_SRC

*****  meson.build (provided by upstream)

Upstream provides meson.build

#+HEADER: :NO-tangle ../subprojects/tinyendian/meson.build
#+HEADER: :noweb yes
#+BEGIN_SRC sh
# -*- mode: python; -*-

project(
    'tinyendian',
    'd',
    meson_version: '>=<<meson_version_set>>',
    version: '<<tinyendian_version_set>>',
    default_options: ['buildtype=release'],
)

src_dir = include_directories('source/')
pkgc = import('pkgconfig')

tinyendian_src = [
    'source/tinyendian.d'
]

install_headers(tinyendian_src, subdir: 'd/')

tinyendian_lib = library(
    meson.project_name(),
    [tinyendian_src],
    include_directories: [src_dir],
    version: meson.project_version(),
    pic: true,
    install: true,
)

pkgc.generate(
    name: meson.project_name(),
    libraries: tinyendian_lib,
    subdirs: 'd/',
    version: meson.project_version(),
    description: 'Lightweight endianness library for D.'
)

# Make Tinyendian easy to use as subproject
tinyendian_dep = declare_dependency(
    link_with: tinyendian_lib,
    include_directories: [src_dir]
)
#+END_SRC