Advertisement
FlippySquirrel

auto compile for c programs in directory

Aug 4th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. black='\E[30m'
  4. red='\E[31m'
  5. green='\E[32m'
  6. yellow='\E[33m'
  7. blue='\E[34m'
  8. magenta='\E[35m'
  9. cyan='\E[36m'
  10. white='\E[37m'
  11.  
  12. bold='\033[1m'
  13. normal='\033[2m'
  14.  
  15. #set defaults
  16. COMPILER='gcc'
  17. SUBDIR='progs'
  18.  
  19. while [ ! -z ${1} ]; do
  20.  
  21.     #compiler selection
  22.     if [ "${1}" == "-cc" ]; then
  23.         COMPILER='cc'
  24.         shift
  25.     fi
  26.  
  27.     #subdirectory selection
  28.     if [ "${1}" == "-d" ]; then
  29.         shift
  30.         SUBDIR=${1}
  31.         shift
  32.     fi
  33.  
  34.     if [ "${1}" == "-p" ]; then
  35.         shift
  36.         BASENAME=${1}
  37.         shift
  38.     fi
  39.  
  40. done
  41.  
  42. #if directory doesn't exist
  43. if [ ! -d "${SUBDIR}" ]; then
  44.     mkdir ${SUBDIR}
  45. fi
  46.  
  47. echo -e "\n${yellow}Using ${bold}${COMPILER}${normal} to compile.\n"
  48. echo -e "${yellow}Compiling into ${bold}${SUBDIR}${normal} directory.\n"
  49.  
  50. if [ -z ${BASENAME} ]; then
  51.     for BASENAME in `ls *.c -1`
  52.     do
  53.         echo -e "${bold}${white}Compiling: ${bold}${green}${BASENAME}"
  54.         ${COMPILER} ${BASENAME} -o ${SUBDIR}/${BASENAME%%.c}
  55.     done
  56. else
  57.     echo -e "${bold}${white}Compiling: ${bold}${green}${BASENAME}"
  58.     ${COMPILER} ${BASENAME}.c -o ${SUBDIR}/${BASENAME}
  59. fi
  60.  
  61. tput sgr0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement