# Edison Design Group C++ Front End
# Makefile for miscellaneous tools used in the build process.

CXXFLAGS =

default:
	@echo "No default target; use make mk_errinfo, etc."

# Tool program that builds the error include files from the .txt files.
mk_errinfo: mk_errinfo.c
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -I../src -o mk_errinfo mk_errinfo.c

# See whether the host compiler supports long long
lldef:
	@rm -f lltest.c lldef
	@echo "-DHAVE_LONG_LONG=0" > lldef
	@echo "long long i = 0x12341234;" > lltest.c
	@echo "int main() { printf(\"%llx\", i); return 0; }" >> lltest.c
	@if $(CXX) lltest.c > /dev/null 2>&1 ; then \
	  if (./a.out | fgrep "12341234" ) > /dev/null ; then \
	    echo "-DHAVE_LONG_LONG=1" > lldef ; \
	  fi \
	fi
	@rm -f lltest.c a.out

# Program that determines some configuration attributes of the host
# system.
dettarg: dettarg.c lldef
	$(CXX) -w -o dettarg `cat lldef` dettarg.c

dettarg.out: dettarg lldef
	./dettarg >> dettarg.out
	@if fgrep "HAVE_LONG_LONG=0" lldef > /dev/null ; then \
	  echo "#define INTEGER_VALUE_REPR_IS_A_HOST_INTEGER 0" >> \
                                                     dettarg.out ; \
	fi

# Run dettarg and append its output to the defines.h.proto file in the src
# directory to create a defines.h file.  If the defines.h file exists
# already, do nothing.
# If the host C compiler does not support "long long", force
# use of simulated integers.
config: dettarg.out
	@if [ -f ../src/defines.h ]; then \
	  : ; \
	else \
	  cat ../src/defines.h.proto dettarg.out > ../src/defines.h; \
	  echo "Default defines.h file created."; \
	fi

clean:
	rm -f dettarg.out mk_errinfo.pcc.c lltest.c a.out

clobber: clean
	rm -f mk_errinfo dettarg lldef
