#!/bin/sh
SCRIPT=$1

# Step 1-2. R-W
chmod 777 -R ./DAILEO;
chmod 777 -R ./THEALE;

case "$SCRIPT" in
     A5-HARDFLOAT | a5-hardfloat | A5-HardFloat)
         # Step 2-1. tool-chain
         # N/A
         # Step 2-1. make SN
         cd DAILEO/Supernova/projects;
         source buildsettings/build_A5_129E_IPC.sh;
         make rebuild_all;
         make image_all;
         # Step 3-1. tool-chain
         # N/A
         # Step 3-2. make DFB
         cd ../../../THEALE/RedLion/Lunar/directfb/1.4.2;
         ./AutoRelease/configure_muf_modify.sh a5-hardfloat;
export THEALE_PATH=$(pwd)/../../../..;
echo $THEALE_PATH;
         source ./mstconfigure_muf.sh;
         ./AutoRelease/libtool_modify.sh;
         make all;
         rm -rf $OUTPUT_DIR/*;
         make install;
         ./mstconfigure_muf.sh package ./;
         # Step 4-1. tool-chain
         # N/A
         # Step 4-2. make SN
         cp ./directfb-1.4.2m.tar.gz ../../../../../DAILEO/Supernova/develop/extra/target/mips-glibc/hardfloat;
         cd ../../../../../DAILEO/Supernova/projects;
         source buildsettings/build_A5_129E_IPC.sh;
         sed -i 's/FPU_ENABLE \= 1/FPU_ENABLE \= 1/g' ./board/a5/pcb.mk;
         sed -i 's/SKYPE_ENABLE = 1/SKYPE_ENABLE = 0/g' ./sw_cfg/europe_dtv/config.mk;
         sed -i 's/@grep -B3/#@grep -B3/g' ../target/Makefile;
         make rebuild_all;
         make image_all;
         ;;
     A5-SOFTFLOAT | a5-softfloat | A5-SoftFloat)
         # Step 2-1. tool-chain
         # N/A
         # Step 2-1. make SN
         cd DAILEO/Supernova/projects;
         source buildsettings/build_A5_129E_IPC.sh;
         make rebuild_all;
         make image_all;
         # Step 3-1. tool-chain
         # N/A
         # Step 3-2. make DFB
         cd ../../../THEALE/RedLion/Lunar/directfb/1.4.2/;
         ./AutoRelease/configure_muf_modify.sh a5-softfloat;
export THEALE_PATH=$(pwd)/../../../..;
echo $THEALE_PATH;
         source ./mstconfigure_muf.sh;
         ./AutoRelease/libtool_modify.sh;
         make all;
         rm -rf $OUTPUT_DIR/*;
         make install;
         ./mstconfigure_muf.sh package ./;
         # Step 4-1. tool-chain
         # N/A
         # Step 4-2. make SN
         cp ./directfb-1.4.2m.tar.gz ../../../../../DAILEO/Supernova/develop/extra/target/mips-glibc/softfloat;
         cd ../../../../../DAILEO/Supernova/projects;
         source buildsettings/build_A5_129E_IPC.sh;
         sed -i 's/FPU_ENABLE \= 1/FPU_ENABLE \= 0/g' ./board/a5/pcb.mk;
         sed -i 's/SKYPE_ENABLE = 1/SKYPE_ENABLE = 0/g' ./sw_cfg/europe_dtv/config.mk;
         sed -i 's/QTWEBKIT_ENABLE = 1/QTWEBKIT_ENABLE = 0/g' ./sw_cfg/europe_dtv/config.mk
         sed -i 's/@grep -B3/#@grep -B3/g' ../target/Makefile;
         make rebuild_all;
         make image_all;
         ;;
     A3-HARDFLOAT | a3-hardfloat | A3-HardFloat)
         # Step 2-1. tool-chain
         export PATH1=$PATH;
         # Step 2-1. make SN
         cd DAILEO/Supernova/projects;
         source buildsettings/build_A3_145B_DVB_IPC.sh;
         make rebuild_all;
         make image_all;
         # Step 3-1. tool-chain
         export PATH=/tools/arm-2011.09-70-lite/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin:$PATH;
         # Step 3-2. make DFB
         cd ../../../THEALE/RedLion/Lunar/directfb/1.4.2;
         ./AutoRelease/configure_muf_modify.sh a3-hardfloat;
export THEALE_PATH=$(pwd)/../../../..;
echo $THEALE_PATH;
         source ./Arm_mstconfigure_muf.sh;
         ./AutoRelease/libtool_modify.sh;
         make all;
         rm -rf $OUTPUT_DIR/*;
         make install;
         ./Arm_mstconfigure_muf.sh package ./;
         # Step 4-1. tool-chain
         export PATH=$PATH1
         # Step 4-2. make SN
         cp ./directfb-1.4.2m.tar.gz ../../../../../DAILEO/Supernova/develop/extra/target/arm-gnueabi/hardfloat
         cd ../../../../../DAILEO/Supernova/projects;
         source buildsettings/build_A3_145B_DVB_IPC.sh;
         sed -i 's/FPU_ENABLE \= 1/FPU_ENABLE \= 1/g' ./board/a3/pcb.mk;
         sed -i 's/SKYPE_ENABLE = 1/SKYPE_ENABLE = 0/g' ./sw_cfg/europe_dtv/config.mk
         sed -i 's/@grep -B3/#@grep -B3/g' ../target/Makefile;
         make rebuild_all;
         make image_all;
         ;;
     A3-SOFTFLOAT | a3-softfloat | A3-SoftFloat)
         # Step 2-1. tool-chain
         export PATH1=$PATH;
         # Step 2-1. make SN
         cd DAILEO/Supernova/projects;
         source buildsettings/build_A3_145B_DVB_IPC.sh;
         make rebuild_all;
         make image_all;
         # Step 3-1. tool-chain
         export PATH=/tools/arm-2011.09-70-lite/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin:$PATH;
         # Step 3-2. make DFB
         cd ../../../THEALE/RedLion/Lunar/directfb/1.4.2;
         ./AutoRelease/configure_muf_modify.sh a3-softfloat;
export THEALE_PATH=$(pwd)/../../../..;
echo $THEALE_PATH;
         source ./Arm_mstconfigure_muf.sh;
         ./AutoRelease/libtool_modify.sh;
         make all;
         rm -rf $OUTPUT_DIR/*;
         make install;
         ./Arm_mstconfigure_muf.sh package ./;
         # Step 4-1. tool-chain
         export PATH=$PATH1
         # Step 4-2. make SN
         cp ./directfb-1.4.2m.tar.gz ../../../../../DAILEO/Supernova/develop/extra/target/arm-gnueabi/softfloat;
         cd ../../../../../DAILEO/Supernova/projects;
         source buildsettings/build_A3_145B_DVB_IPC.sh;
         sed -i 's/FPU_ENABLE \= 1/FPU_ENABLE \= 0/g' ./board/a3/pcb.mk;
         sed -i 's/SKYPE_ENABLE = 1/SKYPE_ENABLE = 0/g' ./sw_cfg/europe_dtv/config.mk
         sed -i 's/@grep -B3/#@grep -B3/g' ../target/Makefile;
         make rebuild_all;
         make image_all;
         ;;    
     EIFFEL-HARDFLOAT | eiffel-hardfloat | Eiffel-HardFloat)
         # Step 2-1. tool-chain
         export PATH1=$PATH;
         # Step 2-1. make SN
         cd DAILEO/Supernova/projects;
         source buildsettings/build_Eiffel_169A_IPC_OPEN_BROWSER.sh;
         make rebuild_all;
         make image_all;
         # Step 3-1. tool-chain
         export PATH=/tools/arm-2011.09-70-lite/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin:$PATH;
         # Step 3-2. make DFB
         cd ../../../THEALE/RedLion/Lunar/directfb/1.4.2;
         ./AutoRelease/configure_muf_modify.sh eiffel-hardfloat;
export THEALE_PATH=$(pwd)/../../../..;
echo $THEALE_PATH;
         source ./Arm_mstconfigure_muf.sh;
         ./AutoRelease/libtool_modify.sh;
         make all;
         rm -rf $OUTPUT_DIR/*;
         make install;
         ./Arm_mstconfigure_muf.sh package ./;
         # Step 4-1. tool-chain
         export PATH=$PATH1
         # Step 4-2. make SN
         cp ./directfb-1.4.2m.tar.gz ../../../../../DAILEO/Supernova/develop/extra/target/arm-gnueabi/hardfloat
         cd ../../../../../DAILEO/Supernova/projects;
         source buildsettings/build_Eiffel_169A_IPC_OPEN_BROWSER.sh
         sed -i 's/FPU_ENABLE \= 1/FPU_ENABLE \= 1/g' ./board/eiffel/pcb.mk;
         sed -i 's/SKYPE_ENABLE = 1/SKYPE_ENABLE = 0/g' ./sw_cfg/europe_dtv/config.mk
         sed -i 's/@grep -B3/#@grep -B3/g' ../target/Makefile;
         make rebuild_all;
         make image_all;
         ;;
     EIFFEL-SOFTFLOAT | eiffel-softfloat | Eiffel-SoftFloat)
         # Step 2-1. tool-chain
         export PATH1=$PATH;
         # Step 2-1. make SN
         cd DAILEO/Supernova/projects;
         source buildsettings/build_Eiffel_169A_IPC_OPEN_BROWSER.sh;
         make rebuild_all;
         make image_all;
         # Step 3-1. tool-chain
         export PATH=/tools/arm-2011.09-70-lite/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin:$PATH;
         # Step 3-2. make DFB
         cd ../../../THEALE/RedLion/Lunar/directfb/1.4.2;
         ./AutoRelease/configure_muf_modify.sh eiffel-softfloat;
export THEALE_PATH=$(pwd)/../../../..;
echo $THEALE_PATH;
         source ./Arm_mstconfigure_muf.sh;
         ./AutoRelease/libtool_modify.sh;
         make all;
         rm -rf $OUTPUT_DIR/*;
         make install;
         ./Arm_mstconfigure_muf.sh package ./;
         # Step 4-1. tool-chain
         export PATH=$PATH1
         # Step 4-2. make SN
         cp ./directfb-1.4.2m.tar.gz ../../../../../DAILEO/Supernova/develop/extra/target/arm-gnueabi/softfloat;
         cd ../../../../../DAILEO/Supernova/projects;
         source buildsettings/build_Eiffel_169A_IPC_OPEN_BROWSER.sh
         sed -i 's/FPU_ENABLE \= 1/FPU_ENABLE \= 0/g' ./board/eiffel/pcb.mk;
         sed -i 's/SKYPE_ENABLE = 1/SKYPE_ENABLE = 0/g' ./sw_cfg/europe_dtv/config.mk
         sed -i 's/@grep -B3/#@grep -B3/g' ../target/Makefile;
         make rebuild_all;
         make image_all;
         ;;    
     A7P-HARDFLOAT | a7p-hardfloat | A7p-HardFloat)
         # Step 2-1. tool-chain
         export PATH=/tools/mips-2011.09/bin/:$PATH;
         # Step 2-1. make SN
         cd DAILEO/Supernova/projects;
         source buildsettings/build_Amethyst_028B_DVB_Lite_UCLIBC_SPI.sh
         make rebuild_all;
         make image_all;
         # Step 3-1. tool-chain
         # N/A
         # Step 3-2. make DFB
         cd ../../../THEALE/RedLion/Lunar/directfb/1.4.2/;
         ./AutoRelease/configure_muf_modify.sh a7p-hardfloat;
export THEALE_PATH=$(pwd)/../../../..;
echo $THEALE_PATH;
         source ./mstconfigure_muf_uclibc.sh;
         ./AutoRelease/libtool_modify.sh;
         sed -i 's/#include <stropts.h>.*/\/\/#include <stropts.h>/g' ./inputdrivers/mstarir/mstarir.c;
         make all;
         rm -rf $OUTPUT_DIR/*;
         make install;
         ./mstconfigure_muf_uclibc.sh package ./;
         # Step 4-1. tool-chain
         # N/A
         # Step 4-2. make SN
          cp ./directfb-1.4.2m.tar.gz ../../../../../DAILEO/Supernova/develop/extra/target/mips-uclibc/hardfloat
         cd ../../../../../DAILEO/Supernova/projects;
         source buildsettings/build_Amethyst_028B_DVB_Lite_UCLIBC_SPI.sh
         make rebuild_all;
         make image_all;         
         ;;
     K3-HARDFLOAT | k3-hardfloat | K3-HardFloat)
export PHOTOSPHERE_ROOT=$PHOTOSPHERE_ROOT;
echo $PHOTOSPHERE_ROOT;
export KERNEL_PATH=$KERNEL_PATH;
echo $KERNEL_PATH;
         # Step 2-1. tool-chain
         export PATH1=$PATH;
         # Step 2-1. make SN
         cd $PHOTOSPHERE_ROOT/cus_mstar/project/mstar_demo;
         make;
         # Step 3-1. tool-chain
         export PATH=/tools/arm-2011.09-70-lite/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin:$PATH;
         # Step 3-2. make DFB
         cd ../../../../../../THEALE/RedLion/Lunar/directfb/1.4.2;
         ./AutoRelease/configure_muf_modify.sh k3-hardfloat;
export THEALE_PATH=$(pwd)/../../../..;
echo $THEALE_PATH;
         source ./mstconfigure_ddi_arm.sh;
         ./AutoRelease/libtool_modify.sh;
         make all;
         rm -rf $OUTPUT_DIR/*;
         make install;
         ./mstconfigure_ddi_arm.sh package ./;
         cp directfb-1.4.2m.tar.gz $PHOTOSPHERE_ROOT/cus_mstar/mw_util_lib/
         ;;
     *)
     
         echo ##### modify configure_muf.sh
         exit 1
         ;;
esac
