# Copyright (c) 2016 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# Auto-load module for 'tmake' build system integration

use init

autosetup_add_init_type tmake "Tcl-based tmake build system" {
	autosetup_check_create auto.def \
{# Initial auto.def created by 'autosetup --init=tmake'
# vim:set syntax=tcl:

use cc cc-lib cc-db cc-shared
use tmake

# Add any user options here
# Really want a --configure that takes over the rest of the command line
options {
}

cc-check-tools ar ranlib

set objdir [get-env BUILDDIR objdir]

make-config-header $objdir/include/autoconf.h
make-tmake-settings $objdir/settings.conf {[A-Z]*} *dir lib_*
}

	autosetup_check_create project.spec \
{# Initial project.spec created by 'autosetup --init=tmake'

tmake-require-version 0.7.3

# vim:set syntax=tcl:
define? DESTDIR _install

# XXX If configure creates additional/different files than include/autoconf.h
#     that should be reflected here
Autosetup include/autoconf.h

# e.g. for autoconf.h
IncludePaths include

ifconfig !CONFIGURED {
	# Not configured, so don't process subdirs
	AutoSubDirs off
	# And don't process this file any further
	ifconfig false
}
}

	set configure [readfile configure]
	# XXX Do we need also need to support a system install of tmake?
	if {[string first {#@TMAKEUPDATED@} $configure] < 0} {
		if {[regsub {#@@INITCHECK@@#} $configure \
			{test -z "$TMAKE" -a -x "$dir/tmake" \&\& exec "$dir/tmake" --force --configure "$@"; #@TMAKEUPDATED@} configure]} {
			writefile configure $configure\n
			exec chmod +x configure
			puts "Updated configure to invoke local tmake."
			if {![file exec autosetup/tmake]} {
				puts "Warning: autosetup/tmake is missing."
				puts "   Install it with: tmake --install=autosetup"
			}
		} else {
			puts "Warning: configure isn't created by a recent autosetup, not updating."
		}
	} else {
		puts "I see configure for tmake already exists."
	}
	if {![file exists build.spec]} {
		puts "Note: I don't see build.spec. Try running: tmake --genie"
	}
}
