package rosa

var _perl = H("perl")

// MakeMakerHelper builds projects using the included MakeMaker script.
type MakeMakerHelper struct {
	// Whether to skip the check target.
	SkipCheck bool
}

// extra returns perl.
func (*MakeMakerHelper) extra() P { return P{_perl, _make} }

// wantsChmod returns true.
func (*MakeMakerHelper) wantsChmod() bool { return true }

// wantsWrite returns true.
func (*MakeMakerHelper) wantsWrite() bool { return true }

// scriptEarly is a noop.
func (*MakeMakerHelper) scriptEarly() string { return "" }

// wantsDir requests the source directory.
func (*MakeMakerHelper) wantsDir() (string, bool) { return "", false }

// script generates Makefile.PL-based build and test commands.
func (attr *MakeMakerHelper) script(t Toolchain, _ string) string {
	if attr == nil {
		attr = new(MakeMakerHelper)
	}

	script := `perl Makefile.PL \
	PREFIX=/system
make \
	` + jobsFlagE + ` \
	` + loadFlagE
	if !attr.SkipCheck && t.opts&OptSkipCheck == 0 {
		script += `
make \
	` + jobsFlagE + ` \
	` + loadFlagE + ` \
	test
`
	}
	script += "make DESTDIR=/work install\n"
	return script
}
