#!/bin/bash
# mk_c_src.sh 

# THE MONSTER EATER SILICON ... lol
# O MONSTRO COMEDOR DE SILICIO ... rsrsrsrs

# THIS SCRIPT IS FREE FOR ALL AND FOREVER. 

# ANSI C Script to Make .c's files to testing.
# --------------------------------------------

# Last Update ... Fortaleza,Ce (Brasil) DD/MM/YYYY - 01/12/2014.
# Start ......... Fortaleza,Ce (Brasil) DD/MM/YYYY - 14/11/2014.
#

# Script para Estudantes da linguagem ANSI C.
# Script for Students of ANSI C language.
# -------------------------------------------

# Cria arquivos fontes (.c) bem como o Makefile.
# Creates source files (.c) and the Makefile.
# ----------------------------------------------

# Para testes de STRESS, FUNCOES, PILHA, SIMBOLOS, VARIAVEIS, PARAMETROS, MEMORIA etc,etc,etc ... 
# To test STRESS, FEATURES, CELL, SYMBOLS, VARIABLE, SETUP, MEMORY etc, etc, etc ...

# Forma de chamada das funcoes.
# Call shape of functions. 

# main => cfn1(Local_cfn1 ... Local_cfnx) => cfn2(...) => cfnx 
# ------------------------------------------------------------

# by Roberto Gomes Borges (RGB) E-Mail .: robertolinux (at) gmail.com
##############################################################################

# Tested in ...openSUSE 13.1(x86_64), CentOS 6.6 (x86,x86_64) CentOS 7.0 (x86_64)
# Debian 7(x86,x86_64), Debian 7(kFreeBSD),Ubuntu 14.04 SRV/DESKTOP LTS(x86,x86_64), SlackWare 14.1(x86)

# Ainda Falta testar no Windows/DOS/FreeBSD/NetBSD/OpenBSD/Solaris/QNX/AIX/HP-UX/Minix/Tru64/Plan9/SCO.
# etc,etc,etc. rsrsrsrsrs....

# Still Lack test in Windows / DOS / FreeBSD / NetBSD / OpenBSD / Solaris / QNX / AIX / HP-UX / Minix / Tru64 / Plan 9 / SCO.
# etc, etc, etc. lol ....
# -----------------------------------------------------------------------------------------------------

# help (pt_BR and US)
# -------------------

# Como proceder ...
# What to do ...

# $ pwd
# /home/bob
# $ mkdir -p mkc/src
# $ cp /home/bob/Downloads/mk_c_src.sh mkc/
# $ chmod +x mkc/mk_c_src.sh
# $ cd mkc/src
# $ time ../mk_c_src.sh
# $ time make -j <number of cores>
# $ time ./test

###########################
## VARIAVEIS DE AMBIENTE ##
## VARIABLE ENVIRONMENT  ##
###########################

#####################################################
# Funcao para incluir no path os diretorios basicos # 
# Function to include in the path directories basic #
#####################################################

pathmunge () {
  if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
     PATH=$1:$PATH
  fi
}
#
pathmunge /bin
pathmunge /sbin
pathmunge /usr/bin
pathmunge /usr/local/bin
#

#
# (OS COMMANDS)
#
echo "Wait/Aguarde ... Creating (main.c)"
#
CAT=`which cat`
CUT=`which cut`
CP=`which cp`
DT=`which date`
ECHO=`which echo`
EGREP=`which egrep`
GREP=`which grep`
MKDIR=`which mkdir`
MV=`which mv`
PERL=`which perl`
RMDIR=`which rmdir`
RM=`which rm`
SORT=`which sort`
TAR=`which tar`
TOUCH=`which touch`

####################################################################

MAIN="main.c"
 
PROJECT="test"     # BINARY
COMPILER="gcc"
LINK_FLAGS="-lm" 
COMPILE_FLAGS="-O3 -Werror"
OBJECTS=""       

#####################################################################

# ATTENTION/ATENÇÃO AQUI/HERE ....

# Variavel (K) e variavel (M)
# Variable (K) and variable (M)
# -----------------------------

# Variavel (K) => Quantidade de Arquivos (.c) a criar.
# Variavel (M) => Qauntidade de Funcoes Estaticas ou não, contidas em cada arquivo (.c) criado.

# Variable (K) => File Number (.c) to create.
# Variable (M) => Functions of static or not, quantity contained in each file (.c) created.

#############
#############
#############

# MAX ...

K=$((8))  # Max. .c's files to create.

M=$((16)) # Max. Static or NOT, Functions create into .c's files.

STATIC_S_N="N" # FUNCOES STATIC ? (S/N) STATIC FUNCTION ? (Y/N)
###############################################################

##############################
#                            #
# Variables for STRESS ...   #
#                            #  
##############################

###############
#             #
# GLOBALS VAR #
#             #
###############

G_CHAR_VAR=$((32))
G_INT_VAR=$((32))
G_FLOAT_VAR=$((32))
G_DOUBLE_VAR=$((32))

##############
#            #
# LOCAL VARS #
#            #
##############

L_CHAR_VAR=$((16))
L_INT_VAR=$((16))
L_FLOAT_VAR=$((16))
L_DOUBLE_VAR=$((16))

#

###############
#             #
# STATICS VAR #
#             #
###############

S_CHAR_VAR=$((8))
S_INT_VAR=$((8))
S_FLOAT_VAR=$((8))
S_DOUBLE_VAR=$((8))

#

#############
#############
#############

DATE=$(date)                   # Today
  OS=$(uname -rpmia)           # Operating System

DTINI=`$DT +%Y-%m-%d-%H:%M:%S` # Date And Time Start

####################################################################

#
MKFILE="makefile"
#
echo "# MakeFile to  ANSI C Compiler Tests"        > $MKFILE
#
echo " "                                          >> $MKFILE
#
echo "# by Roberto Gomes Borges (RGB) 1982-2014"  >> $MKFILE
echo "# e-mail .: robertolinux (at) gmail.com"    >> $MKFILE
echo "# Fortaleza,Ce (BR) - $DATE"                >> $MKFILE
echo "# $OS"                                      >> $MKFILE
echo " "                                          >> $MKFILE
#
echo "PROJECT=$PROJECT"                           >> $MKFILE
echo "COMPILER=$COMPILER"                         >> $MKFILE
echo "LINK_FLAGS=$LINK_FLAGS"                     >> $MKFILE
echo "COMPILE_FLAGS=$COMPILE_FLAGS"               >> $MKFILE
#
echo " "                                          >> $MKFILE
#
echo 'OBJECTS=\'                                  >> $MKFILE
echo 'main.o \'                                   >> $MKFILE

# MAIN.C

echo "/*"                                                                                       > $MAIN
echo " "                                                                                       >> $MAIN
echo "**********************************************************"                              >> $MAIN
echo "*  Vrs. 0.0.0.01 pre-pre-pre-alpha. 14/11/2014           *"                              >> $MAIN 
echo "*  +--------------------------------------------------+  *"                              >> $MAIN
echo "*  |                                                  |  *"                              >> $MAIN
echo "*  | Script to make (.C) mk_c_src.sh      ???????.bat |  *"                              >> $MAIN
echo "*  | ------------------------------------------------ |  *"                              >> $MAIN 
echo "*  |                                                  |  *"                              >> $MAIN
echo "*  | Roberto Gomes Borges (RGB) 1982-2014.            |  *"                              >> $MAIN
echo "*  | ------------------------------------------------ |  *"                              >> $MAIN
echo "*  | LINUX/Windows/DOS DosBox/DosEmu/VirtualBox. etc. |  *"                              >> $MAIN
echo "*  +--------------------------------------------------+  *"                              >> $MAIN  
echo "*    e-mail .: robertolinux (at) gmail.com               *"                              >> $MAIN 
echo "**********************************************************"                              >> $MAIN
echo " "                                                                                       >> $MAIN
echo "*/"                                                                                      >> $MAIN
#
echo " "                                                                                       >> $MAIN
echo '#include <stdlib.h>'                                                                     >> $MAIN
echo '#include <stdio.h>'                                                                      >> $MAIN
echo '#include <string.h>'                                                                     >> $MAIN
echo '#include <math.h>'                                                                       >> $MAIN
echo '#include <ctype.h>'                                                                      >> $MAIN
echo '#include <limits.h>'                                                                     >> $MAIN
echo '#include <float.h>'                                                                      >> $MAIN
echo '#include <stdint.h>'                                                                     >> $MAIN
echo '#include <time.h>'                                                                       >> $MAIN
echo '//#include <quadmath.h>'                                                                 >> $MAIN
#
echo " "                                                                                       >> $MAIN
echo "/*"                                                                                      >> $MAIN
echo " "                                                                                       >> $MAIN
echo "by Roberto Gomes Borges (RGB) 1982-2014"                                                 >> $MAIN
echo "e-mail .: robertolinux (at) gmail.com"                                                   >> $MAIN
echo "Fortaleza,Ce (BR) - $DATE"                                                               >> $MAIN
echo $OS                                                                                       >> $MAIN
echo " "                                                                                       >> $MAIN
echo "*/"                                                                                      >> $MAIN
echo " "                                                                                       >> $MAIN
#
echo "//"                                                                                      >> $MAIN
# 
for ((g=1 ; g<=$G_CHAR_VAR ; g++)); do
    echo 'char G_CHAR_VAR_'$g'[]="Bla, Ble, Bli, Blo, Blu 0,1,2,3,4,5,6,7,8,9"; // GLOBAL VAR' >> $MAIN
done
#
echo "//"                                                                                      >> $MAIN
#
for ((g=1 ; g<=$G_INT_VAR ; g++)); do
    echo 'int G_INT_VAR_'$g'='$g'; // GLOBAL VAR'                                              >> $MAIN
#   echo 'int G_INT_VAR_'$g'=0; // GLOBAL VAR'                                                 >> $MAIN
done
#
echo "//"                                                                                      >> $MAIN
#
for ((g=1 ; g<=$G_FLOAT_VAR ; g++)); do
#   echo 'float G_FLOAT_VAR_'$g'='$g.0'; // GLOBAL VAR'                                        >> $MAIN
    echo 'float G_FLOAT_VAR_'$g'=0.0; // GLOBAL VAR'                                           >> $MAIN
done
#
echo "//"                                                                                      >> $MAIN
#
for ((g=1 ; g<=$G_DOUBLE_VAR ; g++)); do
#   echo 'double G_DOUBLE_VAR_'$g'='$g.0'; // GLOBAL VAR'                                      >> $MAIN
    echo 'double G_DOUBLE_VAR_'$g'=0.0; // GLOBAL VAR'                                         >> $MAIN
done
#
echo "//"                                                                                      >> $MAIN
#
echo "unsigned long long int li_contador=0;      // Variavel GLOBAL"                           >> $MAIN
echo "unsigned long long int gulli_contador=0;   // Variavel GLOBAL"                           >> $MAIN
echo "unsigned long long int uit64=0;            // Variavel GLOBAL"                           >> $MAIN
#
#echo "extern unsigned long long int sulli_contador;" // Var STATIC                            >> $MAIN
#
echo "//"                                                                                      >> $MAIN
echo "void rgb_inc_contador(void);               // Incrementa a variavel global contador"     >> $MAIN 
echo "void rgbVoidRet(void);                     // Prototipo (RETORNA NADA)"                  >> $MAIN
echo "int  rgbIntRet0(void);                     // Prototipo (RETORNA 0 (Zero))"              >> $MAIN
echo "int  rgbIntRet1(void);                     // Prototipo (RETORNA 1 (Hum))"               >> $MAIN
echo "//"                                                                                      >> $MAIN
#
echo " "                                                                                       >> $MAIN
#
echo "int main(int argc, char *argv[]) {"                                                      >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    unsigned       int  num=0x80000000; // Para testar depois..."                        >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    char                  c=-128; // Faixa de -128,0,127"                                >> $MAIN
echo "    unsigned char        uc=0;    // Faixa de 0 ate 255"                                 >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    int                   i=0; // Default SIGNED Faixa de -2.147.483.648, 0, ate 2.147.483.647 ( ( (2^32) / 2 ) - 1 ) Espeificador %i ou %d" >> $MAIN
echo "    unsigned       int   ui=0; // Faixa de 0 ate 4.294.967.295 Especificador de formato %u"                                    >> $MAIN
echo "    signed         int   si=0; // Faixa de -2.147.483.648, 0, ate 2.147.483.647 Especificador de formato %i ou %d "            >> $MAIN
echo "    short          int  shi=0; // Faixa de -32.768, 0, ate 32.767 Especificador de formato %i ou %d "                          >> $MAIN
echo " "                                                                                                                             >> $MAIN
echo "    long           int   li=0; // Faixa de 0 ate 9223372036854775807 ou .."                                                    >> $MAIN
echo "                               // long long signed integer type. At least in the [−9223372036854775807,+9223372036854775807] " >> $MAIN
echo "                               // range, thus at least 64 bits in size. Specified since the C99 version of the standard. "     >> $MAIN
echo "    unsigned short int ushi=0;"                                                          >> $MAIN
echo "    signed short   int sshi=0;"                                                          >> $MAIN
echo "    unsigned long  int  uli=0;"                                                          >> $MAIN
echo "    signed   long  int  sli=0;"                                                          >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    long       int  uiloops=0; // Contagem de loops nos lacos ..."                       >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    unsigned long long int umax=0;"                                                      >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    long double        ld=0.0;"                                                          >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo " "                                                                                       >> $MAIN
echo "    /*"                                                                                  >> $MAIN
echo " "                                                                                       >> $MAIN
echo "    uint8_t            uit8=0;"                                                          >> $MAIN
echo "    uint16_t          uit16=0;"                                                          >> $MAIN
echo "    uint32_t          uit32=0;"                                                          >> $MAIN
echo "    uint64_t          uit64=0;"                                                          >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    int8_t              it8=0;"                                                          >> $MAIN
echo "    int16_t            it16=0;"                                                          >> $MAIN
echo "    int32_t            it32=0;"                                                          >> $MAIN
echo "    int64_t            it64=0;"                                                          >> $MAIN
echo " "                                                                                       >> $MAIN
echo "    */"                                                                                  >> $MAIN
echo " "                                                                                       >> $MAIN 
#
for ((g=1 ; g<=$L_CHAR_VAR ; g++)); do
    echo '    char L_CHAR_VAR_'$g'[]="Bla, Ble, Bli, Blo, Blu 0,1,2,3,4,5,6,7,8,9";'           >> $MAIN
done
#
echo "    //"                                                                                  >> $MAIN
#
for ((g=1 ; g<=$L_INT_VAR ; g++)); do
    echo '    int L_INT_VAR_'$g'='$g';'                                                        >> $MAIN
#   echo '    int L_INT_VAR_'$g'=0;'                                                           >> $MAIN
done
#
echo "    //"                                                                                  >> $MAIN
#
for ((g=1 ; g<=$L_FLOAT_VAR ; g++)); do
#   echo '    float L_FLOAT_VAR_'$g'='$g.0';'                                                  >> $MAIN
    echo '    float L_FLOAT_VAR_'$g'=0.0;'                                                     >> $MAIN
done
#
echo "    //"                                                                                  >> $MAIN
#
for ((g=1 ; g<=$L_DOUBLE_VAR ; g++)); do
#   echo '    double L_DOUBLE_VAR_'$g'='$g.0';'                                                >> $MAIN
    echo '    double L_DOUBLE_VAR_'$g'=0.0;'                                                   >> $MAIN
done
#
echo "    //"                                                                                  >> $MAIN
#
#echo " "                                                                                      >> $MAIN 
echo "    time_t  start,end;"                                                                  >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    start  = time(NULL);"                                                                >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo '    cfn1(__func__);'                                                                     >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "    end     = time(NULL);"                                                               >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo '    printf("\n");'                                                                       >> $MAIN
echo '    printf("Total de Loops for, while, do, (uit64) ..: %llu\n"  ,uit64); // Loops'              >> $MAIN
echo '    printf("Valor da variavel GLOBAL (li_contador) ..: %llu\n"  ,li_contador); // Loops'        >> $MAIN
echo '    printf("Get value from STATIC var sulli_contador.: %llu\n"  ,gulli_contador); // Loops'     >> $MAIN
echo '    printf("Tempo decorrido / Elapsed time...........: %f segundos.\n", difftime(end, start));' >> $MAIN
echo '    printf("\nUse readelf, size, objdump, etc to Analysis binary file.\n\n");'           >> $MAIN
echo "    //"                                                                                  >> $MAIN
echo "return(0);"                                                                              >> $MAIN
echo "//"                                                                                      >> $MAIN
echo "}"                                                                                       >> $MAIN
echo "////////////////////////////////////////////"                                            >> $MAIN
echo "void rgb_inc_contador(void)"                                                             >> $MAIN
echo "{"                                                                                       >> $MAIN
echo " // Incrementa a variavel GLOBAL em UM"                                                  >> $MAIN
echo " li_contador++;"                                                                         >> $MAIN
echo " // "                                                                                    >> $MAIN 
echo " return;"                                                                                >> $MAIN
echo " //"                                                                                     >> $MAIN
echo "}"                                                                                       >> $MAIN
echo "////////////////////////////////////////////"                                            >> $MAIN
echo "void rgbVoidRet(void)"                                                                   >> $MAIN
echo "{"                                                                                       >> $MAIN
echo " // Nao faz nada de util, chama 2 funcoes de retorno 0 e 1, ...apenas retorna null."     >> $MAIN
echo " // Atribui o valor da STATIC VAR sulli_contador to GLOBAL VAR gulli_contador"           >> $MAIN
echo " int izero = 2147483647;"                                                                >> $MAIN
echo " int ihum  = 2147483647;"                                                                >> $MAIN
echo " // "                                                                                    >> $MAIN
echo " static unsigned long long int sulli_contador=0;"                                        >> $MAIN
echo " // "                                                                                    >> $MAIN
echo " izero = rgbIntRet0();"                                                                  >> $MAIN
echo " ihum  = rgbIntRet1();"                                                                  >> $MAIN
echo " // "                                                                                    >> $MAIN
echo " sulli_contador++;"                                                                      >> $MAIN
echo " gulli_contador = sulli_contador;"                                                       >> $MAIN
echo " // "                                                                                    >> $MAIN
echo " return;"                                                                                >> $MAIN
echo "}"                                                                                       >> $MAIN
echo "////////////////////////////////////////////"                                            >> $MAIN	
echo "int rgbIntRet0(void)"                                                                    >> $MAIN
echo "{"                                                                                       >> $MAIN
echo " // Retorna 0 (ZERO)"                                                                    >> $MAIN
echo " int izeroret = 0;"                                                                      >> $MAIN
echo " //"                                                                                     >> $MAIN
echo " return(izeroret);"                                                                      >> $MAIN
echo " //"                                                                                     >> $MAIN
echo "}"                                                                                       >> $MAIN 
echo "////////////////////////////////////////////"                                            >> $MAIN
echo "int rgbIntRet1(void)"                                                                    >> $MAIN
echo "{"                                                                                       >> $MAIN
echo " // Retorna 1 (Hum)"                                                                     >> $MAIN
echo " int ihumret = 1;"                                                                       >> $MAIN
echo " // "                                                                                    >> $MAIN
echo " return(ihumret);"                                                                       >> $MAIN
echo " //"                                                                                     >> $MAIN
echo "}"                                                                                       >> $MAIN
echo "////////////////////////////////////////////"                                            >> $MAIN
echo "//EOF"                                                                                   >> $MAIN
echo " "                                                                                       >> $MAIN
#
echo "Wait/Aguarde ..."
#
for ((i=1; i <= $K ; i++)) ; do
    #
    J=$((i+1))
    # 
    echo "/*"                                                           > cfn$i.c
    echo "  "                                                          >> cfn$i.c
    echo "**********************************************************"  >> cfn$i.c
    echo "*  Vrs. 0.0.0.01 pre-pre-pre-alpha. 14/11/2014           *"  >> cfn$i.c 
    echo "*  +--------------------------------------------------+  *"  >> cfn$i.c
    echo "*  |                                                  |  *"  >> cfn$i.c
    echo "*  | Script to make (.C) mk_c_src.sh     ????????.bat |  *"  >> cfn$i.c
    echo "*  | ------------------------------------------------ |  *"  >> cfn$i.c 
    echo "*  |                                                  |  *"  >> cfn$i.c
    echo "*  | Roberto Gomes Borges (RGB) 1982-2014.            |  *"  >> cfn$i.c
    echo "*  | ------------------------------------------------ |  *"  >> cfn$i.c
    echo "*  | LINUX/Windows/DOS DosBox/DosEmu/VirtualBox. etc. |  *"  >> cfn$i.c
    echo "*  +--------------------------------------------------+  *"  >> cfn$i.c  
    echo "*    e-mail .: robertolinux (at) gmail.com               *"  >> cfn$i.c 
    echo "**********************************************************"  >> cfn$i.c
    echo " "                                                           >> cfn$i.c
    echo "*/"                                                          >> cfn$i.c 
    #
    echo "Criando Arquivo ... " cfn$i.c
    #
    echo " "                                                       >> cfn$i.c
    #
    echo '#include <stdlib.h>'                                     >> cfn$i.c
    echo '#include <stdio.h>'                                      >> cfn$i.c
    echo '#include <string.h>'                                     >> cfn$i.c
    echo '#include <math.h>'                                       >> cfn$i.c
    echo '#include <ctype.h>'                                      >> cfn$i.c
    echo '#include <limits.h>'                                     >> cfn$i.c
    echo '#include <float.h>'                                      >> cfn$i.c
    echo '#include <stdint.h>'                                     >> cfn$i.c
    echo '#include <time.h>'                                       >> cfn$i.c
    echo '//#include <quadmath.h>'                                 >> cfn$i.c
    # 
    echo " "                                                       >> cfn$i.c
    echo "/*"                                                      >> cfn$i.c
    echo " "                                                       >> cfn$i.c
    echo "by Roberto Borges (RGB) 1982-2014"                       >> cfn$i.c
    echo "e-mail .: robertolinux (at) gmail.com"                   >> cfn$i.c
    echo "Fortaleza,Ce (BR) - $DATE"                               >> cfn$i.c
    echo $OS                                                       >> cfn$i.c
    echo " "                                                       >> cfn$i.c
    echo "*/"                                                      >> cfn$i.c
    echo " "                                                       >> cfn$i.c
    #
    echo "//"                                                      >> cfn$i.c
    # 
    for ((g=1 ; g<=$G_CHAR_VAR ; g++)); do
        echo 'char G_CHAR_VAR_'cfn$i'_'$g'[]="Bla, Ble, Bli, Blo, Blu 0,1,2,3,4,5,6,7,8,9"; // GLOBAL VAR' >> cfn$i.c
    done
    #
    echo "//"                                                      >> cfn$i.c
    #
    for ((g=1 ; g<=$G_INT_VAR ; g++)); do
        echo 'int G_INT_VAR_'cfn$i'_'$g'='$g'; // GLOBAL VAR'      >> cfn$i.c
    #   echo 'int G_INT_VAR_'cfn$i'_'$g'=0; // GLOBAL VAR'         >> cfn$i.c
    done
    #
    echo "//"                                                      >> cfn$i.c
    #
    for ((g=1 ; g<=$G_FLOAT_VAR ; g++)); do
    #   echo 'float G_FLOAT_VAR_'cfn$i'_'$g'='$g.0'; //GLOBAL VAR' >> cfn$i.c
        echo 'float G_FLOAT_VAR_'cfn$i'_'$g'=0.0; // GLOBAL VAR'   >> cfn$i.c
    done
    #
    echo "//"                                                      >> cfn$i.c
    #
    for ((g=1 ; g<=$G_DOUBLE_VAR ; g++)); do
    #   echo 'double G_DOUBLE_VAR_'cfn$i'_'$g'='$g.0';//GLOBAL VAR' >> cfn$i.c
        echo 'double G_DOUBLE_VAR_'cfn$i'_'$g'=0.0; // GLOBAL VAR' >> cfn$i.c
    done
    #
    echo "//"                                                      >> cfn$i.c
    # 
    for ((x=1 ; x<= $M ; x++)) ; do
        #
        if [ $STATIC_S_N == "S" ] || [ $STATIC_S_N == "Y" ]   ; then
           echo "static void" Local_cfn$x"(const char* strRec);  // Prototype" >> cfn$i.c
        else
           echo "void" Local_"cfn$i"_cfn$x"(const char* strRec); // Prototype" >> cfn$i.c
        fi
        #
    done
    #
    echo " "                                                       >> cfn$i.c
    #
    echo "static const char* rgbQuemSouEu(); // Prototype"         >> cfn$i.c
    #
    echo " "                                                       >> cfn$i.c
    #    
    for ((g=1 ; g<=$G_CHAR_VAR ; g++)); do
        echo 'extern char G_CHAR_VAR_'$g'[]; // GLOBAL VAR'        >> cfn$i.c
    done
    #
    echo "//"                                                      >> cfn$i.c
    #
    for ((g=1 ; g<=$G_INT_VAR ; g++)); do
        echo 'extern int G_INT_VAR_'$g'; // GLOBAL VAR'            >> cfn$i.c
    done
    #
    echo "//"                                                      >> cfn$i.c
    #
    for ((g=1 ; g<=$G_FLOAT_VAR ; g++)); do
        echo 'extern float G_FLOAT_VAR_'$g'; // GLOBAL VAR'        >> cfn$i.c
    done
    #
    echo "//"                                                      >> cfn$i.c
    #
    for ((g=1 ; g<=$G_DOUBLE_VAR ; g++)); do
        echo 'extern double G_DOUBLE_VAR_'$g'; // GLOBAL VAR'      >> cfn$i.c
    done
    #
    echo "//"                                                      >> cfn$i.c
    #
    echo "extern unsigned long long int uit64;"                    >> cfn$i.c
    echo " "                                                       >> cfn$i.c
    echo "int "cfn$i"(char* strRecebida) {"                        >> cfn$i.c
    echo "    //"                                                  >> cfn$i.c
    for ((g=1 ; g<=$L_CHAR_VAR ; g++)); do
        echo '    char L_CHAR_VAR_'$g'[]="Bla, Ble, Bli, Blo, Blu 0,1,2,3,4,5,6,7,8,9";' >> cfn$i.c
    done
    #
    echo "    //"                                                  >> cfn$i.c
    #
    for ((g=1 ; g<=$L_INT_VAR ; g++)); do
        echo '    int L_INT_VAR_'$g'='$g';'                        >> cfn$i.c
    #   echo '    int L_INT_VAR_'$g'=0;'                           >> cfn$i.c
    done
    #
    echo "    //"                                                  >> cfn$i.c
    #
    for ((g=1 ; g<=$L_FLOAT_VAR ; g++)); do
    #   echo '    float L_FLOAT_VAR_'$g'='$g.0';'                  >> cfn$i.c
        echo '    float L_FLOAT_VAR_'$g'=0.0;'                     >> cfn$i.c
    done
    #
    echo "    //"                                                  >> cfn$i.c
    #
    for ((g=1 ; g<=$L_DOUBLE_VAR ; g++)); do
    #   echo '    double L_DOUBLE_VAR_'$g'='$g.0';'                >> cfn$i.c
        echo '    double L_DOUBLE_VAR_'$g'=0.0;'                   >> cfn$i.c
    done
    #
    echo "    //"                                                  >> cfn$i.c
    echo "    time_t current_time;"                                >> cfn$i.c
    echo "    char* c_time_string;"                                >> cfn$i.c
    echo "    //"                                                  >> cfn$i.c
    echo "    current_time  = time(NULL);"                         >> cfn$i.c
    echo "    c_time_string = ctime(&current_time);"               >> cfn$i.c 
    echo "    //"                                                  >> cfn$i.c
    echo '    printf("Em Data/Hora (Date/Time) ...............: %s\n",c_time_string);'                        >> cfn$i.c
    echo '    printf("Quem me Chamou / Who called me .........: %s\n",strRecebida);'                          >> cfn$i.c
    echo '    printf("Quem Eu sou / Who I am (Function/File) .: \"%s\"/\"%s\"\n\n",rgbQuemSouEu(),__FILE__);' >> cfn$i.c
#   echo '    printf("Quem Eu sou ......: %s %s ",__func__,__FILE__);'                           >> cfn$i.c
#   echo '    printf("\n");'                                                                     >> cfn$i.c
    #
    echo "    //"                                                  >> cfn$i.c
    #
    # M = Total de Funcoes Estaricas dentro dos OBJ'S 
    #    
    for ((l=1; l <= $M ; l++)) ; do
        #
        N=$((l+1))
        #
        if [ $l -eq 1 ]
        then
#          echo "    "Local_cfn$l"(rgbQuemSouEu());"               >> cfn$i.c
           #
           if [ $STATIC_S_N == "S" ] || [ $STATIC_S_N == "Y" ] ; then
              echo "    "Local_cfn$l"(__func__);"                  >> cfn$i.c
           else
              echo "    "Local_"cfn$i"_cfn$l"(__func__);"          >> cfn$i.c
           fi
           # 
           echo "    //"                                           >> cfn$i.c
           echo "return(0);"                                       >> cfn$i.c
           echo "//"                                               >> cfn$i.c
           echo "}"                                                >> cfn$i.c
        fi
        echo " "                                                   >> cfn$i.c
        #
        if [ $STATIC_S_N == "S" ] || [ $STATIC_S_N == "Y" ] ; then
           echo "   Criando Funcao Static ... " Local_cfn$l
        else
           echo "   Criando Funcao NOT Static ... " Local_"cfn$i"_cfn$l
        fi
        #
#       echo "static const char*" Local_cfn$l"(const char* strRec) {"     >> cfn$i.c
        #
        if [ $STATIC_S_N == "S" ] || [ $STATIC_S_N == "Y" ] ; then
           echo "static void" Local_cfn$l"(const char* strRec) {"     >> cfn$i.c
        else
           echo "void" Local_"cfn$i"_cfn$l"(const char* strRec) {"    >> cfn$i.c
        fi
        #
        echo "//"                                                  >> cfn$i.c
        echo "//char   c;"                                         >> cfn$i.c                    
        echo "//int    i;"                                         >> cfn$i.c
        echo "//float  f;"                                         >> cfn$i.c
        echo "//double d;"                                         >> cfn$i.c
        echo "//"                                                  >> cfn$i.c
        #
        echo "unsigned       int  num=0x80000000; // Para testar depois..."                        >> cfn$i.c
        echo "//"                                                                                  >> cfn$i.c
        echo "char                  c=-128; // Faixa de -128,0,127"                                >> cfn$i.c
        echo "unsigned char        uc=0;    // Faixa de 0 ate 255"                                 >> cfn$i.c
        echo "//"                                                                                  >> cfn$i.c
        echo "int                   i=0; // Default SIGNED Faixa de -2.147.483.648, 0, ate 2.147.483.647 ( ( (2^32) / 2 ) - 1 ) Espeificador %i ou %d" >> cfn$i.c
        echo "unsigned       int   ui=0; // Faixa de 0 ate 4.294.967.295 Especificador de formato %u"                                    >> cfn$i.c
        echo "signed         int   si=0; // Faixa de -2.147.483.648, 0, ate 2.147.483.647 Especificador de formato %i ou %d "            >> cfn$i.c
        echo "short          int  shi=0; // Faixa de -32.768, 0, ate 32.767 Especificador de formato %i ou %d "                          >> cfn$i.c
        echo " "                                                                                                                         >> cfn$i.c
        echo "long           int   li=0; // Faixa de 0 ate 9223372036854775807 ou .."                                                    >> cfn$i.c
        echo "                           // long long signed integer type. At least in the [−9223372036854775807,+9223372036854775807] " >> cfn$i.c
        echo "                           // range, thus at least 64 bits in size. Specified since the C99 version of the standard. "     >> cfn$i.c
        echo "unsigned short int ushi=0;"                                                          >> cfn$i.c
        echo "signed short   int sshi=0;"                                                          >> cfn$i.c
        echo "unsigned long  int  uli=0;"                                                          >> cfn$i.c
        echo "signed   long  int  sli=0;"                                                          >> cfn$i.c
        echo "//"                                                                                  >> cfn$i.c
        echo "long       int  uiloops=0; // Contagem de loops nos lacos ..."                       >> cfn$i.c
        echo "//"                                                                                  >> cfn$i.c
        echo "unsigned long long int umax=0;"                                                      >> cfn$i.c
        echo "//"                                                                                  >> cfn$i.c
        echo "long double        ld=0.0;"                                                          >> cfn$i.c
        echo "//"                                                                                  >> cfn$i.c
        echo " "                                                                                   >> cfn$i.c
        echo "/*"                                                                                  >> cfn$i.c
        echo " "                                                                                   >> cfn$i.c
        echo "uint8_t            uit8=0;"                                                          >> cfn$i.c
        echo "uint16_t          uit16=0;"                                                          >> cfn$i.c
        echo "uint32_t          uit32=0;"                                                          >> cfn$i.c
        echo "uint64_t          uit64=0;"                                                          >> cfn$i.c
        echo "//"                                                                                  >> cfn$i.c
        echo "int8_t              it8=0;"                                                          >> cfn$i.c
        echo "int16_t            it16=0;"                                                          >> cfn$i.c
        echo "int32_t            it32=0;"                                                          >> cfn$i.c
        echo "int64_t            it64=0;"                                                          >> cfn$i.c
        echo " "                                                                                   >> cfn$i.c
        echo "*/"                                                                                  >> cfn$i.c
        echo " "                                                                                   >> cfn$i.c 
        echo "//"                                                                                  >> cfn$i.c 
        #
        for ((g=1 ; g<=$L_CHAR_VAR ; g++)); do
            echo 'char L_CHAR_VAR_'$g'[]="Bla, Ble, Bli, Blo, Blu 0,1,2,3,4,5,6,7,8,9";' >> cfn$i.c
        done
        #
        echo "//"                                                      >> cfn$i.c
        #
        for ((g=1 ; g<=$L_INT_VAR ; g++)); do
            echo 'int L_INT_VAR_'$g'='$g';'                            >> cfn$i.c
        #   echo 'int L_INT_VAR_'$g'=0;'                               >> cfn$i.c
        done
        #
        echo "//"                                                      >> cfn$i.c
        #
        for ((g=1 ; g<=$L_FLOAT_VAR ; g++)); do
        #   echo 'float L_FLOAT_VAR_'$g'='$g.0';'                      >> cfn$i.c
            echo 'float L_FLOAT_VAR_'$g'=0.0;'                         >> cfn$i.c
        done
        #
        echo "//"                                                      >> cfn$i.c
        #
        for ((g=1 ; g<=$L_DOUBLE_VAR ; g++)); do
        #   echo 'double L_DOUBLE_VAR_'$g'='$g.0';'                    >> cfn$i.c
            echo 'double L_DOUBLE_VAR_'$g'=0.0;'                       >> cfn$i.c
        done
        #
        echo "//"                                                      >> cfn$i.c
        # Aqui ...	
        for ((g=1 ; g<=$S_CHAR_VAR ; g++)); do
            echo 'static char S_CHAR_VAR_'$g'[]="Bla, Ble, Bli, Blo, Blu 0,1,2,3,4,5,6,7,8,9";' >> cfn$i.c
        done
        #
        echo "//"                                                      >> cfn$i.c
        #
        for ((g=1 ; g<=$S_INT_VAR ; g++)); do
            echo 'static int S_INT_VAR_'$g'='$g';'                            >> cfn$i.c
        #   echo 'static int S_INT_VAR_'$g'=0;'                               >> cfn$i.c
        done
        #
        echo "//"                                                      >> cfn$i.c
        #
        for ((g=1 ; g<=$S_FLOAT_VAR ; g++)); do
        #   echo 'static float S_FLOAT_VAR_'$g'='$g.0';'                      >> cfn$i.c
            echo 'static float S_FLOAT_VAR_'$g'=0.0;'                         >> cfn$i.c
        done
        #
        echo "//"                                                      >> cfn$i.c
        #
        for ((g=1 ; g<=$S_DOUBLE_VAR ; g++)); do
        #   echo 'static double S_DOUBLE_VAR_'$g'='$g.0';'                    >> cfn$i.c
            echo 'static double S_DOUBLE_VAR_'$g'=0.0;'                       >> cfn$i.c
        done
        #
        echo "//"                                                      >> cfn$i.c
        #
#       echo "for (ui=0 ; ui< 4294967295 ; ui++)"                      >> cfn$i.c
        echo "for (ui=0 ; ui< 1024 ; ui++)"                            >> cfn$i.c
        echo "{"                                                       >> cfn$i.c
        echo " "                                                       >> cfn$i.c
        echo " rgbVoidRet();"                                          >> cfn$i.c
        echo " uiloops = uiloops + rgbIntRet1();"                      >> cfn$i.c
        echo " uit64   = uit64   + rgbIntRet1();"                      >> cfn$i.c
        echo " rgb_inc_contador();"                                    >> cfn$i.c
        echo " "                                                       >> cfn$i.c
        echo "}"                                                       >> cfn$i.c
        echo "//"                                                      >> cfn$i.c 
        #
        if ! [ $N -gt $M ] # Se nao for a ultima funcao do loop.
        then     
#          echo Local_cfn$N"(rgbQuemSouEu());"                           >> cfn$i.c
        if [ $STATIC_S_N == "S" ] || [ $STATIC_S_N == "Y" ] ; then
           echo Local_cfn$N"(__func__);"                                 >> cfn$i.c
        else
           echo Local_"cfn$i"_cfn$N"(__func__);"                         >> cfn$i.c
        fi
        #
        else
           #
           echo "//"                                                     >> cfn$i.c
           echo "// Chama a Proxima Funcao, em caso de nao ser a ultima" >> cfn$i.c
           echo "//"                                                     >> cfn$i.c
           #
           if ! [ $J -gt $K ] # Se nao for a ultima funcao do loop.
           then 
              echo cfn$J"(rgbQuemSouEu());"                              >> cfn$i.c
           else
              echo "// NOP NOP NOP NOP !!! Ultima Funcao do Loop"        >> cfn$i.c
           fi
           #
           echo "//"                                                     >> cfn$i.c
        #
        fi
        #
        echo "//"                                                        >> cfn$i.c
        echo "return;"                                                   >> cfn$i.c  
        echo "//"                                                        >> cfn$i.c
        echo "}"                                                         >> cfn$i.c
        #
    done
    #
    echo "//"                                          >> cfn$i.c
    #
    echo "static const  char* rgbQuemSouEu(void) {"    >> cfn$i.c
    echo '       static char array[] = "'cfn$i"()"'";' >> cfn$i.c
    echo '       return (array);'                      >> cfn$i.c
#   echo '       return ("'cfn$i"()"'");'              >> cfn$i.c
    echo "}"                                           >> cfn$i.c
    echo " "                                           >> cfn$i.c
    echo "// EOF"                                      >> cfn$i.c
    #
    if ! [ $J -gt $K ]
    then 
       echo "cfn""${i%%.*}"".o \\" >> $MKFILE
    else
       echo "cfn""${i%%.*}"".o"    >> $MKFILE
    fi
    #
done
#
echo " "                            >> $MKFILE
#
DTFIN=`date +%Y-%m-%d-%H:%M:%S`
#
echo " "
echo "Script Start ...:" $DTINI 
echo "Script End .....:" $DTFIN 
echo " "
#
echo "Now type ... (Digite a sequencia de comandos abaixo)"
echo " "
echo 'time make -j<number of cpu cores>'
echo "time strip test"
echo "time upx -9v test"
echo "time ./test"
echo " "
#
echo "Use readelf, size, objdump, etc to Analysis binary file."
#
echo 'all: $(PROJECT)'                                              >> $MKFILE
echo " "                                                            >> $MKFILE
echo "debug: COMPILE_FLAGS += -g"                                   >> $MKFILE
echo 'debug: $(PROJECT)'                                            >> $MKFILE
echo " "                                                            >> $MKFILE
echo "%.o: %.c"                                                     >> $MKFILE
echo '		$(COMPILER) $(COMPILE_FLAGS) -c $<'                 >> $MKFILE
echo " "                                                            >> $MKFILE
echo '$(PROJECT): $(OBJECTS)'                                       >> $MKFILE
echo '		$(COMPILER) $(OBJECTS) $(LINK_FLAGS) -o $(PROJECT)' >> $MKFILE
echo " "                                                            >> $MKFILE
echo "clean:"                                                       >> $MKFILE
echo '		rm $(PROJECT) *.o'                                  >> $MKFILE
echo " "                                                            >> $MKFILE
#

# Use readelf, size, objdump, etc to Analysis binary file
# -------------------------------------------------------

# Program sections
#
#  reflect different logical parts of program
#
#    text  - program code
#    data  - initialized variables
#    bss (block started by symbol) - uninitialized variables
#    stack - automatically allocated variables (local variables) and other stack frame entries
#    heap  - dynamically allocated variables
#
# Low Address          | . . . |
#                      +-------+ -.                       int x = 1;      /* x placed in data */
#                      | text  |   \                      int y;          /* y in placed bss  */
#                      |-------|    | program's           int main(){
#                      | data  |    | layout in               int z;      /* z alloc. on stack */
#                      |-------|    | memory                  ...
#                      | bss   |    |                         y = 2;      /* code put in text  */
#                      |-------|    |                         ...
#                      | heap  |    |                         return 0;   /* retval in reg %o0 */
#                      |---|---|    |                     }
#                      | . V . |    |
#                      | . . . |    |                     a dynamically allocated variable will
#                      | . ^ . |    |                       placed in the heap
#                      |---|---|    |
#                      | stack |   /                      a local variable declared with the
#                      +-------+ -'                         keyword "static" in C will be placed
# High Address         | . . . |                            in data if initialized, else in bss

#
# Enjoy ...
# Have a lot of fun...
# EOF

