#!/bin/bash

HDRS="robotnik_82575.h robotnik_api.h robotnik_defines.h robotnik_hw.h robotnik_mac.h robotnik_manage.h robotnik_mbx.h robotnik_nvm.h robotnik_osdep.h robotnik_phy.h robotnik_regs.h robotnik.h robotnik_regtest.h robotnik_vmdq.h kcompat.h"
SRCS="robotnik_82575.c robotnik_api.c robotnik_mac.c robotnik_manage.c robotnik_mbx.c robotnik_nvm.c robotnik_phy.c robotnik_ethtool.c robotnik_hwmon.c robotnik_main.c robotnik_param.c robotnik_procfs.c robotnik_ptp.c robotnik_vmdq.c"

for HDR in $HDRS
do
  echo "Unused macros from $HDR"
  MACROS="${HDR}.macros"

  make $MACROS

  grep -f $MACROS -o -h $SRCS > tmp2.txt
  for H in $HDRS
  do
    if [ "$H" != "$HDR" ]
    then
      grep -f $MACROS -o -h $H >> tmp2.txt
    fi
  done

  sort tmp2.txt | uniq > tmp3.txt

  grep -vf tmp3.txt $MACROS > tmp4.txt

  wc -l tmp4.txt
  cat tmp4.txt

done
