Home | History | Annotate | Line # | Download | only in swig
swigit revision 1.1
      1 #! /bin/sh
      2 
      3 #
      4 # Copyright (c) 2009 The NetBSD Foundation, Inc.
      5 # All rights reserved.
      6 #
      7 # This code is derived from software contributed to The NetBSD Foundation
      8 # by Alistair Crooks (agc (at] netbsd.org)
      9 #
     10 # Redistribution and use in source and binary forms, with or without
     11 # modification, are permitted provided that the following conditions
     12 # are met:
     13 # 1. Redistributions of source code must retain the above copyright
     14 #    notice, this list of conditions and the following disclaimer.
     15 # 2. Redistributions in binary form must reproduce the above copyright
     16 #    notice, this list of conditions and the following disclaimer in the
     17 #    documentation and/or other materials provided with the distribution.
     18 #
     19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29 # POSSIBILITY OF SUCH DAMAGE.
     30 #
     31 
     32 # rushed script to call swig and compile the output
     33 # Usage: swigit <lang> <module>
     34 
     35 prefix=$(pkg_info -qp swig | awk '{ print $1 }')
     36 
     37 lang=$1
     38 module=$2
     39 
     40 case "$lang" in
     41 "")
     42 	echo "You need to specify an interpreted language like perl or tcl"
     43 	exit 1
     44 	;;
     45 perl)
     46 	dir=$(pkg_info -qL perl | awk '/EXTERN.h/ { gsub("/EXTERN.h$", ""); print }')
     47 	incpath='CPPFLAGS+=-I'"$dir"
     48 	;;
     49 python)
     50 	swigflags="-classic"
     51 	dir=$(pkg_info -qL 'python*' | awk '/Python.h/ { gsub("/Python.h$", ""); print }')
     52 	incpath='CPPFLAGS+=-I'"$dir"
     53 	;;
     54 esac
     55 
     56 case "$module" in
     57 "")
     58 	echo "You need to specify a module"
     59 	exit 1
     60 	;;
     61 esac
     62 
     63 cat << EOF > ${module}${lang}.i
     64 %module ${module}${lang}
     65 %{
     66 #include <${module}.h>
     67 %}
     68 %include ${module}.h
     69 EOF
     70 
     71 cp ../../include/${module}.h .
     72 
     73 swig ${swigflags} -${lang} ${module}${lang}.i
     74 
     75 cat << EOF > Makefile
     76 # \$NetBSD\$
     77 # Automatically generated by swigit wrapper script
     78 
     79 PREFIX=${prefix}
     80 
     81 LIB=${module}${lang}
     82 SRCS=${module}${lang}_wrap.c
     83 WARNS=0
     84 MKMAN=no
     85 CPPFLAGS+=-I\${PREFIX}/include
     86 ${incpath}
     87 LDFLAGS+=-L\${PREFIX}/lib
     88 LDADD+=-l${module}
     89 
     90 .include <bsd.lib.mk>
     91 EOF
     92 
     93 cat << EOF >> shlib_version
     94 major=0
     95 minor=0
     96 EOF
     97 
     98 env USETOOLS=no make
     99