node ('centos7' + ' && !vm1-centos7'){
    try {
	stage('Preparation') {
	    withEnv(['SPIKE_TEST_TRACES_URL=https://github.com/bluewww/spike-instruction-trace-patch',
		     'PATH+WHATEVER=/home/balasr/.local/bin:/home/balasr/.riscv/bin']) {
		checkout scm
		sh 'git submodule update --init --recursive'
		sh "make generate-tests"
		sh "make generate-tests-64"
	    }
	}
	stage('Build (32-bit)') {
	    if (isUnix()) {
		sh "make clean"
		sh "make tb-all"
	    } else {
		echo "unix only"
	    }
	}
	stage('Test (32-bit)') {
	    sh "make -j8 test"
	}

	stage('Build (64-bit)') {
	    if (isUnix()) {
		sh "make clean"
		sh "make c-sv-lib tb-all VLOG_FLAGS+=+define+TRDB_ARCH64"
	    } else {
		echo "unix only"
	    }
	}
	stage('Test (64-bit)') {
	    sh "make -j8 test-64"
	}

    } catch (e) {
	currentBuild.result = "FAILED"
	echo "SENDING E-MAIL"
	notifyFailed()
	throw e
    }
}

def notifyFailed() {
  emailext (
      subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
      body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
	<p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
      recipientProviders: [[$class: 'DevelopersRecipientProvider']]
    )
}
