From 5cf97862b58925164293fd314d9f2df69539ceaa Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Thu, 7 Jul 2011 16:04:10 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D1=88=D0=B8=D0=BB=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D0=B8=D0=BB=D0=B8=D1=82=D1=8C=20=D1=81=D0=B2=D0=BE=D0=B9?= =?UTF-8?q?=20smake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bash/smake/etc/smake/build.smk | 60 ++++++++++++++++++++++++ bash/smake/etc/smake/env.smk | 7 +++ bash/smake/etc/smake/rules.smk | 3 ++ bash/smake/smake.sh | 85 ++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 bash/smake/etc/smake/build.smk create mode 100644 bash/smake/etc/smake/env.smk create mode 100644 bash/smake/etc/smake/rules.smk create mode 100755 bash/smake/smake.sh diff --git a/bash/smake/etc/smake/build.smk b/bash/smake/etc/smake/build.smk new file mode 100644 index 0000000..826a6ff --- /dev/null +++ b/bash/smake/etc/smake/build.smk @@ -0,0 +1,60 @@ +#________________________________________ +# BUILD SCRIPT (don't change) | +#_______________________________________| +ifeq ($(mode),) + mode = debug +endif +ifeq ($(mode),debug) + CFLAGS = -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion + LDFLAGS = +endif +ifeq ($(mode),profile) + CFLAGS = -O0 -g -p -ftest-coverage -Wcoverage-mismatch + LDFLAGS = -g -p +endif +ifeq ($(mode),develop) + CFLAGS += -O2 -g + LDFLAGS += -O1 +endif +ifeq ($(mode),release) + CFLAGS += -O2 + LDFLAGS += -O1 +endif + +CFLAGS += -Wall +LDFLAGS += -Wall $(LIBRARIES) + +all: change_build_mode $(TARGET) + +ifneq ($(mode),debug) +ifneq ($(mode),profile) +ifneq ($(mode),develop) +ifneq ($(mode),release) + @echo "Invalid build mode." + @echo "Please use 'make mode=release', 'make mode=develop' or 'make mode=debug'" + @exit 1 +endif +endif +endif +endif + @echo ".........................." + @echo "Building on "$(mode)" mode " + @echo "CFLAGS=$(CFLAGS)" + @echo "LDFLAGS=$(LDFLAGS)" + @echo ".........................." + +OLD_BUILD_MODE=$(shell cat build_mode.out 2>/dev/null) +change_build_mode: +ifneq ($(mode), $(OLD_BUILD_MODE)) + @echo CLEANING... + @make clean &>/dev/null + @echo $(mode) > build_mode.out +endif + +%.o : + $(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $< + +clean: + $(RM) *.o *.out callgrind.out.* *.gcno $(TARGET) + +.PHONY: all change_build_mode clean diff --git a/bash/smake/etc/smake/env.smk b/bash/smake/etc/smake/env.smk new file mode 100644 index 0000000..0959eb4 --- /dev/null +++ b/bash/smake/etc/smake/env.smk @@ -0,0 +1,7 @@ +#_________________________________ +# ENVIRONMENT | +#________________________________| +CC=REP_CC +CXX=REP_CXX +LIBRARIES=REP_LIBRARIES +TARGET=REP_TARGET diff --git a/bash/smake/etc/smake/rules.smk b/bash/smake/etc/smake/rules.smk new file mode 100644 index 0000000..57f68e8 --- /dev/null +++ b/bash/smake/etc/smake/rules.smk @@ -0,0 +1,3 @@ +#_________________________________ +# R U L E S | +#________________________________| diff --git a/bash/smake/smake.sh b/bash/smake/smake.sh new file mode 100755 index 0000000..1d6c4a1 --- /dev/null +++ b/bash/smake/smake.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +REP_CC=cc +REP_CXX=c++ +REP_INCLUDE='-I$(HOME)/projects/include -I/usr/include' +REP_LIBRARIES= +REP_TARGET=target + +SMAKE_DIR=~/dev/bash/smake/etc/smake +ENV_FILE=$SMAKE_DIR/env.smk +BUILD_FILE=$SMAKE_DIR/build.smk +RULES_FILE=$SMAKE_DIR/rules.smk + +# Debug +DEBUG=1 + +# Parameters processing +TEMP=`getopt -o c:x:i:l:t: --long cc:,cxx:,include:,libraries:,target: -- "$@"` +eval set -- "$TEMP" + +while true ; do + case "$1" in + -c|--cc) REP_CC=$2 ; echo "CC=$REP_CC" ; shift 2 ;; + -x|--cxx) REP_CXX=$2 ; echo "CXX=$REP_CXX" ; shift 2 ;; + -i|--include) REP_INCLUDE=$2 ; echo "INCLUDE=$REP_INCLUDE"; shift 2 ;; + -l|--libraries) REP_LIBRARIES=$2 ; echo "LIBRARIES=$REP_LIBRARIES"; shift 2 ;; + -t|--target) REP_TARGET=$2 ; echo "TARGET=$REP_TARGET"; shift 2 ;; + --) shift ; break ;; + *) echo "Internal error!" ; exit 1 ;; + esac +done + +# --- Environment --- +sed "s~REP_CC~$REP_CC~ ; s~REP_CXX~$REP_CXX~ ; \ + s~REP_LIBRARIES~$REP_LIBRARIES~ ; s~REP_TARGET~$REP_TARGET~" $ENV_FILE > Makefile + +# INCLUDE0, INCLUDE1, INCLUDE2, ... +REP_INCLUDE=`echo $REP_INCLUDE | sed "s~-I~~g ; s~\\$(HOME)~${HOME}~"` + +i=1 +for d in $REP_INCLUDE; do + echo "INCLUDE$i=$d" >> Makefile + i=$((i+1)) +done + +for d in $REP_INCLUDE; do + echo -n ' $(INCLUDE'$j')' >> Makefile +done +echo >> Makefile + +echo >> Makefile + +# --- Build --- +cat $BUILD_FILE >> Makefile + +echo >> Makefile + +# --- Rules --- +cat $RULES_FILE >> Makefile + +all_dep_lst=`grep ^\#include\ \" $REP_TARGET.c | sed 's~[^"]*"\([^"]*\)"~\1~' | sort -u` + +while [[ "$all_dep_lst" != "$old_all_dep_lst" ]]; do + old_all_dep_lst=$all_dep_lst + for f in $all_dep_lst; do + F="" + for d in . $REP_INCLUDE; do + #echo "$d/$f" # | sed "s~^${HOME}~$\(HOME\)~" + if [ -f "$d/$f" ]; then + F="$d/$f" + break + fi + done + if [ "$F" == "" ]; then + echo "file \"$f\" not found" + exit -1 + fi + #echo "F=$F" + all_dep_lst="$all_dep_lst "`grep ^\#include\ \" $F | sed 's~[^"]*"\([^"]*\)"~\1~'` + all_dep_lst=`echo $all_dep_lst | sed 's~ ~\n~g' | sort -u` + done +done + +echo "all_dep_lst=$all_dep_lst" +