#!/bin/sh
set -e

cat > smoke.cpp <<'EOF'
#include <crengine-ng-config.h>
#include <crengine.h>
#include <lvstreamutils.h>

#include <cstdio>
#include <cstring>

int main()
{
    /* The library has the data directory baked in at compile time; check
     * that the hyphenation data really is installed where it says. */
    lString8 path(CRE_NG_DATADIR);
    path << "hyph/hyph-en-us.pattern";

    LVStreamRef stream = LVOpenFileStream(path.c_str(), LVOM_READ);
    if (stream.isNull()) {
        fprintf(stderr, "cannot open %s\n", path.c_str());
        return 1;
    }
    stream->Close();

    /* LVExtractFilename() lives in the shared library, so this also checks
     * that the pkg-config link flags actually resolve. */
    lString8 name = LVExtractFilename(path);
    printf("opened %s from %s\n", name.c_str(), CRE_NG_DATADIR);

    return strcmp(name.c_str(), "hyph-en-us.pattern") == 0 ? 0 : 1;
}
EOF

g++ -Wall -o smoke smoke.cpp $(pkg-config --cflags --libs crengine-ng)
./smoke
