#!/bin/bash

GEN_NM_SETTING_CONST_FILE=../nm_setting_const_gen.go

if [ ! -d /usr/include/libnm ]; then
    echo "please install libnm-dev and retry"
    exit 1
fi

echo "// This file is automatically generated, please don't edit manually." > ${GEN_NM_SETTING_CONST_FILE}
echo -e "package network\n" >> ${GEN_NM_SETTING_CONST_FILE}
for f in /usr/include/libnm/nm-setting*.h; do
  echo "// $f";
  echo "const (";
  grep '^#define.*".*"' "$f" | awk '{print $2,"=",$3}';
  echo -e ")\n";
done >> ${GEN_NM_SETTING_CONST_FILE}
gofmt -w ${GEN_NM_SETTING_CONST_FILE}

echo "GEN ${GEN_NM_SETTING_CONST_FILE}"
