#!/command/execlineb -P

# Compile convert-leapsecs.c, then use this to create
# src/libstddjb/leapsecs_table.c

define PREFIX ./tools

backtick -n N
{
  pipeline
  {
    redirfd -r 0 ${PREFIX}/leapsecs.txt
    ${PREFIX}/convert-leapsecs
  }
  wc -l
}
import -u N

if
{
  s6-echo "/* ISC license. */

/* This file has been generated by ./tools/make-leapsecs_table */

#include <skalibs/uint64.h>
#include <skalibs/tai.h>
#include \"djbtime-internal.h\"

unsigned int const leapsecs_table_len = ${N} ;
static uint64_t const leapsecs_table_[${N}] =\n{"
}

if
{
  redirfd -r 0 ${PREFIX}/leapsecs.txt
  ${PREFIX}/convert-leapsecs
}

s6-echo "} ;\nuint64_t const *const leapsecs_table = leapsecs_table_ ;"
