#!/usr/bin/bash

# Copyright (C) 2019 NEC Corporation
# This file is part of the VEOS.
#
# The VEOS is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# The VEOS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with the VEOS; if not, see
# <http://www.gnu.org/licenses/>

#update PATH_NREADELF with the path of nreadelf of your system.

PATH_NREADELF="/opt/nec/ve/bin/nreadelf"

# 2.?.? or later -> 1.002.000.000
GNU_VRSN=1002000000

for FILE in $*; do

 ERROR=`$PATH_NREADELF -p .comment $FILE 2>&1 1> /dev/null`

 if [ -n "$ERROR" ]; then
  continue
 fi

 MUSL="NO"

 for COMPILER in ncc nfort ; do

  for VRSN in \
   `$PATH_NREADELF -p .comment $FILE | grep $COMPILER | \
       awk '{print $4}' | awk -F. '{printf "1%03d%03d%03d\n", $1,$2,$3}'`; do

   if (( $VRSN < $GNU_VRSN )) ;
   then
    MUSL="YES"
   fi

  done

 done

 if [ $MUSL = "YES" ]; then
  echo "This is compiled with musl-libc: $FILE"
 fi

done
