#!/bin/sh
# subdirmk - part of the test suite
#  Copyright 2019 Mark Wooding
#  Copyright 2019 Ian Jackson
# SPDX-License-Identifier: LGPL-2.0-or-later
# There is NO WARRANTY.

set -ex

. tests/build-common

make_copy example

cd tests/example/example

: ----- out of tree build -----

mkdir build
cd build
>>../src/for-test.sd.mk
>>../lib/for-test.mk.in
>>../for-test-final.sd.mk
.././autogen.sh && ../configure
make -j4 all check

: ----- testing rebuild on input change -----

reset_times () {
	cd ..

	find ! -path './build/*' -type f -print0 \
	| xargs -0 \
	touch -hmd 'now -2000 seconds' --

	cd build

	find -type f -print0 \
	| xargs -0 \
	touch -hmd 'now -1000 seconds' --
}

: ----- for-check-1 -----
reset_times
echo 'for-check-1:' >>../src/for-test.sd.mk
make -j4 for-check-1
grep '^for-check-1:' src/Dir.mk || false

: ----- for-check-2 -----
reset_times
echo 'for-check-2:' >>../lib/for-test.mk.in
make -j4 for-check-2
grep '^for-check-2:' lib/for-test.mk || false

: ----- for-check-3 -----
reset_times
echo 'for-check-3:' >>../for-test-final.sd.mk
make -j4 for-check-3
grep '^for-check-3:' Final.mk

echo ok.
