# fss-0005 iki-0002
#
# This is designed for compiling bzip2-1.0.8.
#
# To use this do the following:
#   1) Download and extract bzip2-1.0.8.
#   2) Change into the extracted bzip2-1.0.8 directory.
#   3) Create the directory path "data/build/" within this bzip2-1.0.8 directory.
#   4) Copy the files fakefile-bzip2, settings-bzip2, and settings-bzip2recover) into the created directory path "data/build/".
#   5) Use the featureless make build operation to make, such as: "fake".

settings:
  environment PATH LD_LIBRARY_PATH
  environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH

main:
  operate bzip2
  operate bzip2recover
  operate scripts
  operate tests

bzip2:
  print
  print Building settings-bzip2.
  build settings-bzip2

bzip2recover:
  print
  print Building settings-bzip2recover.
  build settings-bzip2recover

scripts:
  print
  print Copying bzip2 scripts.
  touch directory build build/programs build/programs/scripts
  copy bzdiff bzgrep build/programs/scripts

tests:
  print
  print Performing tests.

  # Conditionally setup the build_path.
  parameter build_path build/

  if parameter build:value
    parameter build_path parameter:"build:value"

  # Conditionally setup the LD_LIBRARY_PATH to include the just compiled libraries.
  if define LD_LIBRARY_PATH
  and parameter work:value
    define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:parameter:"work:value"libraries/shared:define:"LD_LIBRARY_PATH"'

  else
  if define LD_LIBRARY_PATH
    define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:define:"LD_LIBRARY_PATH"'

  else
  if parameter work:value
    define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:parameter:"work:value"libraries/shared'

  # Setup the PATH to use the just compiled programs.
  define PATH parameter:"build_path"programs/static:parameter:"build_path"programs/shared:define:"PATH"

  # Execute the tests (redirects are not currently supported, so execute using bash).
  run cat words1
  run bash -c 'bzip2 -1  < sample1.ref > sample1.rb2'
  run bash -c 'bzip2 -2  < sample2.ref > sample2.rb2'
  run bash -c 'bzip2 -3  < sample3.ref > sample3.rb2'
  run bash -c 'bzip2 -d  < sample1.bz2 > sample1.tst'
  run bash -c 'bzip2 -d  < sample2.bz2 > sample2.tst'
  run bash -c 'bzip2 -ds < sample3.bz2 > sample3.tst'
  run cmp sample1.bz2 sample1.rb2
  run cmp sample2.bz2 sample2.rb2
  run cmp sample3.bz2 sample3.rb2
  run cmp sample1.tst sample1.ref
  run cmp sample2.tst sample2.ref
  run cmp sample3.tst sample3.ref
  run cat words3
