# $Id$

BOLD= ""
RED= ""
GREEN= ""
ORANGE= ""
BLUE= ""
WHITE= ""

define echo_message
  @echo $(BOLD)
  @echo --------------------------------------------------------------------------------
  @echo $(BOLD)$(1) target $(BLUE)$@$(BOLD)
  @echo $(WHITE)
endef

define remove_existing_dirs
  @PKG_PATH=`ls -t $(SRCSDIR)/$(1) | head -n1` && \
  ROOT=`tar -tf $$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'` && \
  rm -rf $(SRCSDIR)/$$ROOT && \
  rm -rf $(SRCSDIR)/$${ROOT%-*}-build
endef

define remove_existing_dirs2
  @PKG_PATH=\`ls -t $(SRC)/$(1) | head -n1\` && \
  ROOT=`tar -tf $$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'` && \
  rm -rf $(SRC)/$$ROOT && \
  rm -rf $(SRC)/$${ROOT-*}-build
endef

define remove_build_dirs
  @ROOT=`head -n1 $(SRCSDIR)/$(PKG_LST) | sed 's@^./@@;s@/.*@@'` && \
  rm -rf $(SRCSDIR)/$$ROOT && \
  rm -rf $(SRCSDIR)/$(1)-build
endef

define remove_build_dirs2
  @ROOT=`head -n1 $(SRC)/$(PKG_LST) | sed 's@^./@@;s@/.*@@'` && \
  rm -rf $(SRC)/$$ROOT && \
  rm -rf $(SRC)/$(1)-build
endef

define housekeeping
  @touch  $@ && \
  sleep .25 && \
  echo -e "\n\n "$(BOLD)Target $(BLUE)$@ $(BOLD)OK && \
  echo --------------------------------------------------------------------------------$(WHITE)

endef

define get_pkg_root
  @ROOT=`head -n1 $(SRCSDIR)/$(PKG_LST) | sed 's@^./@@;s@/.*@@'` && \
  if [ "$(1)" != "nouser" ]; then \
    echo "export PKGDIR=$(SRCSDIR)/$$ROOT" > envars; \
    chown -R $(LUSER) $(SRCSDIR)/$$ROOT; \
  else \
    echo "export PKGDIR=$(crSRCSDIR)/$$ROOT" > envars; \
  fi;
endef

define get_pkg_root2
  @ROOT=`head -n1 $(SRC)/$(PKG_LST) | sed 's@^./@@;s@/.*@@'` && \
  echo "export PKGDIR=$(SRC)/$$ROOT" > envars
endef

define unpack
  @cd $(SRCSDIR) && \
  tar -xvf `ls -t $(1) | head -n1` > $(PKG_LST)
endef

define unpack2
  @cd $(SRCSDIR) && \
  /tools/bin/tar -xvf `ls -t $(1) | head -n1` > $(PKG_LST)
endef

define unpack3
  @cd $(SRC) && \
  tar -xvf `ls -t $(1) | head -n1` > $(PKG_LST)
endef

define echo_report
  @echo
  @echo $(BOLD) The report file $(BLUE)$(1)$(BOLD) has been created
  @echo
  @echo ${WHITE}Please send the $(BOLD)$(MOUNT_PT)/jhalfs/$(1)$(WHITE)
  @echo file to $(BOLD)manuel@linuxfromscratch.org$(WHITE)
  @echo
  @echo That will help us to keep more accurate SBU and
  @echo disk usage values into the book. Thanks.
endef

define echo_finished
  @echo $(BOLD)
  @echo --------------------------------------------------------------------------------
  @echo $(BOLD) Finished the build of $(BLUE)$(1)$(BOLD)
  @echo --------------------------------------------------------------------------------
  @echo -e \\t\\t$(RED)W A R N I N G$(BOLD)
  @echo --------------------------------------------------------------------------------
  @echo
  @echo To be able to boot your new system you need to follow
  @echo the next steps:$(WHITE)
  @echo
  @echo -e \\t- Enter to the chroot using the command found
  @echo -e \\tin the section -Entering the Chroot Environment-
  @echo -e \\texcept if building CLFS with METHOD=boot.
  @echo
  @echo -e \\t- Set a password for the root user.
  @echo
  @echo -e \\t- Edit or create /etc/fstab, /etc/hosts, /etc/sysconfig/clock,
  @echo -e \\t/etc/sysconfig/console, /etc/sysconfig/network,
  @echo -e \\t/etc/sysconfig//network-devices/ifconfig.eth0/ipv4 and
  @echo -e \\tany other configuration file required to suit your needs.
  @echo
  @echo -e \\t- Exit from the chroot.
  @echo
  @echo -e \\t- Set-up the boot loader, except if building CLFS with METHOD=boot.
  @echo -e \\tYou can set-up the host bootloader or the new boot-loader
  @echo -e \\tinstalled on the new system.
  @echo -e \\tIf the last, you must to mount the virtual filesystems, re-enter
  @echo -e \\tthe chroot and be sure that /dev is populated with the
  @echo -e \\trequired devices before configure the boot-loader. When ready,
  @echo -e \\texit from the chroot and umount the filesystems
  @echo
  @echo If you are an experienced LFS user, several of those steps can be
  @echo skipped or done in a different way. But then, that is something
  @echo that you already know and there is no need to discuss it here.
  @echo $(BOLD)
  @echo --------------------------------------------------------------------------------
  @echo -e \\t\\t$(GREEN)Have a nice day $(ORANGE):-\)$(BOLD)
  @echo --------------------------------------------------------------------------------$(WHITE)
endef

define echo_boot_finished
  @echo $(BOLD)
  @echo --------------------------------------------------------------------------------
  @echo        $(BOLD) Finished building a minimal boot system for $(BLUE)$(1)$(BOLD)
  @echo --------------------------------------------------------------------------------
  @echo -e \\t\\t$(RED)W A R N I N G$(BOLD)
  @echo --------------------------------------------------------------------------------
  @echo
  @echo The build is not complete. Follow the next steps:$(WHITE)
  @echo
  @echo -e \\t- Edit or create $(MOUNT_PT)/etc/fstab
  @echo -e \\t and any other configuration file required to suit your needs.
  @echo $(BOLD)
  @echo $(BOLD)$(YELLOW)
  @echo  1.If it is necessary, transfer the newly created partition to the target machine
  @echo  2.Boot the new partition.
  @echo  3.Once you are logged in issue the following commands
  @echo -e \\t $(BOLD})cd /jhalfs
  @echo -e \\t $(BOLD)make makesys
  @echo  The build process should resume. Follow any instructions that appear.
  @echo --------------------------------------------------------------------------------
  @echo -e \\t\\t$(GREEN)Have a nice day $(ORANGE):-\)$(BOLD)
  @echo --------------------------------------------------------------------------------$(WHITE)
endef