changeset 15419:60090630cb76

generate declarations for all built-in DEFUN functions * mkbuiltins: New options, --source and --header. With --header, generate declarations for DEFUN functions. * libinterp/Makefile.am (builtin-defun-decls.h): New rule. (builtins.cc): Use --source option for mkbuiltins. (BUILT_SOURCES, BUILT_NODISTFILES, octinclude_HEADERS, nodist_liboctinterp_la_SOURCES): Add builtin-defun-decls.h to the list. * builtins.h: Include builtin-defun-decls.h.
author John W. Eaton <jwe@octave.org>
date Wed, 19 Sep 2012 13:24:32 -0400
parents dd371063e414
children 2afbe4295682
files libinterp/Makefile.am libinterp/builtins.h libinterp/mkbuiltins
diffstat 3 files changed, 80 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/Makefile.am
+++ b/libinterp/Makefile.am
@@ -53,6 +53,7 @@
   interpfcn/defaults.h \
   interpfcn/graphics-props.cc \
   interpfcn/graphics.h \
+  builtin-defun-decls.h \
   operators/ops.cc \
   parse-tree/lex.cc \
   parse-tree/oct-gperf.h \
@@ -73,6 +74,7 @@
   interp-core/oct-errno.cc \
   interpfcn/defaults.h \
   interpfcn/graphics.h \
+  builtin-defun-decls.h \
   operators/ops.cc \
   oct-conf.h \
   version.h \
@@ -100,6 +102,7 @@
   interpfcn/graphics-props.cc \
   parse-tree/oct-gperf.h \
   builtins.h \
+  builtin-defun-decls.h \
   octave.h \
   $(OCTAVE_VALUE_INC) \
   $(PARSE_TREE_INC) \
@@ -157,6 +160,7 @@
   interpfcn/defaults.h \
   interpfcn/graphics.h \
   operators/ops.cc \
+  builtin-defun-decls.h \
   builtins.cc \
   oct-conf.h \
   version.h \
@@ -246,7 +250,11 @@
 	mv $@-t $@
 
 builtins.cc: $(DEF_FILES) mkbuiltins
-	$(srcdir)/mkbuiltins $(DEF_FILES) > $@-t
+	$(srcdir)/mkbuiltins --source $(DEF_FILES) > $@-t
+	mv $@-t $@
+
+builtin-defun-decls.h: $(SRC_DEF_FILES) mkbuiltins
+	$(srcdir)/mkbuiltins --header $(SRC_DEF_FILES) > $@-t
 	mv $@-t $@
 
 if AMCOND_ENABLE_DYNAMIC_LINKING
--- a/libinterp/builtins.h
+++ b/libinterp/builtins.h
@@ -23,6 +23,10 @@
 #if !defined (octave_builtins_h)
 #define octave_builtins_h 1
 
+#if !defined (MAKE_BUILTINS)
+#include "builtin-defun-decls.h"
+#endif
+
 extern OCTINTERP_API void install_builtins (void);
 
 #endif
--- a/libinterp/mkbuiltins
+++ b/libinterp/mkbuiltins
@@ -18,14 +18,59 @@
 # along with Octave; see the file COPYING.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-if test $# -eq 0; then
-  echo "usage: mkbuiltins f1 f2 ..." 1>&2
+if test $# -lt 2; then
+  echo "usage: mkbuiltins --header|--source f1 f2 ..." 1>&2
   exit 1
 fi
 
 SED=${SED:-'sed'}
 
-cat << \EOF
+make_header=false
+make_source=false
+case "$1" in
+  --header)
+    make_header=true
+    shift
+  ;;
+  --source)
+    make_source=true
+    shift
+  ;;
+  *)
+    echo "mkbuiltins: unrecognized option: $1" 1>&2
+    exit 1
+  ;;
+esac
+
+if $make_header; then
+
+  cat << \EOF
+// DO NOT EDIT!  Generated automatically by mkbuiltins.
+
+#if !defined (octave_builtins_h)
+#define octave_builtins_h 1
+
+#define DEFUN_DECL(name) \
+  extern OCTINTERP_API octave_value_list \
+  name (const octave_value_list& = octave_value_list (), int = 0);
+
+class octave_value_list;
+
+EOF
+
+ $SED -n -e 's/ *\(XDEFUN\|XDEFCONSTFUN\)_INTERNAL *( *\([_A-Za-z][_A-Za-z0-9]*\) *,.*$/DEFUN_DECL (F\2);/p; s/^ *XDEFUNX_INTERNAL *( *"\([_A-Za-z][_A-Za-z0-9]*\)" *,.*$/DEFUN_DECL (F\1);/p' "$@"
+
+  cat << \EOF
+
+#undef DEFUN_DECL
+
+#endif
+
+EOF
+
+else
+
+  cat << \EOF
 // DO NOT EDIT!  Generated automatically by mkbuiltins.
 
 #ifdef HAVE_CONFIG_H
@@ -79,33 +124,35 @@
 
 EOF
 
-for arg
-do
-  fcn=`echo "$arg" | $SED 's,.*/,,; s/\.df//; s/-/_/g;'`
-  echo "static void"
-  echo "install_${fcn}_fcns (void)"
-  echo "{"
-  cat "$arg"
-  echo "}"
-  echo ""
-done
+  for arg
+  do
+    fcn=`echo "$arg" | $SED 's,.*/,,; s/\.df//; s/-/_/g;'`
+    echo "static void"
+    echo "install_${fcn}_fcns (void)"
+    echo "{"
+    cat "$arg"
+    echo "}"
+    echo ""
+  done
 
-cat << \EOF
+  cat << \EOF
 
 void
 install_builtins (void)
 {
 EOF
 
-for arg
-do
-  fcn=`echo "$arg" | $SED 's,.*/,,; s/\.df//; s/-/_/g;'`
-  echo "  install_${fcn}_fcns ();"
-done
+  for arg
+  do
+    fcn=`echo "$arg" | $SED 's,.*/,,; s/\.df//; s/-/_/g;'`
+    echo "  install_${fcn}_fcns ();"
+  done
 
-cat << \EOF
+  cat << \EOF
 }
 
 EOF
 
+fi
+
 exit 0