#!/usr/bin/gmake
export TIMEOUT?=8
ifndef BASH_BUILD_DIR
  $(error Please set the BASH_BUILD_DIR variable to the path of the directory where bash was (successfully!) built.)
endif
ifndef BASH_SOURCE_DIR
  $(error Please set the BASH_SOURCE_DIR variable to the path of the directory containing the source that was built into BASH_BUILD_DIR.)
endif

all: setpgid killpg test

SHELL:=/bin/bash

CC:=gcc
CPPFLAGS:=-I. -I$(BASH_SOURCE_DIR) -I$(BASH_SOURCE_DIR)/lib -I$(BASH_SOURCE_DIR)/builtins -I$(BASH_SOURCE_DIR)/include \
          $(if $(filter $(BASH_SOURCE_DIR),$(BASH_BUILD_DIR)),,-I$(BASH_BUILD_DIR) -I$(BASH_BUILD_DIR)/lib -I$(BASH_BUILD_DIR)/builtins)
OFLAGS?= -O3
GFLAGS?= -g
C_FLAGS?=$(CFLAGS)
LD_FLAGS?=$(LDFLAGS)
# ensure that we compile into position-independant code :
v:=$(filter -fPIC,$(C_FLAGS))
ifeq ($(v),)
C_FLAGS:=$(C_FLAGS) -fPIC $(OFLAGS) $(GFLAGS)
ifdef CFLAGS
$(undefine CFLAGS)
endif
# CFLAGS MUST be a recursively expanded variable!
CFLAGS=$(C_FLAGS)
endif
# ensure that we provide expected shared object name in resulting library shared object file:
v:=$(filter -shared,$(LD_FLAGS))
ifeq ($(v),)
LD_FLAGS:=$(LDFLAGS) -shared -Wl,-soname,$$@
ifdef LDFLAGS
$(undefine LDFLAGS)
endif
# LDFLAGS MUST be a recursively expanded variable!
LDFLAGS=$(LD_FLAGS)
endif

setpgid:setpgid.o

killpg:killpg.o

clean: setpgid.o killpg.o
	rm -vf $^

.PHONY: clean

export BASH_LOADABLES_DIR:=$(if $(BASH_LOADABLES_DIR),$(BASH_LOADABLES_DIR),$(strip $(shell pwd)))

noctty:noctty.o

show_the_bug: invoker.sh job.sh nterm.sh
	unset BASH_LOADABLES_DIR; ./invoker.sh  0<&- 2>&1 | tee 

test:
	bash -c ./invoker.sh 0<&- 2>&1 | tee 

.PHONY: show_the_bug test


