Switch from make to scons

Scons will track changes to my include/ directory better than make will.
I also have an easier time understanding the Sconstruct file than I did
with Makefiles.
This commit is contained in:
Bryan Schumaker 2011-08-28 11:10:58 -04:00
parent ac03eed3f5
commit 7e9b2f9380
7 changed files with 58 additions and 94 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.o
*.swp
.sconsign.dblite
ocarina
include/version.h

View File

@ -1,41 +0,0 @@
MAJOR = 5
MINOR = 0
BUG = 0
DEBUG = y
export CC = g++
export INCLUDE = -I$(CURDIR)/include
export GTK = `pkg-config --cflags --libs gtk+-2.0`
export GST = `pkg-config --cflags --libs gstreamer-0.10`
export LINK = $(GST) $(GTK)
export SRCDIR = $(CURDIR)
export MAKEFLAGS = --no-print-directory
DIRS = libsaria gui
CLEANDIRS = $(DIRS:%=clean-%)
ifeq ($(DEBUG), y)
export CFLAGS = -Wall -Werror -g -DDEBUG
else
export CFLAGS = -O2
endif
export BUILD = $(CC) $(CFLAGS) $(INCLUDE)
.PHONY: all $(DIRS) clean $(CLEANDIRS) version.h
all: version.h $(DIRS)
$(BUILD) $(shell find . | grep "\.o$$") -o ocarina $(LINK)
version.h:
sh scripts/make_version.sh $(SRCDIR) $(MAJOR) $(MINOR) $(BUG) $(DEBUG)
$(DIRS):
$(MAKE) -f $(SRCDIR)/scripts/Makefile -C $@
clean: $(CLEANDIRS)
rm -f *.o ocarina include/version.h
$(CLEANDIRS):
$(MAKE) -f $(SRCDIR)/scripts/Makefile -C $(@:clean-%=%) clean

43
Sconstruct Normal file
View File

@ -0,0 +1,43 @@
MAJOR = 5
MINOR = 0
BUG = 0
CONFIG={"FLAGS":[]}
def read_config():
for line in open("config"):
(key, value) = line.strip().split("=")
CONFIG[key] = value
if value == "y":
CONFIG["FLAGS"] += ["-D"+key]
read_config()
FLAGS = ["-O2"]
if CONFIG["DEBUG"] == "y":
FLAGS = ["-Wall", "-Werror", "-g"]
env = Environment(CCFLAGS = FLAGS + CONFIG["FLAGS"])
if ARGUMENTS.get('VERBOSE') != "1":
env.Append(CXXCOMSTR = "CXX $TARGET")
env.Append(LINKCOMSTR = "Linking $TARGET")
env.Append(CPPPATH = "include")
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
env.ParseConfig('pkg-config --cflags --libs gstreamer-0.10')
def version_h():
f = open("include/version.h", "w")
for line in open("include/version.tmpl", "r"):
line = line.replace("__MAJOR__", str(MAJOR))
line = line.replace("__MINOR__", str(MINOR))
line = line.replace("__BUG__", str(BUG))
line = line.replace("__EXTRA__", CONFIG["EXTRA"])
f.write(line)
f.close()
version_h()
def list_dirs(directory):
import os
dirs = [x[0] for x in os.walk(directory)]
return [Glob(dir + "/*.cpp") for dir in dirs]
ocarina=env.Program('ocarina', list_dirs('libsaria') + list_dirs('gui'))
Clean(ocarina, "include/version.h")

2
config Normal file
View File

@ -0,0 +1,2 @@
EXTRA=
DEBUG=y

View File

@ -5,10 +5,15 @@
#include <sstream>
using namespace std;
unsigned int MAJOR = AAAAA;
unsigned int MINOR = BBBBB;
unsigned int BUG = CCCCC;
string EXTRA = "DDDDD";
unsigned int MAJOR = __MAJOR__;
unsigned int MINOR = __MINOR__;
unsigned int BUG = __BUG__;
string EXTRA = "__EXTRA__";
#ifdef DEBUG
bool IS_DEBUG = true;
#else /* DEBUG */
bool IS_DEBUG = false;
#endif /* DEBUG */
string vers_str()
{
@ -17,7 +22,9 @@ string vers_str()
if (BUG != 0)
stream << "." << BUG;
if (EXTRA != "")
stream << EXTRA;
stream << "-" << EXTRA;
if (IS_DEBUG == true)
stream << "-" << "debug";
return stream.str();
}
#endif /* OCARINA_VERSION_H */

View File

@ -1,22 +0,0 @@
# Bryan Schumaker (4 / 1 / 2011)
DIRS = $(shell ls -l | grep '^d' | awk '{print $$9}')
FILES = $(shell ls *.cpp)
OBJS = $(FILES:%.cpp=%.o)
CLEANDIRS = $(DIRS:%=clean-%)
.PHONY: all $(DIRS) clean $(CLEANDIRS)
all:$(OBJS) $(DIRS)
%.o: %.cpp
$(BUILD) -c $*.cpp $(LINK)
$(DIRS):
$(MAKE) -f $(SRCDIR)/scripts/Makefile -C $@
clean: $(CLEANDIRS)
rm -f *.o
$(CLEANDIRS):
$(MAKE) -f $(SRCDIR)/scripts/Makefile -C $(@:clean-%=%) clean

View File

@ -1,26 +0,0 @@
#!/bin/bash
SRCDIR=$1
MAJOR=$2
MINOR=$3
BUG=$4
EXTRA=""
if [ "$5" == "y" ]; then
EXTRA="-debug"
fi
FILE=$SRCDIR/include/version.h
rm -f $FILE
cp $SRCDIR/scripts/version.tmpl $FILE
function replace
{
sed "s/$1/$2/" $FILE > $FILE.new
mv $FILE.new $FILE
}
replace AAAAA $MAJOR
replace BBBBB $MINOR
replace CCCCC $BUG
replace DDDDD $EXTRA