Makefiles: Added our own implementation of `stmkmf`
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 31 Jul 2017 23:03:46 +0100
changeset 134 78f8c3f3390d
parent 133 8229af6e81df
child 135 0325651d2b43
Makefiles: Added our own implementation of `stmkmf` This is a preparation to fork and clean Smalltalk/X makefiles. Since package makefile is generated by stmkmf, we need to use our own in order to include our own makefiles.
bin/stmkmf.rb
rakelib/setup.rake
specs/baseline.rbspec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/stmkmf.rb	Mon Jul 31 23:03:46 2017 +0100
@@ -0,0 +1,86 @@
+#!/usr/bin/env ruby
+DOCUMENTATION = <<DOCEND
+Generates a `Makefile` for compiling a Smalltalk/X class library. 
+
+DOCEND
+
+#
+# Generates a makefile for a Smalltalk/X package. Return status code
+# (0 means success)
+def stmkmf(cwd: '.', out: 'makefile', top: nil)   
+  if not File.exist? cwd then
+    STDERR.puts "error: no such directory: #{cwd}"
+    return 1
+  end
+  if not File.directory? cwd then
+    STDERR.puts "error: not a directory: #{cwd}"
+    return 2
+  end
+  if not File.exist? File.join(cwd, 'Make.proto') then
+    STDERR.puts "error: could not find Make.proto: #{File.join(cwd, 'Make.proto')}"    
+    return 3
+  end
+  if top.nil? then 
+    m = /^TOP=(.*)$/.match(File.read(File.join(cwd, 'Make.proto')))
+    if m.nil? then
+      STDERR.puts "error: could not ectract TOP from Make.proto (missing TOP=.. definition?)"    
+      return 4
+    end
+    top = m[1]
+  end
+  if not File.directory? top then
+    STDERR.puts "error: TOP not a cwd: #{top}"    
+    return 5
+  end
+  makelib = File.join(cwd, top, '..', '..' , 'makelib')
+  if not File.exist? makelib then
+    STDERR.puts "error: could not find out include cwd: #{makelib}"    
+    return 6
+  end
+  File.open(File.join(cwd, out), "w") do | f |
+    f.puts <<-CONTENTS
+#  
+# Do not edit! Automatically generated by stmkmf.
+# 
+include #{top}/rules/stdHeader
+include #{top}/configurations/COMMON/defines
+include #{top}/configurations/vendorConf
+include #{top}/configurations/myConf
+include #{top}/rules/stdHeader2
+
+include Make.spec
+include Make.proto
+
+include #{top}/rules/stdRules
+CONTENTS
+  end
+  return 0
+end
+
+if __FILE__ == $0
+  require 'optparse'
+
+  cwd = '.'
+  out = 'makefile'
+
+
+  optparser = OptionParser.new do | optparser |
+    optparser.banner = "Usage: stmkmf.rb [options] [stx-top-directory]"
+    optparser.on('-C', '--cd DIRECTORY', "Generates makefile in DIRECTORY. Optional, default is current working cwd.") do | value |
+      cwd = value
+    end
+    optparser.on('-o', '--out FILE', "Write result to FILE. Optional, default is 'makefile'") do | value |
+      out = value
+    end    
+    optparser.on(nil, '--help', "Prints this message") do
+      puts DOCUMENTATION
+      puts optparser.help()
+      exit 0
+    end
+  end
+  optparser.parse!
+  top = ARGV[0] || nil
+
+
+  exit stmkmf(cwd: cwd, out: out, top: top)
+end
--- a/rakelib/setup.rake	Wed Aug 02 20:21:39 2017 +0100
+++ b/rakelib/setup.rake	Mon Jul 31 23:03:46 2017 +0100
@@ -185,7 +185,7 @@
       task pkg.name => [ BUILD_DIR / pkg.directory / 'makefile' ]
       file BUILD_DIR / pkg.directory / 'makefile' do
         chdir BUILD_DIR / pkg.directory do
-          if not system "sh #{ pkg.top() / 'stx' / 'rules' / 'stmkmf'}"
+          if not system "#{ pkg.top() / 'stx' / 'rules' / 'stmkmf'}"
             raise Exception.new("Canmot run stmkmf for #{pkg.directory}")
           end
         end
--- a/specs/baseline.rbspec	Wed Aug 02 20:21:39 2017 +0100
+++ b/specs/baseline.rbspec	Mon Jul 31 23:03:46 2017 +0100
@@ -50,6 +50,14 @@
 
     file BUILD_DIR / 'stx' / 'rules'  => BUILD_DIR do | t |
       checkout :'exept:public', 'stx/rules'
+      if unix? then        
+        chdir BUILD_DIR / 'stx' / 'rules'  do
+          rm_f 'stmkmf'
+          # Argh, cannot use ln_s as it cannot make symlinks with relative
+          # paths. Sigh, 
+          sh "ln -s \'../../../bin/stmkmf.rb\' stmkmf"
+        end
+      end
       # the clear is here to avoid multiple checkouts
       t.clear()
     end