#!/usr/bin/ruby
cwd = File.dirname( __FILE__ )
require "#{cwd}/admin/utils.rb"

 h2 'Determining installation prefix' do
    if ARGV.include? '--prefix'
      n=ARGV.index '--prefix'
      ENV['LFM_PREFIX'] = ARGV[n+1]
    end
    ENV['LFM_PREFIX'] = '/usr/local' if ENV['LFM_PREFIX'].nil?
    if File.exists? ENV['LFM_PREFIX'] and !File.directory? ENV['LFM_PREFIX']
      abort "Installation prefix exists but isn't a directory: "+ENV['LFM_PREFIX']
    end
    puts "Will install to: "+ENV['LFM_PREFIX']
  end

  h2 "Configuring qmake..." do
    args=Array.new
    if ARGV.include? '--release'
      args << '-config release'
    else
      args << '-config debug'
    end
    if ARGV.include? '--no-strip'
      args << '"CONFIG += nostrip"'
    end
    ENV['LFM_QMAKE'] = "#{$qmake} #{args.join(' ')}"
  end

  h2 "Generating Makefile..." do
    hs = Array.new
    hs << 'global.h'
    hs << 'core/UrlBuilder.h' << 'core/XmlQuery.h' << 'core/misc.h'
    hs << 'fingerprint/Fingerprint.h' << 'fingerprint/FingerprintableSource.h'
    hs << 'radio/RadioStation.h' << 'radio/RadioTuner.h'
    hs << 'scrobble/Audioscrobbler.h' << 'scrobble/ScrobblePoint.h' << 'scrobble/ScrobbleCache.h'
    hs << 'types/Tasteometer.h' << 'types/AbstractType.h' << 'types/Track.h' << 'types/Mbid.h' << 'types/Artist.h' << 'types/Album.h' << 'types/FingerprintId.h' << 'types/Playlist.h' << 'types/Tag.h' << 'types/User.h' << 'types/Xspf.h'
    hs << 'ws/ws.h' << 'ws/InternetConnectionMonitor.h' << 'ws/NetworkAccessManager.h'
    uname = `uname`
	ENV['LFM_VERSION']="0.4.0" 
	File.new("#{cwd}/Makefile", 'w').write `ruby admin/Makefile.rb #{hs.join(' ')}`
  end

  puts
  puts "Good, your configure is finished! Now type: make"
  
