From dacdb0c45c33ad7c3b78ec6d6757ab0d3009b909 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 4 Nov 2014 15:47:35 -0500 Subject: [PATCH] sclpl can now find it's own damn header (when run with a path prefix only) --- build.rb | 60 ++++++++++++++++++++---------------------- source/runtime/sclpl.h | 3 ++- source/sclpl/main.c | 2 +- spec/cli_spec.rb | 7 ++--- 4 files changed, 33 insertions(+), 39 deletions(-) diff --git a/build.rb b/build.rb index 5f9c421..d0c3a62 100755 --- a/build.rb +++ b/build.rb @@ -14,28 +14,35 @@ base_env = BuildEnv.new do |env| env.build_dir('source','build/obj/source') env.build_dir('modules','build/obj/modules') - # Add a builder for creating a CMake project - env.add_builder :CMake do |target, sources, cache, env, vars| - target_dir = File.dirname(target) - source_dir = "../" * target_dir.split(/\\|\//).length + File.dirname(sources.first) - cmd = env.expand_varref("${CMAKE_CMD}", vars.merge('_SOURCES' => source_dir)) - unless cache.up_to_date?(target, cmd, sources, env) - cache.mkdir_p(target_dir) - Dir.chdir(target_dir) { env.execute("CMake #{target}", cmd) } - cache.register_build(target, cmd, sources, env) + env.add_builder :Install do |target, sources, cache, env, vars| + is_dir = (sources.length > 1) || Dir.exists?(sources.first) + outdir = is_dir ? target : File.dirname(target) + # Collect the list of files to copy over + file_map = {} + if is_dir + sources.each do |src| + if Dir.exists? src + Dir["#{src}/**/*"].each do |subfile| + subpath = Pathname.new(subfile).relative_path_from(Pathname.new(src)).to_s + file_map[subfile] = "#{outdir}/#{subpath}" + end + else + file_map[src] = "#{outdir}/#{File.basename(src)}" + end + end + else + file_map[sources.first] = target end - target if File.exists? target - end - - # Add a builder for building a project with Make - env.add_builder :Make do |target, sources, cache, env, vars| - working_dir = File.dirname(sources.first) - cmd = env.expand_varref("${MAKE_CMD}", vars) - unless cache.up_to_date?(target, cmd, sources, env) - Dir.chdir(working_dir) { env.execute("Make #{target}", cmd) } - cache.register_build(target, cmd, sources, env) + # Check the cache and copy if necessary + unless cache.up_to_date?(target, :Install, file_map.keys, env) + puts "INSTALL #{target}" + file_map.each do |k,v| + cache.mkdir_p(File.dirname(v)) + FileUtils.cp(k,v) + end + cache.register_build(target, :Install, file_map.keys, env) end - target if File.exists? target + target if (is_dir ? Dir.exists?(target) : File.exists?(target)) end # CMake Configuration @@ -69,18 +76,6 @@ test_env = base_env.clone do |env| end end -#------------------------------------------------------------------------------ -# Clang Toolchain Targets -#------------------------------------------------------------------------------ -#main_env.CMake('build/llvm/Makefile', -# Dir['source/vendor/llvm-3.4.2/CMakeLists.txt', -# 'source/vendor/llvm-3.4.2/cmake/**/*/']) -#main_env.Make("build/llvm/bin/clang#{windows? ? '.exe':''}", -# ['build/llvm/Makefile'] + Dir['source/vendor/llvm-3.4.2/tools/**/*.*']) - -# Register clang with the environment -#ENV['PATH'] = "build/llvm/bin/#{windows? ? ';':':'}#{ENV['PATH']}" - #------------------------------------------------------------------------------ # Release Build Targets #------------------------------------------------------------------------------ @@ -88,6 +83,7 @@ main_env.Library('build/lib/libcds.a', FileList['modules/libcds/source/**/*.c']) main_env.Library('build/lib/libopts.a', FileList['modules/libopts/source/**/*.c']) main_env.Program('build/bin/sclpl', FileList['source/sclpl/*.c', 'build/lib/libopts.a', 'build/lib/libcds.a']) +main_env.Install('build/include/sclpl.h', 'source/runtime/sclpl.h') #------------------------------------------------------------------------------ # Test Build Targets diff --git a/source/runtime/sclpl.h b/source/runtime/sclpl.h index 1b1524d..ae1699a 100644 --- a/source/runtime/sclpl.h +++ b/source/runtime/sclpl.h @@ -89,9 +89,10 @@ static inline _Value __string(char v[]) { static inline _Value __struct(size_t nflds, ...) { void** obj = (void**)allocate(nflds, sizeof(void*) * nflds); + size_t i; va_list args; va_start(args, nflds); - for(size_t i = 0; i < nflds; i++) + for(i = 0; i < nflds; i++) obj[i] = va_arg(args, void*); va_end(args); return (_Value)obj; diff --git a/source/sclpl/main.c b/source/sclpl/main.c index 2fca00d..95d01ae 100644 --- a/source/sclpl/main.c +++ b/source/sclpl/main.c @@ -295,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(5, str_new("gcc -c -o"), mem_retain(ofname), str_new("-I"), get_inc_dir(), mem_retain(in)); + vec_t* parts = vec_new(5, str_new("cc -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)); diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index e4a4480..3924281 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -47,23 +47,20 @@ describe "cli" do end it "should compile the input file in verbose mode (short flag)" do - pending "Can't find the sclpl header" expect(cli(['-v', '--object', 'spec/src/sample.scl'])).to eq( - "clang -c -o spec/src/sample.o spec/src/sample.c") + "cc -c -o spec/src/sample.o -I ./build/bin/../include/ spec/src/sample.c\n") expect(File.exists? 'spec/src/sample.o').to be(true) FileUtils.rm('spec/src/sample.o') end it "should compile the input file in verbose mode (long flag)" do - pending "Can't find the sclpl header" expect(cli(['--verbose', '--object', 'spec/src/sample.scl'])).to eq( - "clang -c -o spec/src/sample.o spec/src/sample.c") + "cc -c -o spec/src/sample.o -I ./build/bin/../include/ spec/src/sample.c\n") expect(File.exists? 'spec/src/sample.o').to be(true) FileUtils.rm('spec/src/sample.o') end it "should compile the input file" do - pending "Can't find the sclpl header" expect(cli(['--object', 'spec/src/sample.scl'])).to eq("") expect(File.exists? 'spec/src/sample.o').to be(true) FileUtils.rm('spec/src/sample.o') -- 2.52.0