]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Added a semi-complete method for finding the location of the executable and by extens...
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 4 Nov 2014 17:50:22 +0000 (12:50 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 4 Nov 2014 17:50:22 +0000 (12:50 -0500)
Rakefile [deleted file]
modules/libcds
source/sclpl/main.c

diff --git a/Rakefile b/Rakefile
deleted file mode 100644 (file)
index 165b3fc..0000000
--- a/Rakefile
+++ /dev/null
@@ -1,124 +0,0 @@
-require "rspec"
-require "rspec/core/rake_task"
-require './build-system/setup'
-
-def windows?
-  RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
-end
-
-#------------------------------------------------------------------------------
-# Envrionment Definitions
-#------------------------------------------------------------------------------
-# Define the compiler environment
-base_env = BuildEnv.new(echo: :command) do |env|
-  env.build_dir('source','build/obj/source')
-  env.build_dir('modules','build/obj/modules')
-  env.set_toolset(:clang)
-  env["CFLAGS"] += ['-DLEAK_DETECT_LEVEL=1', '--std=c99', '-Wall', '-Wextra', '-Werror']
-  env["CPPPATH"] += ['modules/libopts/source'] + Dir['modules/libcds/source/**/']
-end
-
-main_env = base_env.clone do |env|
-  env.build_dir('source','build/obj/source')
-  env.build_dir('modules','build/obj/modules')
-  env["CFLAGS"] += ['-O3']
-end
-
-test_env = base_env.clone do |env|
-  env.build_dir('source','build/obj_test/source')
-  env.build_dir('modules','build/obj_test/modules')
-  env['CFLAGS'] +=  ['-O0', '--coverage']
-  env['LDFLAGS'] += ['--coverage']
-end
-
-#------------------------------------------------------------------------------
-# Clang Toolchain Targets
-#------------------------------------------------------------------------------
-CLANG_BUILD_DIR = 'build/llvm'
-CLANG_BIN_DIR = 'build/llvm/bin'
-CLANG_BIN_NAME = 'clang'
-CLANG_SRC_DIR = 'source/vendor/llvm-3.4.2'
-CLANG_CMAKE_GENERATOR = ENV['CMAKE_GENERATOR'] || "Unix Makefiles"
-CLANG_CMAKE_OPTS = [ '-DCMAKE_BUILD_TYPE=Release' ]
-CLANG_MAKE_CMD = windows? ? 'nmake' : 'make'
-
-file "#{CLANG_BUILD_DIR}/Makefile" => FileList["#{CLANG_SRC_DIR}/cmake/**/*"] do
-    FileUtils.mkdir_p(CLANG_BUILD_DIR)
-    FileUtils.cd(CLANG_BUILD_DIR) do
-        sh "cmake #{CLANG_CMAKE_OPTS.join} -G\"#{CLANG_CMAKE_GENERATOR}\" ../../#{CLANG_SRC_DIR}"
-    end
-end
-
-file "#{CLANG_BIN_DIR}/#{CLANG_BIN_NAME}" => ["#{CLANG_BUILD_DIR}/Makefile"] + FileList["#{CLANG_SRC_DIR}/tools/clang/**/*.c"] do
-    FileUtils.cd(CLANG_BUILD_DIR) do
-        sh "#{CLANG_MAKE_CMD}"
-    end
-end
-
-task :clang => ["#{CLANG_BIN_DIR}/#{CLANG_BIN_NAME}"]
-
-# Register clang with the environment
-ENV['PATH'] = "#{CLANG_BIN_DIR}#{windows? ? ';':':'}#{ENV['PATH']}"
-
-#------------------------------------------------------------------------------
-# Rscons Build Targets
-#------------------------------------------------------------------------------
-task :default => [:build, :spec]
-
-desc "Build all targets"
-task :build => [:clang, :sclpl]
-
-desc "Build the sclpl compiler and interpreter"
-task :sclpl => [:libcds, :libopts] do
-  main_env.Program('build/bin/sclpl',
-    FileList['source/sclpl/*.c', 'build/lib/libopts.a', 'build/lib/libcds.a'])
-end
-
-task :libcds do
-  main_env.Library('build/lib/libcds.a', FileList['modules/libcds/source/**/*.c'])
-end
-
-task :libopts do
-  main_env.Library('build/lib/libopts.a', FileList['modules/libopts/source/**/*.c'])
-end
-
-#------------------------------------------------------------------------------
-# Cleanup Target
-#------------------------------------------------------------------------------
-desc "Clean all rscons generated files and directories"
-task(:clean) { Rscons.clean }
-
-desc "Clean object files generated for vendor libraries as well as rscons"
-task :clean_all => [:clean] do
-  if Dir.exist? CLANG_BUILD_DIR
-    FileUtils.cd(CLANG_BUILD_DIR) { sh "#{CLANG_MAKE_CMD} clean" }
-  end
-end
-
-desc "Clobber the build directory and all it's contents"
-task(:clobber) { FileUtils.rm_rf('build/') }
-
-#------------------------------------------------------------------------------
-# RSpec Tests for the Compiler
-#------------------------------------------------------------------------------
-# Make the specs depend on the libs
-task :spec => [:libcds, :libopts]
-
-# Build and test the compiler with coverage
-RSpec::Core::RakeTask.new(:spec) do |t,args|
-  t.rspec_opts = ['--format', 'documentation']
-  test_env.Program('build/bin/sclpl-test',
-    FileList['source/sclpl/*.c', 'build/lib/libopts.a', 'build/lib/libcds.a'])
-  main_env.process
-  test_env.process
-end
-
-desc "Generate test coverage reports"
-task :coverage => [:spec] do
-  FileList['build/obj_test/**/*.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
index 6f230a518de102ec91186f35ffff401546fd4878..a239e68f5e8711583d9bf5aeedf6365e759f3d84 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 6f230a518de102ec91186f35ffff401546fd4878
+Subproject commit a239e68f5e8711583d9bf5aeedf6365e759f3d84
index 8bbe94108483a022cfc097c07f1b8ba904befb56..2fca00dda41aa8f2769b690517875eff00e85774 100644 (file)
@@ -117,21 +117,54 @@ char Program_Cmd[]   = "cc -o %s %s";
 char StaticLib_Cmd[] = "ar rcs %s %s";
 char SharedLib_Cmd[] = "cc -shared %s";
 
-str_t* str_join(char* joinstr, vec_t* strs) {
-    str_t* ret = str_new("");
-    str_t* jstr = str_new(joinstr);
-    for (size_t idx = 0; idx < vec_size(strs); idx++) {
-        str_t* str = (str_t*)vec_at(strs, idx);
-        if (str_size(ret) > 0)
-            mem_swap((void**)&ret, str_concat(ret, jstr));
-        mem_swap((void**)&ret, str_concat(ret, str));
+/* Utility Functions
+ *****************************************************************************/
+str_t* get_bin_dir(void) {
+    str_t* bindir = NULL;
+    str_t* slash = str_new("/");
+    str_t* progname = str_new(opts_prog_name());
+    size_t index = str_rfind(progname, slash);
+    str_t* path = (index == SIZE_MAX) ? NULL : str_substr(progname, 0, index+1);
+    str_t* prog = (index == SIZE_MAX) ? str_new(str_cstr(progname)) : str_substr(progname, index+1, str_size(progname));
+    if (NULL != path) {
+        bindir = mem_retain(path);
+    } else {
+        error_msg("Could not locate the bin directory");
+        exit(1);
+    //    str_t* pathvar = str_new(getenv("PATH"));
+    //    str_t* sep = str_new(":");
+    //    vec_t* paths = str_split(pathvar, sep);
+    //    for (size_t idx = 0u; idx < vec_size(paths); idx++) {
+    //        str_t* currpath = (str_t*)vec_at(paths, idx);
+    //        str_t* binpath = str_concat(str_concat(currpath, slash), prog);
+    //        if (file_exists(str_cstr(binpath))) {
+    //            bindir = binpath;
+    //            mem_release(currpath);
+    //            break;
+    //        }
+    //        mem_release(currpath);
+    //        mem_release(binpath);
+    //    }
+    //    mem_release(sep);
+    //    mem_release(pathvar);
+    //    mem_release(paths);
     }
-    mem_release(jstr);
-    return ret;
+    mem_release(slash);
+    mem_release(progname);
+    mem_release(path);
+    mem_release(prog);
+    return bindir;
+}
+
+str_t* get_inc_dir(void) {
+    str_t* bindir  = get_bin_dir();
+    str_t* pathmod = str_new("../include/");
+    str_t* incdir  = str_concat(bindir, pathmod);
+    mem_release(bindir);
+    mem_release(pathmod);
+    return incdir;
 }
 
-/* Utility Functions
- *****************************************************************************/
 typedef enum {
     TOKFILE,
     ASTFILE,
@@ -262,7 +295,7 @@ str_t* translate_file(str_t* in) {
 
 str_t* compile_file(str_t* in) {
     str_t* ofname  = get_filename(OBJECT, in);
-    vec_t* parts   = vec_new(3, str_new("clang -c -o"), mem_retain(ofname), mem_retain(in));
+    vec_t* parts   = vec_new(5, str_new("gcc -c -o"), mem_retain(ofname), str_new("-I"), get_inc_dir(), mem_retain(in));
     str_t* command = str_join(" ", parts);
     if (opts_is_set(NULL, "verbose"))
         puts(str_cstr(command));
@@ -392,6 +425,15 @@ static int emit_program(void) {
 int main(int argc, char **argv) {
     opts_parse( Options_Config, argc, argv );
 
+    //str_t* bindir = get_bin_dir();
+    //str_t* incdir = get_inc_dir();
+    //printf("Bin Dir: %s\n", str_cstr(bindir));
+    //printf("Inc Dir: %s\n", str_cstr(incdir));
+    //mem_release(bindir);
+    //mem_release(incdir);
+    //puts("done");
+    //exit(1);
+
     if (!opts_is_set(NULL,"mode")) {
         print_usage();
     } else if(opts_equal(NULL, "mode", "repl")) {