rakelib/compile.rake
changeset 138 2507036dfee8
parent 137 e665031cade7
parent 136 29bd0a3c4a31
child 168 37f3dd667f71
--- a/rakelib/compile.rake	Fri Aug 11 09:23:06 2017 +0200
+++ b/rakelib/compile.rake	Fri Aug 11 09:59:28 2017 +0200
@@ -3,8 +3,8 @@
 
 
 STX_TOP_DIR = BUILD_DIR / 'stx'
-STX_CONF_DIR = STX_TOP_DIR / 'configurations'
-STX_RULES_DIR = STX_TOP_DIR / 'rules'
+STX_CONF_DIR = BUILD_DIR
+STX_RULES_DIR = BUILD_DIR / '..' / 'makelib'
 if win32?
   STC = STX_TOP_DIR / 'stc' / 'stc.exe'
   LIBRUN = STX_TOP_DIR / 'librun' / 'objmingw' / 'librun.dll'
@@ -26,8 +26,8 @@
 end
 
 def rm_rf_all_in_except(directory, exceptions = [])
-  if File.directory? directory
-    Dir.foreach(directory) {|each| rm_rf File.join(directory, each) if each != '.' and each != '..' and !exceptions.include?(each)}
+  if File.directory?(directory)
+    Dir.foreach(directory) {|each| rm_rf File.join(directory, each) if (each != '.' and each != '..' and !exceptions.include?(each))}
   else
     rm_f directory
   end
@@ -79,7 +79,7 @@
         librun.a
         symlist.c
         Make.proto
-        Makefile
+        makefile
     )
     LIBRUN_BINARY_FILES2 = []
 
@@ -197,93 +197,31 @@
   task :application => :'setup:dependencies'
 
 
-  case
-    when unix?
-      task :config => [STX_CONF_DIR / 'COMMON' / 'defines',
-                       STX_CONF_DIR / 'vendorConf',
-                       STX_CONF_DIR / 'myConf',
-                       STX_RULES_DIR / 'stdRules']
-
-
-      task STX_RULES_DIR / 'stdRules' do
-        # Sigh, yet another hack here. For a funny reason, target newobj depends on .o files
-        # and not on target objs. The problem is that some of the .o may need some third party
-        # library being built before (for example, stx:libview2 requires libjpeg-9 being built
-        # before!). To workaround this, we have to patch the rule so it depends on target `objs`
-        # which depends on `pre_objs` that builds libraries. Triple sigh here. I should fork rules
-        # directory...
-        sed('newobj: $(LIBNAME)Init.c $(LINKOBJS)', 'newobj: $(LIBNAME)Init.c objs $(LINKOBJS)', STX_RULES_DIR / 'stdRules', true)
-
-        # Yet another hack to pass absolute filenames when compiling. This should help Jenkins's
-        # Warning plugin correctly locate files mentioned in compile log - it cannot deal with relative paths
-        # (as it cannot track compilation process's working directory, naturally)
-        sed(' $(STFILE)', ' $(PWD)/$(STFILE)', STX_RULES_DIR / 'stdRules', true)
-      end
-
-      directory STX_CONF_DIR do |t|
-        ; mkdir_p t.name;
-      end
-
-      directory STX_CONF_DIR / 'COMMON' do |t|
-        ; mkdir_p t.name;
-      end
+  task :config => [ STX_CONF_DIR / 'stx-config.make' ]
 
-      directory STX_CONF_DIR / 'COMMON' / 'defines' => STX_CONF_DIR / 'COMMON' do |t|
-        File.open(t.name, 'w') do |f|
-          f.puts <<-CONTENTS
-          # Do not edit! Automatically generated by rake (rakelib/#{__FILE__})
-          # 
-          # Nothing here, all "common" definitions are included in config file
-          # (`config-<OS>-<ARCH>.make`)
-          CONTENTS
-        end
-      end
-
-      file STX_CONF_DIR / 'vendorConf' => STX_CONF_DIR do |t|
-        makelib_dir = Pathname.new(File.expand_path('makelib')).relative_path_from(Pathname.new(BUILD_DIR / 'stx'))
-        os = nil
-        linux? ? (os = 'linux') : (raise Exception.new('Unsupported operating system'))
+  directory STX_CONF_DIR do 
+    mkdir_p STX_CONF_DIR
+  end
+    
+  file STX_CONF_DIR / 'stx-config.make' => STX_CONF_DIR  do
+    makelib_dir = Pathname.new(File.expand_path('makelib')).relative_path_from(Pathname.new(BUILD_DIR / 'stx' ))
+    os = nil
+    case 
+    when linux? 
+      os = 'linux'
+    when win32?
+      os = 'mingw32'
+    else
+      raise Exception.new('Unssuported operating system')
+    end
 
-        File.open(t.name 'w') do |f|
-          f.puts <<-CONTENTS
-          # Do not edit! Automatically generated by rake (rakelib/#{__FILE__})
-          #
-          TOP ?= #{BUILD_DIR / 'stx'}
-          MAKELIB_DIR ?= $(TOP)/#{makelib_dir}
-          include $(MAKELIB_DIR)/config-#{os}-#{ARCH}.make          
-          CONTENTS
-        end
-      end
-
-      file STX_CONF_DIR / 'myConf' => STX_CONF_DIR do |t|
-        File.open(t.name, 'w') do |f|
-          f.puts <<-CONTENTS
-          # Local modifications / additions specific to this very build, if needed. 
-          
-#
-          CONTENTS
-        end
-      end
-    when win32?
-      task :'config' => [STX_RULES_DIR / 'stdRules_bc_mingwhack.txt']
-
-      file STX_RULES_DIR / 'stdRules_bc_mingwhack.txt' do
-        File.open(STX_RULES_DIR / 'stdRules_bc', 'a') do |f|
-          f.puts '!if defined(USEMINGW32) || defined(USEMINGW64)'
-          f.puts "CFLAGS=#{GCC_CFLAGS} $(CFLAGS1) $(CFLAGS2) $(LOCALINCLUDES) $(CLOCAL_INCL) $(CFLAGS_LOCAL)"
-          f.puts '!endif'
-        end
-        File.open(STX_RULES_DIR / 'stdRules_bc_mingwhack.txt', 'a') {|f| f.puts 'stdRules_bc CFLAGS already fixed'}
-      end
-    else
-      error "Unsupported platform: #{Config::CONFIG['host_os']}"
-  end
+    File.open(STX_CONF_DIR / 'stx-config.make', 'w') do | f |
+      f.puts "BUILD_TARGET ?= #{os}-#{ARCH}"
+    end
+  end 
 
   rule 'makefile' do |t|
-    (rm (File.dirname(t.name) / 'GNUmakefile')) if File.exist?(File.dirname(t.name) / 'GNUmakefile')
-    chdir File.dirname(t.name) do
-      ; sh "'#{STX_TOP_DIR / 'rules' / 'stmkmf'}'";
-    end
+    chdir File.dirname(t.name) do; sh "'#{STX_TOP_DIR / 'rules' / 'stmkmf'}'"; end
   end
 
   task :stc do
@@ -300,7 +238,7 @@
       end
     end
 
-    (cp STX_TOP_DIR / 'stc' / 'stx-config.h', STX_TOP_DIR / 'include' / 'stx-config.h') unless File.exist? STX_TOP_DIR / 'include' / 'stx-config.h'
+    (cp STX_TOP_DIR / 'stc' / 'stx-config.h', STX_TOP_DIR / 'include' / 'stx-config.h') unless File.exist?(STX_TOP_DIR / 'include' / 'stx-config.h')
 
     unless File.exist? STC
       cleanup_stc
@@ -314,7 +252,7 @@
       begin
         begin
           if win32_wine?
-            (mkdir 'libffi' / 'build_win32' / 'objbc') unless File.exist? 'libffi' / 'build_win32' / 'objbc'
+            (mkdir 'libffi' / 'build_win32' / 'objbc') unless File.exist?('libffi' / 'build_win32' / 'objbc')
           end
           # A workaround for Windows 10 & ancient Borland make which 
           # tend to crash there when trying to recompile already compiled
@@ -349,26 +287,51 @@
     task 'libraries' => [vogl_dir / 'src' / 'libvogl.a']
 
     file vogl_dir / 'src' / 'libvogl.a' => [vogl_dir / 'makefile'] do
-      chdir STX_TOP_DIR / 'support' / 'VGL' / 'vogl' do
-        ; make;
-      end
+      chdir STX_TOP_DIR / 'support' / 'VGL' / 'vogl' do; make; end
     end
   end
 end
 
 
+task "stx:librun:symbols"
+
 #
 # Various compilation hacks here and there (sigh)
 # 
+desc "Update the VM symbol database"
+task 'stx:librun:symbols' do | task |    
+  symbols_stc = BUILD_DIR / 'stx' / 'include' / 'symbols.stc'
+  if unix?
+    # UNIX VMs have the symbol database built into the binary as
+    # static data so we need to recompile the VM
+    stx_librun = project.package('stx:librun')
+    stx_librun_dll = BUILD_DIR / stx_librun.directory() / OBJ_DIR / stx_librun.dll_name()
+
+    if not uptodate?(stx_librun_dll, [ symbols_stc ]) then
+      Rake::Task["stx:librun"].reenable()
+      Rake::Task["stx:librun"].invoke()
+    end
+  elsif win32? 
+    # Windows VM reads the symbol database from a file `symbols.stc` located
+    # alongside the program executable so we need to copy that file
+    app = project.application
+    symbols_stc_in_app_directory = BUILD_DIR / app.directory() / 'symbols.stc'
+    if not uptodate?(symbols_stc_in_app_directory, [ symbols_stc ]) then
+      cp symbols_stc, symbols_stc_in_app_directory
+    end
+  end
+  task.reenable()
+end
 
 if unix?
   # A hack for Debian (and possibly other Linux distros) that does not ship
   # 32bit libodbc.a / libodbcinst.a. Link directly against .so
-  task :'stx:libdb/libodbc:pre' do
-    sed('-lodbc -lodbcinst', '-l:libodbc.so.2 -l:libodbcinst.so.2', BUILD_DIR / 'stx' / 'libdb' / 'libodbc' / 'Make.proto', true)
-  end
+  task :'stx:libdb/libodbc:pre' do     
+	  sed('-lodbc -lodbcinst' , '-l:libodbc.so.2 -l:libodbcinst.so.2', BUILD_DIR / 'stx' / 'libdb' / 'libodbc' / 'Make.proto', true)
+  end  
 end
 
 
 
 
+