bin/stmkmf.rb
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 31 Jul 2017 23:03:46 +0100
changeset 134 78f8c3f3390d
child 135 0325651d2b43
permissions -rw-r--r--
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.

#!/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