]> git.mdlowis.com Git - archive/carl.git/commitdiff
Switched to a simple POSIX compliant makefile
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 29 Nov 2015 22:12:51 +0000 (17:12 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 29 Nov 2015 22:12:51 +0000 (17:12 -0500)
12 files changed:
.gitmodules
Gemfile [deleted file]
Gemfile.lock [deleted file]
LICENSE.md [moved from LICENSE with 100% similarity]
Makefile [new file with mode: 0644]
build.ninja [deleted file]
build.rb [deleted file]
modules/atf [deleted submodule]
modules/build-system [deleted submodule]
project.rb [deleted file]
tests/atf.c [new file with mode: 0644]
tests/atf.h [new file with mode: 0644]

index 48ebd4b01f8b65c4db5a2de579bb68a771573880..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,6 +0,0 @@
-[submodule "modules/build-system"]
-    path = modules/build-system
-    url = https://github.com/mikedlowis/build-system.git
-[submodule "modules/atf"]
-       path = modules/atf
-       url = https://github.com/mikedlowis/atf.git
diff --git a/Gemfile b/Gemfile
deleted file mode 100644 (file)
index 894906d..0000000
--- a/Gemfile
+++ /dev/null
@@ -1,4 +0,0 @@
-source 'https://rubygems.org'
-gem 'rake', '>= 0'
-gem 'rscons', '>= 0'
-gem 'rspec', '>= 0'
diff --git a/Gemfile.lock b/Gemfile.lock
deleted file mode 100644 (file)
index 88f9e23..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-GEM
-  remote: https://rubygems.org/
-  specs:
-    diff-lcs (1.2.5)
-    json (1.8.2)
-    rake (10.4.2)
-    rscons (1.9.0)
-      json (~> 1.0)
-    rspec (3.2.0)
-      rspec-core (~> 3.2.0)
-      rspec-expectations (~> 3.2.0)
-      rspec-mocks (~> 3.2.0)
-    rspec-core (3.2.2)
-      rspec-support (~> 3.2.0)
-    rspec-expectations (3.2.0)
-      diff-lcs (>= 1.2.0, < 2.0)
-      rspec-support (~> 3.2.0)
-    rspec-mocks (3.2.1)
-      diff-lcs (>= 1.2.0, < 2.0)
-      rspec-support (~> 3.2.0)
-    rspec-support (3.2.2)
-
-PLATFORMS
-  ruby
-
-DEPENDENCIES
-  rake
-  rscons
-  rspec
similarity index 100%
rename from LICENSE
rename to LICENSE.md
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..944c0ed
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,91 @@
+#------------------------------------------------------------------------------
+# Build Configuration
+#------------------------------------------------------------------------------
+# Update these variables according to your requirements.
+
+# tools
+CC = c99
+LD = ${CC}
+AR = ar
+
+# flags
+INCS      = -Isource/ -Itests/
+CPPFLAGS  = -D_XOPEN_SOURCE=700
+CFLAGS   += ${INCS} ${CPPFLAGS}
+LDFLAGS  += ${LIBS}
+ARFLAGS   = rcs
+
+#------------------------------------------------------------------------------
+# Build Targets and Rules
+#------------------------------------------------------------------------------
+SRCS = source/data/bstree.c               \
+       source/data/hash.c                 \
+       source/data/list.c                 \
+       source/data/slist.c                \
+       source/data/vec.c                  \
+       source/main.c                      \
+       source/refcount.c                  \
+       source/utf/chartorune.c            \
+       source/utf/fullrune.c              \
+       source/utf/runecmp.c               \
+       source/utf/runeinrange.c           \
+       source/utf/runelen.c               \
+       source/utf/runenlen.c              \
+       source/utf/runetochar.c            \
+       source/utf/runetype/alphas.c       \
+       source/utf/runetype/controls.c     \
+       source/utf/runetype/digits.c       \
+       source/utf/runetype/lowers.c       \
+       source/utf/runetype/marks.c        \
+       source/utf/runetype/numbers.c      \
+       source/utf/runetype/other.c        \
+       source/utf/runetype/otherletters.c \
+       source/utf/runetype/punctuation.c  \
+       source/utf/runetype/spaces.c       \
+       source/utf/runetype/symbols.c      \
+       source/utf/runetype/titles.c       \
+       source/utf/runetype/tolower.c      \
+       source/utf/runetype/totitle.c      \
+       source/utf/runetype/toupper.c      \
+       source/utf/runetype/uppers.c       \
+       source/utf/runetype.c
+OBJS = ${SRCS:.c=.o}
+
+TEST_SRCS = tests/data/bstree.c \
+            tests/data/hash.c   \
+            tests/data/slist.c  \
+            tests/atf.c         \
+            tests/main.c        \
+            tests/refcount.c    \
+            tests/utf/test_unicodedata.c
+TEST_OBJS = ${TEST_SRCS:.c=.o}
+
+all: options libcarl.a testcarl
+
+options:
+       @echo "Toolchain Configuration:"
+       @echo "  CC       = ${CC}"
+       @echo "  CFLAGS   = ${CFLAGS}"
+       @echo "  LD       = ${LD}"
+       @echo "  LDFLAGS  = ${LDFLAGS}"
+       @echo "  AR       = ${AR}"
+       @echo "  ARFLAGS  = ${ARFLAGS}"
+
+libcarl.a: ${OBJS}
+       @echo AR $@
+       @${AR} ${ARFLAGS} $@ ${OBJS}
+
+testcarl: ${TEST_OBJS} libcarl.a
+       @echo LD $@
+       @${LD} -o $@ ${TEST_OBJS} libcarl.a ${LDFLAGS}
+       -./$@
+
+.c.o:
+       @echo CC $<
+       @${CC} ${CFLAGS} -c -o $@ $<
+
+clean:
+       @rm -f libcarl.a testcarl ${OBJS} ${TEST_OBJS}
+
+.PHONY: all options
+
diff --git a/build.ninja b/build.ninja
deleted file mode 100644 (file)
index 9a98d49..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-CC = gcc
-DEPSUFFIX = .d
-CPPFLAGS = -Isource/ -Imodules/atf/source
-CFLAGS = -g -O3 -Wall -Wextra --std=c99 --pedantic
-LD = gcc
-LDFLAGS =
-AR = ar
-ARFLAGS = rcs
-
-rule cc
-    command = $CC -MMD -MF $out$DEPSUFFIX $CPPFLAGS $CFLAGS -c -o $out $in
-    depfile = $out$DEPSUFFIX
-rule ld
-    command = $LD $LDFLAGS -o $out $in
-rule ar
-    command = $AR $ARFLAGS $out $in
-    depfile = $out$DEPSUFFIX
-rule command
-    command = $CMD
-
-build source/refcount.o: cc source/refcount.c
-build source/utf/runetype/toupper.o: cc source/utf/runetype/toupper.c
-build source/utf/runetype/tolower.o: cc source/utf/runetype/tolower.c
-build source/utf/runetype/uppers.o: cc source/utf/runetype/uppers.c
-build source/utf/runetype/numbers.o: cc source/utf/runetype/numbers.c
-build source/utf/runetype/symbols.o: cc source/utf/runetype/symbols.c
-build source/utf/runetype/totitle.o: cc source/utf/runetype/totitle.c
-build source/utf/runetype/titles.o: cc source/utf/runetype/titles.c
-build source/utf/runetype/lowers.o: cc source/utf/runetype/lowers.c
-build source/utf/runetype/spaces.o: cc source/utf/runetype/spaces.c
-build source/utf/runetype/punctuation.o: cc source/utf/runetype/punctuation.c
-build source/utf/runetype/alphas.o: cc source/utf/runetype/alphas.c
-build source/utf/runetype/digits.o: cc source/utf/runetype/digits.c
-build source/utf/runetype/controls.o: cc source/utf/runetype/controls.c
-build source/utf/runetype/marks.o: cc source/utf/runetype/marks.c
-build source/utf/runetype/otherletters.o: cc source/utf/runetype/otherletters.c
-build source/utf/runetype/other.o: cc source/utf/runetype/other.c
-build source/utf/runecmp.o: cc source/utf/runecmp.c
-build source/utf/runeinrange.o: cc source/utf/runeinrange.c
-build source/utf/chartorune.o: cc source/utf/chartorune.c
-build source/utf/runetype.o: cc source/utf/runetype.c
-build source/utf/runelen.o: cc source/utf/runelen.c
-build source/utf/fullrune.o: cc source/utf/fullrune.c
-build source/utf/runenlen.o: cc source/utf/runenlen.c
-build source/utf/runetochar.o: cc source/utf/runetochar.c
-build source/data/vec.o: cc source/data/vec.c
-build source/data/list.o: cc source/data/list.c
-build source/data/bstree.o: cc source/data/bstree.c
-build source/data/slist.o: cc source/data/slist.c
-build source/data/hash.o: cc source/data/hash.c
-build source/main.o: cc source/main.c
-build libcarl.a: ar source/refcount.o source/utf/runetype/toupper.o source/utf/runetype/tolower.o source/utf/runetype/uppers.o source/utf/runetype/numbers.o source/utf/runetype/symbols.o source/utf/runetype/totitle.o source/utf/runetype/titles.o source/utf/runetype/lowers.o source/utf/runetype/spaces.o source/utf/runetype/punctuation.o source/utf/runetype/alphas.o source/utf/runetype/digits.o source/utf/runetype/controls.o source/utf/runetype/marks.o source/utf/runetype/otherletters.o source/utf/runetype/other.o source/utf/runecmp.o source/utf/runeinrange.o source/utf/chartorune.o source/utf/runetype.o source/utf/runelen.o source/utf/fullrune.o source/utf/runenlen.o source/utf/runetochar.o source/data/vec.o source/data/list.o source/data/bstree.o source/data/slist.o source/data/hash.o source/main.o
-build tests/refcount.o: cc tests/refcount.c
-build tests/utf/test_unicodedata.o: cc tests/utf/test_unicodedata.c
-build tests/data/bstree.o: cc tests/data/bstree.c
-build tests/data/slist.o: cc tests/data/slist.c
-build tests/data/hash.o: cc tests/data/hash.c
-build tests/main.o: cc tests/main.c
-build modules/atf/source/atf.o: cc modules/atf/source/atf.c
-build test_libc: ld tests/refcount.o tests/utf/test_unicodedata.o tests/data/bstree.o tests/data/slist.o tests/data/hash.o tests/main.o modules/atf/source/atf.o libcarl.a
-build Tests: command test_libc
-    CMD = ./test_libc
diff --git a/build.rb b/build.rb
deleted file mode 100755 (executable)
index 14f5d74..0000000
--- a/build.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env ruby
-require './modules/build-system/setup'
-
-#------------------------------------------------------------------------------
-# Environment Definitions
-#------------------------------------------------------------------------------
-# Define the default compiler environment
-main_env = BuildEnv.new do |env|
-  env["CFLAGS"]  += ['-g', '-O3', '-Wall', '-Wextra', '--std=c99', '--pedantic']
-  env["CPPPATH"] += Dir['source/', 'modules/atf/source']
-end
-
-#------------------------------------------------------------------------------
-# Release Build Targets
-#------------------------------------------------------------------------------
-# Build the library
-main_env.Library('libc.a', FileList['source/**/*.c'])
-
-#------------------------------------------------------------------------------
-# Test Build Targets
-#------------------------------------------------------------------------------
-if Opts[:profile].include? "test"
-  main_env.Program('test_libc', Dir["tests/**/*.c", "modules/atf/source/*.c"] + ['./libc.a'])
-  main_env.Command('Unit Tests', 'test_libc', "CMD" => ['./test_libc'])
-end
-
diff --git a/modules/atf b/modules/atf
deleted file mode 160000 (submodule)
index 1105e4a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 1105e4a88bbda546991da0314ba6060f9f624dba
diff --git a/modules/build-system b/modules/build-system
deleted file mode 160000 (submodule)
index f1a522b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit f1a522b4aed7c58ce3c8467ff8a00f00c3e27e64
diff --git a/project.rb b/project.rb
deleted file mode 100644 (file)
index ab87c5e..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-project do
-  env.CFLAGS   = '-g -O3 -Wall -Wextra --std=c99 --pedantic'
-  env.CPPFLAGS = ['-Isource/', '-Imodules/atf/source']
-
-  library 'libcarl.a', Dir['source/**/*.c']
-  program 'test_libc', Dir["tests/**/*.c", "modules/atf/source/*.c"] + ["libcarl.a"]
-  command 'Tests', 'test_libc', CMD: './test_libc'
-end
diff --git a/tests/atf.c b/tests/atf.c
new file mode 100644 (file)
index 0000000..e1017e8
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+  @file atf.c
+  @brief See header for details
+  $Revision$
+  $HeadURL$
+*/
+#include "atf.h"
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifndef NO_SIGNALS
+#include <signal.h>
+#endif
+
+char* Curr_Test = NULL;
+char* Curr_File = NULL;
+unsigned int Curr_Line = 0;
+static unsigned int Total = 0;
+static unsigned int Failed = 0;
+
+#ifndef NO_SIGNALS
+static void handle_signal(int sig) {
+    /* Determine the signal name */
+    char* sig_name = NULL;
+    switch(sig) {
+        case SIGABRT: sig_name = "SIGABRT"; break;
+        case SIGBUS:  sig_name = "SIGBUS";  break;
+        case SIGFPE:  sig_name = "SIGFPE";  break;
+        case SIGILL:  sig_name = "SIGILL";  break;
+        case SIGSEGV: sig_name = "SIGSEGV"; break;
+        case SIGSYS:  sig_name = "SIGSYS";  break;
+        /* If we don't recognize it then just return and let the default handler
+           catch it. */
+        default:      return;
+    }
+    /* Error and exit. No summary will be printed but the user will know which
+       test has crashed. */
+    fprintf(stderr,"%s:%d:0:%s:CRASH (signal: %d - %s)\n", Curr_File, Curr_Line, Curr_Test, sig, sig_name);
+    Failed++;
+    (void)atf_print_results();
+    exit(1);
+}
+#endif
+
+void atf_init(int argc, char** argv) {
+    /* I reserve the right to use these later */
+    (void)argc;
+    (void)argv;
+
+#ifndef NO_SIGNALS
+    /* Init signal handler */
+    signal(SIGABRT, handle_signal);
+    signal(SIGBUS,  handle_signal);
+    signal(SIGFPE,  handle_signal);
+    signal(SIGILL,  handle_signal);
+    signal(SIGSEGV, handle_signal);
+    signal(SIGSYS,  handle_signal);
+#endif
+}
+
+void atf_run_suite(suite_t suite) {
+    suite();
+}
+
+void atf_test_start(char* file, unsigned int line, char* name) {
+    Curr_File = file;
+    Curr_Line = line;
+    Curr_Test = name;
+    Total++;
+}
+
+bool atf_test_assert(bool success, char* expr, char* file, int line) {
+    bool failed = !success;
+    if (failed) atf_test_fail(expr,file,line);
+    return failed;
+}
+
+void atf_test_fail(char* expr, char* file, int line) {
+    Failed++;
+    printf("%s:%d:0:%s:FAIL:( %s )\n", file, line, Curr_Test, expr); \
+}
+
+int atf_print_results(void) {
+    static const char* results_string =
+    "\nUnit Test Summary"
+    "\n-----------------"
+    "\nTotal:  %d"
+    "\nPassed: %d"
+    "\nFailed: %d"
+    "\n\n";
+    printf(results_string, Total, Total - Failed, Failed);
+    return Failed;
+}
+
diff --git a/tests/atf.h b/tests/atf.h
new file mode 100644 (file)
index 0000000..0e2d2f1
--- /dev/null
@@ -0,0 +1,45 @@
+/**
+  @file atf.h
+  @brief Aardvark Test Framework main interface file.
+  $Revision$
+  $HeadURL$
+*/
+#ifndef TEST_H
+#define TEST_H
+
+#include <stddef.h>
+#include <stdbool.h>
+
+typedef void (*suite_t)(void);
+
+extern char* Curr_Test;
+
+void atf_init(int argc, char** argv);
+
+void atf_run_suite(suite_t suite);
+
+void atf_test_start(char* file, unsigned int line, char* name);
+
+bool atf_test_assert(bool success, char* expr_str, char* file, int line);
+
+void atf_test_fail(char* expr, char* file, int line);
+
+int atf_print_results(void);
+
+#define CHECK(expr) \
+    if(atf_test_assert((expr), #expr, __FILE__, __LINE__)) break
+
+#define TEST_SUITE(name) void name(void)
+
+#define TEST(desc) \
+    for(atf_test_start(__FILE__,__LINE__,#desc); Curr_Test != NULL; Curr_Test = NULL)
+
+#define RUN_EXTERN_TEST_SUITE(name) \
+    do { extern TEST_SUITE(name); atf_run_suite(&name); } while(0)
+
+#define RUN_TEST_SUITE(name) \
+    atf_run_suite(&name)
+
+#define PRINT_TEST_RESULTS atf_print_results
+
+#endif /* TEST_H */