#!/bin/sh
#  file kernel/pascal/remake: compile rules for the Pascal interface
#-----------------------------------------------------------------------+
#  Copyright 2005, Michel Quercia (michel.quercia@prepas.org)           |
#                                                                       |
#  This file is part of Numerix. Numerix is free software; you can      |
#  redistribute it and/or modify it under the terms of the GNU Lesser   |
#  General Public License as published by the Free Software Foundation; |
#  either version 2.1 of the License, or (at your option) any later     |
#  version.                                                             |
#                                                                       |
#  The Numerix Library is distributed in the hope that it will be       |
#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty  |
#  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  |
#  Lesser General Public License for more details.                      |
#                                                                       |
#  You should have received a copy of the GNU Lesser General Public     |
#  License along with the GNU MP Library; see the file COPYING. If not, |
#  write to the Free Software Foundation, Inc., 59 Temple Place -       |
#  Suite 330, Boston, MA 02111-1307, USA.                               |
#-----------------------------------------------------------------------+
#                                                                       |
#              Rgles de construction de l'interface Pascal             |
#                                                                       |
#-----------------------------------------------------------------------+

# m_list = liste des modes (c/d/s)
m_list=
if test "$USE_CLONG" = "1"; then m_list="${m_list} c"; fi
if test "$USE_DLONG" = "1"; then m_list="${m_list} d"; fi
if test "$USE_SLONG" = "1"; then m_list="${m_list} s"; fi

# On y va
cat <<EOF
# File kernel/pascal/makefile: compile rules for the Pascal interface
EOF
sed -n -e '3,/^$/p' $0 
cat <<EOF
# This file was generated by the kernel/pascal/remake script
# switches:
#   USE_CLONG=$USE_CLONG
#   USE_DLONG=$USE_DLONG
#   USE_SLONG=$USE_SLONG
#   MAKE_PASCAL_LIB=$MAKE_PASCAL_LIB
EOF

if test "$MAKE_PASCAL_LIB" = "0"; then exit; fi

cat <<EOF

#-------------------- unit compile rules
EOF
for m in $m_list; do cat <<EOF
kernel/pascal/o/${m}long.p: kernel/pascal/p/xlong.p
	sed -e "s/xx(\([^)]*\))/${m}x_\1/g" -e "s/_name_/${m}long/g" kernel/pascal/p/xlong.p >\$@
kernel/pascal/o/${m}long.ppu: kernel/pascal/o/${m}long.p
	\$(FPC) kernel/pascal/o/${m}long.p
EOF
done
echo

echo -n "lib_pascal = "
for m in $m_list; do echo -n "\\
  kernel/pascal/o/${m}long.ppu "
done
echo

echo -n "lib_pascal_o = "
for m in $m_list; do echo -n "\\
  kernel/pascal/o/${m}long.o "
done
echo

echo -n "lib_pascal_p = "
for m in $m_list; do echo -n "\\
  kernel/pascal/o/${m}long.p "
done
echo

cat <<EOF
#-------------------- installation
.PHONY: install_pascal
install_pascal: \$(lib_pascal) \$(lib_pascal_p)
	mkdir -p \$(PASCAL_INSTALL_LIB) \$(PASCAL_INSTALL_INCLUDE)
	cp -p \$(lib_pascal) \$(lib_pascal_o) \$(PASCAL_INSTALL_LIB)
	cp -p \$(lib_pascal_p) \$(PASCAL_INSTALL_INCLUDE)
EOF

exemples="pi simple shanks"
cat <<EOF

#-------------------- examples
EOF
echo -n "ex_pascal_obj = "
for m in $m_list; do for e in $exemples; do echo -n "\\
  exemples/pascal/$e-$m "
done; done
echo
echo

for m in $m_list; do for e in $exemples; do cat <<EOF
exemples/pascal/$e-$m: exemples/pascal/$e.p \$(lib_c) \$(lib_pascal)
	sed -e "s/_name_/${m}long/g" exemples/pascal/$e.p >exemples/pascal/$e-$m.p
	\$(FPC) exemples/pascal/$e-$m.p -Fukernel/pascal/o -Flkernel/c/o
	@rm exemples/pascal/$e-$m.p exemples/pascal/$e-$m.o
EOF
done; done

cat <<EOF

.PHONY: test_pascal clean_pascal
test_pascal: \$(ex_pascal_obj)
	@echo "-------------------- Testing the Pascal interface"
	for i in $exemples; do for j in $m_list; do \\
	    exemples/pascal/\$\$i-\$\$j -test; \\
	done; done

clean_pascal:
	rm -f kernel/pascal/o/* exemples/pascal/*-c exemples/pascal/*-d exemples/pascal/*-s

#-------------------- done
lib:          \$(lib_pascal)
install:      install_pascal
exemples:     \$(ex_pascal_obj)
test:         test_pascal
clean:        clean_pascal
EOF

