Tuesday, January 18, 2011

compile java program with gcj

#!/bin/bash
# compile java program with gcj
# usage:
#            mygcj myMain.java [otherJavaFiles]
# copyright @ http://scriptdemo.blogspot.com
if [ $# -eq 0 ]; then
   sed -n '2,4p' mygcj
   exit
else
   numfile=$#
   IsMain=1
   myfiles=""
   for srcfile in $*
   do
      nf=`echo ${srcfile} | awk -F. '{print NF}'`
      if [ $nf -eq 1 ]; then
         srcfilename=${srcfile}
         srcfile=${srcfilename}.java
      elif [ $nf -eq 2 ]; then
         srcfilename=`echo ${srcfile} | awk -F. '{print $1}'`
      fi
      [ ! -e ${srcfile} ] && echo "${srcfile} can\'t be found in current directory!" && exit
      if [ $IsMain -eq 1 ]; then
         mainfile=$srcfilename; IsMain=0
      fi
      myfiles="${myfiles} ${srcfile}"
   done
   gcj ${myfiles} --main=${mainfile} -o ${mainfile}
fi

No comments:

ShowCalendar