#!/bin/sh
# Create xpce executable

emulator=bin/xpce.base
xpce=bin/xpce

if [ $# = 1 ]; then xpce=$1; fi

for d in library boot include; do
    if [ ! -d pl/$d ]; then (cd pl; ln -s ../../pl/$d .); fi
done

SWIPL=$PWD/pl; export SWIPL
CANONICAL_PATHS=$PWD; export CANONICAL_PATHS

$emulator -o bin/pl.qfl -b pl/boot/init.pl -c pl/boot/load.pl

$emulator -x bin/pl.qfl -f none << _EOS_
retract(library_directory('/usr/local/lib/pl/library')).

['prolog/boot/pce_expand'].
use_module('prolog/boot/pce_pl').
use_module('prolog/lib/pce').

'\$version'(PlVersion),
send(@pce, catch_error_signals, @on),
concat('SWI-Prolog version ', PlVersion, PlId),
send(@prolog, system, PlId).
   
absolute_file_name('', Home),
format('PCE home directory = ~w~n', Home),
send(@pce, home, Home).


assert((library_directory(PceLib) :-
	get(@pce, home, Home),
	concat(Home, '/prolog/lib', PceLib))).

use_module(library(pce_manual)).

'\$make_system_source_files'.
'\$autoload':clear_library_index.

format('Saving to ~w~n', ['$xpce']),
save_program('$xpce',
	[ goal		= 'pce_host:pce_reinitialise'
	]).

get(@pce, home, Home),
concat(Home, '/prolog/lib', PceLib),
make_library_index(PceLib).


halt.
_EOS_

rm -f bin/pl.qfl

