Created
October 26, 2012 18:28
-
-
Save themasch/3960528 to your computer and use it in GitHub Desktop.
Simple build script. Who needs autoconf?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ######## defaults | |
| EXECUTABLE_NAME="a.out" | |
| LIBS="" | |
| LOG_FILE="/tmp/$(basename $0).$RANDOM.log" | |
| COMPILE_OPTS="" | |
| LINK_OPTS="" | |
| if [ "$1" == "debug" ] | |
| then | |
| COMPILE_OPTS="-ggdb -DDEBUG" | |
| fi | |
| ######## colors | |
| COLOR_RED="" | |
| COLOR_GREEN="" | |
| COLOR_CYAN="" | |
| COLOR_RESET="" | |
| if [ -t 1 ] | |
| then | |
| COLOR_RED="\e[31m" | |
| COLOR_GREEN="\e[32m" | |
| COLOR_CYAN="\e[36m" | |
| COLOR_RESET="\e[0m" | |
| fi | |
| function check_exit() | |
| { | |
| if [ $? == 0 ] | |
| then | |
| echo -e $COLOR_GREEN" successfull"$COLOR_RESET | |
| else | |
| echo -e $COLOR_RED" error"$COLOR_RESET | |
| cat $LOG_FILE | |
| exit 1 | |
| fi | |
| } | |
| if [ -f ./build_config.sh ] | |
| then | |
| . ./build_config.sh | |
| else | |
| echo -e $COLOR_RED"no build_config.sh found, exiting"$COLOR_RESET | |
| exit 1 | |
| fi | |
| touch $LOG_FILE | |
| echo -e $COLOR_CYAN"logging to "$COLOR_RESET$LOG_FILE | |
| if [ -d ./objs/ ] | |
| then | |
| echo -ne $COLOR_GREEN"clearing objs" | |
| rm -f ./objs/* 2> $LOG_FILE | |
| check_exit | |
| else | |
| echo -ne $COLOR_GREEN"creating object dir" | |
| mkdir -p ./objs 2> $LOG_FILE | |
| check_exit | |
| fi | |
| for filename in ./src/*.c | |
| do | |
| modname=${filename#./src/} | |
| modname=./objs/${modname%.c}.o | |
| echo -ne $COLOR_GREEN"compiling"$COLOR_RESET $filename $COLOR_GREEN"->"$COLOR_RESET $modname | |
| ${CC:=gcc} -c $filename -o $modname $COMPILE_OPTS 2> $LOG_FILE | |
| check_exit | |
| done; | |
| echo -ne $COLOR_GREEN"linking"$COLOR_RESET | |
| ${CC:=gcc} -o $EXECUTABLE_NAME objs/*.o $LINK_OPTS $LIBS 2> $LOG_FILE | |
| check_exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| EXECUTABLE_NAME="some_cool_name" | |
| LIBS="-llibthatyouneed" | |
| LOG_FILE="/tmp/$(basename $0).$RANDOM.log" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // build system for sublime text 2 | |
| "build_systems": | |
| [ | |
| { | |
| "cmd": | |
| [ | |
| "./build.sh" | |
| ], | |
| "name": "build.sh", | |
| "selector": "source.c", | |
| "working_dir": "${project_path}" | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment