dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE

crun (974B)


      1 #!/bin/sh
      2 
      3 # CRUN compiles C/C++ code to a temporary file, and executes it.
      4 # Author: Anders Damsgaard, andersd@risup.net
      5 # License: GNU Public License, v. 3+
      6 
      7 # Define compilers and the common compiler flags
      8 CC=cc
      9 CXX=cpp
     10 CFLAGS="-g -Wall -Wextra "
     11 
     12 fullfilename=$(basename "$1")
     13 extension="${fullfilename##*.}"
     14 filename="${fullfilename%.*}"
     15 tmpname=/tmp/$filename
     16 
     17 # Check if the corresponding file is older than the source
     18 # and recompile it if that's the case.
     19 # arg 1: compiler, arg 2: source code file
     20 compile() {
     21 	if [ -e "$tmpname" ]; then
     22 		if test "$2" -nt "$tmpname"; then
     23 			$1 "$2" -o "$tmpname" "$CFLAGS" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
     24 		fi
     25 	else
     26 		$1 "$2" -o "$tmpname" "$CFLAGS" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
     27 	fi
     28 }
     29 
     30 # Compile source to file in /tmp
     31 if [ "$extension" = "c" ]; then
     32 	compile $CC "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
     33 fi
     34 
     35 if [ "$extension" = "cpp" ]; then
     36 	compile $CXX "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
     37 fi
     38 
     39 $tmpname