Makefile
build/
*.o
+*.d
+*.gcno
+*.gcda
.rsconscache
+config.mk
+testcds
+libcds.a
+++ /dev/null
-source 'http://rubygems.org'
-gem 'rscons'
-gem 'rake'
+++ /dev/null
-GEM
- remote: http://rubygems.org/
- specs:
- json (1.8.2)
- rake (10.4.2)
- rscons (1.9.0)
- json (~> 1.0)
-
-PLATFORMS
- ruby
- x86-mingw32
-
-DEPENDENCIES
- rake
- rscons
LDFLAGS += ${LIBS}
ARFLAGS = rcs
+# commands
+COMPILE = @echo CC $@; ${CC} ${CFLAGS} -c -o $@ $<
+LINK = @echo LD $@; ${LD} -o $@ $^ ${LDFLAGS}
+ARCHIVE = @echo AR $@; ${AR} ${ARFLAGS} $@ $^
+CLEAN = @rm -f
+
#------------------------------------------------------------------------------
# Build Targets and Rules
#------------------------------------------------------------------------------
-SRCS = source/vector/vec.c \
- source/map/map.c \
- source/string/str.c \
- source/rbt/rbt.c \
- source/mem/mem.c \
- source/murmur3/murmur3.c \
- source/buffer/buf.c \
- source/list/list.c \
- source/exn/exn.c \
- source/set/set.c \
- source/cmp/cmp.c
-OBJS = ${SRCS:.c=.o}
-
-TEST_SRCS = tests/main.c \
- tests/test_list.c \
- tests/test_exn.c \
- tests/test_str.c \
- tests/test_set.c \
- tests/test_vec.c \
- tests/test_rbt.c \
- tests/test_map.c \
- tests/test_buf.c \
- tests/test.c
-TEST_OBJS = ${TEST_SRCS:.c=.o}
-
-all: options libcds.a testcds
+LIBNAME = cds
+LIB = lib${LIBNAME}.a
+DEPS = ${OBJS:.o=.d}
+OBJS = source/vector/vec.o \
+ source/map/map.o \
+ source/string/str.o \
+ source/rbt/rbt.o \
+ source/mem/mem.o \
+ source/murmur3/murmur3.o \
+ source/buffer/buf.o \
+ source/list/list.o \
+ source/exn/exn.o \
+ source/set/set.o \
+ source/cmp/cmp.o
+
+TEST_BIN = test${LIBNAME}
+TEST_DEPS = ${TEST_OBJS:.o=.d}
+TEST_OBJS = tests/main.o \
+ tests/test_list.o \
+ tests/test_exn.o \
+ tests/test_str.o \
+ tests/test_set.o \
+ tests/test_vec.o \
+ tests/test_rbt.o \
+ tests/test_map.o \
+ tests/test_buf.o \
+ tests/test.o
+
+# load user-specific settings
+-include config.mk
+
+all: options ${LIB} ${TEST_BIN} tests
options:
@echo "Toolchain Configuration:"
@echo " AR = ${AR}"
@echo " ARFLAGS = ${ARFLAGS}"
-libcds.a: ${OBJS}
- @echo AR $@
- @${AR} ${ARFLAGS} $@ ${OBJS}
+tests: ${TEST_BIN}
+ -./$<
-testcds: ${TEST_OBJS} libcds.a
- @echo LD $@
- @${LD} -o $@ ${TEST_OBJS} libcds.a ${LDFLAGS}
- -./$@
+clean:
+ ${CLEAN} ${LIB} ${TEST_BIN} ${OBJS} ${TEST_OBJS} ${DEPS} ${TEST_DEPS}
+ ${CLEAN} ${OBJS:.o=.gcno} ${OBJS:.o=.gcda}
+ ${CLEAN} ${TEST_OBJS:.o=.gcno} ${TEST_OBJS:.o=.gcda}
+ ${CLEAN} ${DEPS} ${TEST_DEPS}
+
+${LIB}: ${OBJS}
+ ${ARCHIVE}
+
+${TEST_BIN}: ${TEST_OBJS} ${LIB}
+ ${LINK}
.c.o:
- @echo CC $<
- @${CC} ${CFLAGS} -c -o $@ $<
+ ${COMPILE}
-clean:
- @rm -f libcds.a testcds ${OBJS} ${TEST_OBJS}
+# load dependency files
+-include ${DEPS}
+-include ${TEST_DEPS}
-.PHONY: all options
+.PHONY: all options tests
-C Data Structures Lib
-=====================
+# C Data Structures Lib
Created By: Michael D. Lowis & A. Bellenir
Email: mike@mdlowis.com; libcds@bellenir.com
-About This Project
-------------------
+## About This Project
+
This library is meant to be a collection of common data structures, implemented
in C, that can be used in any C or C++ program. The goal is to implement many
of the same data structures that the C++ STL provides, in pure C.
-License
--------
+## License
+
Unless explicitly stated otherwise, all code and documentation contained within
this repository is released under the BSD 2-Clause license. The text for this
license can be found in the LICENSE.md file.
-Requirements For Building
--------------------------
-The following dependencies are required for building the library and running the
-tests:
-
-* GCC
-* Ruby (>= 1.9.3)
-* Rake
-* Bundler
-
-Build Instructions
-------------------
-This project uses a combination of Rscons, Rake, and Bundler for the build
-system. The first step to building the project is to ensure the necessary
-dependencies are installed via bundler. The following command will fetch and
-install the necessary Ruby gems:
-
- bundle install
-
-If the installation completes successfully you are all set to build the
-software. Simply execute rake from the root to run all tests and build the
-library:
-
- rake
-
-If you would like more fine-grained control over the build you can see all
-available rake tasks with the following command:
-
- rake -T
-
-Project Files and Directories
------------------------------
- Gemfile Used to specify bundler dependencies.
- Gemfile.lock Generated by bundler and used by Rakefile to lock dependencies.
- LICENSE.md The software license notification.
- README.md You're reading this file right now!
- Rakefile The main build script, used to control the build.
- build/ This is the directory where all output files will be placed.
- source/ The source for the project.
- tests/ Unit test and mock files.
+## Build Instructions
+
+### Requirements For Building
+
+A POSIX-compliant implementation of Make and a C99 compatible compiler
+(appearing as the command "c99" in the path) are all that is required to build
+this project.
+
+### Configuring the Build
+
+The build is configured to build using c99 with POSIX-compliant tools and
+settings by default. These settings can be overridden using the config.mk file
+in the root of the project. This file contains a number of commented out macros
+which can be uncommented and adjusted to provide a variety of useful features
+for development.
+
+### Building
+
+Simply execute make from the root to run all tests and build the library:
+
+ make
+++ /dev/null
-#------------------------------------------------------------------------------
-# Bundler Setup
-#------------------------------------------------------------------------------
-require "bundler"
-begin
- Bundler.setup(:default, :development)
-rescue Bundler::BundlerError => e
- raise LoadError.new("Unable to Bundler.setup(): You probably need to run `bundle install`: #{e.message}")
-end
-require 'rscons'
-require 'rbconfig'
-
-#------------------------------------------------------------------------------
-# Envrionment Definitions
-#------------------------------------------------------------------------------
-# Define the compiler environment
-Env = Rscons::Environment.new do |env|
- env.build_dir('source','build/obj/source')
- env["CFLAGS"] += ['--std=c99', '--pedantic', '-Wall', '-Wextra', '-Werror']
- env['CPPPATH'] += Dir['source/**/']
-end
-
-# Define the test environment
-TestEnv = Env.clone do |env|
- env.build_dir('source','build/obj/test_source')
- env.build_dir('tests','build/obj/tests/source')
- env['CFLAGS'] += ['-g', '--coverage', '-DLEAK_DETECT_LEVEL=1', '-DTESTING']
- env["LDFLAGS"] += ['--coverage']
- env['CPPPATH'] += Dir['tests/']
-end
-
-# Make sure the environment is processed before we quit
-at_exit { Env.process; TestEnv.process}
-
-#------------------------------------------------------------------------------
-# Main Build Targets
-#------------------------------------------------------------------------------
-task :default => [:test, :build]
-
-desc "Build the C Data Structures static library"
-task :build do
- Env.Library('build/libcds.a', Dir['source/**/*.c'])
- Env.process
-end
-
-#------------------------------------------------------------------------------
-# Unit Testing Targets
-#------------------------------------------------------------------------------
-desc "Run all unit tests"
-task :test do
- TestEnv.Program('build/test_libcds', Dir['source/**/*.c', 'tests/**/*.c'])
- TestEnv.process
- sh "build/test_libcds"
-end
-
-desc "Generate test coverage reports"
-task :coverage => [:test] do
- FileList['build/obj/test_source/**/*.gcno'].each do |gcno|
- obj = gcno.ext('o')
- path = File.dirname(obj)
- gcov = File.basename(obj).ext('c.gcov')
- sh *['gcov', '-a', '-b', '-c', obj] and FileUtils.mv("./#{gcov}","#{path}/#{gcov}")
- end
-end
-
-#------------------------------------------------------------------------------
-# Cleanup Target
-#------------------------------------------------------------------------------
-desc "Clean all generated files and directories"
-task(:clean) { Rscons.clean }
-
-desc "Clobber all generated files and directories"
-task(:clobber) { FileUtils.rm_rf('build') }
-