######
#
# HX-2013-03:
# for compiling a distribution of ATS-Postiats
# KO-2014-04-09:
# removing [-T] from [install] as the option is
# not supported on MacOS
# IU-2014-04-30:
# removing the space between -m and the following mode
# as it is not supported on freeBSD
#
######

CPF=cp -f
CPR=cp -R
MVF=mv -f
RMF=rm -f
RMRF=rm -rf

######

MAKE=make
MAKEJ4=make -j4

######
#
all:: config.mk
#
all:: bin2_patsopt
all:: lib2_libatsopt
#
all:: bin_patscc
all:: bin_myatscc
#
all:: ccomp/atslib/lib/libatslib.a
#
######

configure: ; /bin/bash autogen.sh

######
#
# HX: this seems to be working
#
# config.mk : configure ; ./configure
#
#######
#
config.mk: \
configure ; \
@echo "Please execute './configure'." ; exit 1 ;
#
######
#
C3NSTRINTKND=gmpknd
#
#C3NSTRINTKND=intknd
#
######
#
src_patsopt: ; \
$(MAKE) C3NSTRINTKND=$(C3NSTRINTKND) -j4 -C src patsopt
#
bin_patsopt: src_patsopt ; $(CPF) src/patsopt bin/patsopt
#
######
#
CCOMP=gcc
#
GCFLAG=
#GCFLAG=-D_ATS_NGC
#GCFLAG=-D_ATS_GCBDW
#GCFLAG=-D_ATS_GCATS
#
CFLAGS=
LDFLAGS=
#
######
#
src2_patsopt: ; \
$(MAKEJ4) -C src/CBOOT patsopt \
CCOMP=$(CCOMP) GCFLAG=$(GCFLAG) LDFLAGS=$(LDFLAGS) 
#
bin2_patsopt: src2_patsopt ; $(CPF) src/CBOOT/patsopt bin/patsopt
#
######

utl_atscc: ; \
$(MAKE) -C utils/atscc copy build clean
bin_patscc: utl_atscc ; \
$(MVF) utils/atscc/BUILD/patscc bin/patscc

######

utl_myatscc: ; \
$(MAKE) -C utils/myatscc copy build clean
bin_myatscc: utl_myatscc ; \
$(MVF) utils/myatscc/BUILD/myatscc bin/myatscc

######
#
src2_libatsopt: ; \
$(MAKE) -C src/CBOOT CCOMP=$(CCOMP) libatsopt
lib2_libatsopt: src2_libatsopt ; \
$(CPF) src/CBOOT/libatsopt.a ccomp/atslib/lib/.
#
######

ccomp/atslib/lib/libatslib.a: ; $(MAKE) -C ccomp/atslib atslib

######

-include config.mk

######
#
# This variable is to be set externally
#
DESTDIR :=
#
######

export PATSHOME
export PATSLIBHOME

######

bindir2 := $(DESTDIR)$(bindir)
PATSLIBHOME2 := $(DESTDIR)$(PATSLIBHOME)

######
#
# HX-2011-06-01:
# This part was originally written by Georg Bauhaus
# (bauhausATarcorDOTde): It addresses the issue that
# the [-D] option is not available for $(INSTALL) on MacOSX.
#
.PHONY: install_dirs
.PHONY: install_files
#
install: install_files

install_files: \
  install_files_00 \
  install_files_10 \
  install_files_11 \
  install_files_20 \
  install_files_30 \
  install_files_31 \
  install_files_40 \
  install_files_50 \

install_dirs: ; \
  cd "$(abs_top_srcdir)" && \
  $(MKDIR_P) $(PATSLIBHOME2)/bin && \
  if [ ! -d $(bindir2) ] ; then $(MKDIR_P) $(bindir2) ; fi && \
  for x in share ccomp prelude libats contrib ; do \
    find "$$x" -type d -exec $(MKDIR_P) $(PATSLIBHOME2)/\{} \; -print; \
  done

install_files_00: install_dirs ; \
  for x in share ccomp/runtime prelude libats contrib ; do \
    cd "$(abs_top_srcdir)" && \
    $(INSTALL) -d $(PATSLIBHOME2)/"$$x" && \
    find "$$x" -type l -exec $(CPR) \{} $(PATSLIBHOME2)/\{} \; -print && \
    find "$$x" -type f -exec $(INSTALL) -m644 \{} $(PATSLIBHOME2)/\{} \; -print; \
  done

install_files_10: bin/patscc ; \
  $(INSTALL) -m755 $< $(PATSLIBHOME2)/bin/patscc && echo $<
install_files_11: bin/myatscc ; \
  $(INSTALL) -m755 $< $(PATSLIBHOME2)/bin/myatscc && echo $<
install_files_20: bin/patsopt ; \
  $(INSTALL) -m755 $< $(PATSLIBHOME2)/bin/patsopt && echo $<
install_files_30: bin/patscc_env.sh ; \
  $(INSTALL) -m755 $< $(bindir2)/patscc && echo $<
install_files_31: bin/myatscc_env.sh ; \
  $(INSTALL) -m755 $< $(bindir2)/myatscc && echo $<
install_files_40: bin/patsopt_env.sh ; \
  $(INSTALL) -m755 $< $(bindir2)/patsopt && echo $<

install_files_50: ; \
  for x in \
    ccomp/atslib/lib/libatslib.a \
    ccomp/atslib/lib64/libatslib.a ; \
  do \
    if [ -e "$$x" ] ; then \
      $(INSTALL) -m755 "$$x" $(PATSLIBHOME2)/"$$x" && echo "$$x"; \
    fi; \
  done

######
#
# HX-2017-11-11:
# Please execute the following
# command-lines before reinstall
#
# make -C ccomp/atslib clean
# make -C ccomp/atslib atslib
#
reinstall_atslib: install_files_50  
#
######
#
uninstall:: uninstall_bin
uninstall:: uninstall_home
#
uninstall_bin:: ; $(RMF) $(bindir2)/patscc
uninstall_bin:: ; $(RMF) $(bindir2)/myatscc
uninstall_bin:: ; $(RMF) $(bindir2)/patsopt
uninstall_home:: ; $(RMRF) $(PATSLIBHOME2)
#
######

clean::
cleanall:: clean

######

clean:: ; $(RMF) ccomp/atslib/output/*.o
clean:: ; $(MAKE) -C src/CBOOT -f Makefile clean

######

cleanall:: ; $(RMF) stamp-h1
cleanall:: ; $(RMF) config.mk
cleanall:: ; $(RMF) config.log
cleanall:: ; $(RMF) config.status
cleanall:: ; $(RMRF) autom4te.cache

cleanall:: ; $(RMF) bin/patscc
cleanall:: ; $(RMF) bin/myatscc
cleanall:: ; $(RMF) bin/patsopt
cleanall:: ; $(RMF) bin/patscc_env.sh
cleanall:: ; $(RMF) bin/myatscc_env.sh
cleanall:: ; $(RMF) bin/patsopt_env.sh

cleanall:: ; $(RMF) ccomp/atslib/lib/*
cleanall:: ; $(RMF) ccomp/atslib/lib64/*
cleanall:: ; $(RMF) ccomp/atslib/output/*

cleanall:: ; $(MAKE) -C src -f Makefile cleanall
cleanall:: ; $(MAKE) -C src/CBOOT -f Makefile cleanall
cleanall:: ; $(MAKE) -C utils/atscc -f Makefile cleanall

######

distclean:: cleanall

######

###### end of [Makefile_dist] ######
