The little things give you away... A collection of various small helper stuff
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

18 lignes
1.0 KiB

  1. #!/bin/bash
  2. # Usage: create a file foo.c, make foo a symlink to this script
  3. # When foo is executed, this script silently compiles foo.c into .make-and-exec-binaries/foo (if necessary) and execs that with the arguments provided.
  4. # Making a symlink named foo-dbg causes it to compile foo.c with -DDEBUG.
  5. # To customise the compilation, you can set a CFLAGS env var before running foo.
  6. sourcename="${0%-dbg}.c"
  7. if [[ "$0" == *-dbg ]]; then opt='-Og -fsanitize=undefined,address -DDEBUG'; else opt='-O3'; fi
  8. targetfile="$(dirname "$0")/.make-and-exec-binaries/$(basename "$0")"
  9. if [[ ! -f "${targetfile}" || "${sourcename}" -nt "${targetfile}" || "${BASH_SOURCE}" -nt "${targetfile}" ]]; then
  10. mkdir -p "$(dirname "$0")/.make-and-exec-binaries"
  11. gcc -Wall -Wextra -Wshadow -Werror ${opt} ${CFLAGS} -o "${targetfile}" "${sourcename}" || exit
  12. testfile="$(dirname "$0")/.$(basename "${0%-dbg}")-test"
  13. if [[ -f "${testfile}" ]]; then
  14. "${testfile}" || { st=$?; touch -d '1970-01-01T00:00:00Z' "${targetfile}"; exit "${st}"; }
  15. fi
  16. fi
  17. exec "${targetfile}" "$@"