From 7e9b2f93801b0403522ad0c47b996ddefc8c0ac2 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sun, 28 Aug 2011 11:10:58 -0400 Subject: [PATCH] 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. --- .gitignore | 1 + Makefile | 41 ----------------------------- Sconstruct | 43 +++++++++++++++++++++++++++++++ config | 2 ++ {scripts => include}/version.tmpl | 17 ++++++++---- scripts/Makefile | 22 ---------------- scripts/make_version.sh | 26 ------------------- 7 files changed, 58 insertions(+), 94 deletions(-) delete mode 100644 Makefile create mode 100644 Sconstruct create mode 100644 config rename {scripts => include}/version.tmpl (50%) delete mode 100644 scripts/Makefile delete mode 100755 scripts/make_version.sh diff --git a/.gitignore b/.gitignore index de1fb624..0281b253 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o *.swp +.sconsign.dblite ocarina include/version.h diff --git a/Makefile b/Makefile deleted file mode 100644 index 5e84f28f..00000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/Sconstruct b/Sconstruct new file mode 100644 index 00000000..e33eada5 --- /dev/null +++ b/Sconstruct @@ -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") diff --git a/config b/config new file mode 100644 index 00000000..0d8e4300 --- /dev/null +++ b/config @@ -0,0 +1,2 @@ +EXTRA= +DEBUG=y diff --git a/scripts/version.tmpl b/include/version.tmpl similarity index 50% rename from scripts/version.tmpl rename to include/version.tmpl index 80235d63..3f1e5698 100644 --- a/scripts/version.tmpl +++ b/include/version.tmpl @@ -5,10 +5,15 @@ #include 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 */ diff --git a/scripts/Makefile b/scripts/Makefile deleted file mode 100644 index f9fdb3aa..00000000 --- a/scripts/Makefile +++ /dev/null @@ -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 diff --git a/scripts/make_version.sh b/scripts/make_version.sh deleted file mode 100755 index 990b0fe3..00000000 --- a/scripts/make_version.sh +++ /dev/null @@ -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