xref: /netbsd-src/crypto/external/bsd/netpgp/dist/bindings/swig/swigit (revision 7d576ad98313cccaf1d2a122dd67f4a17104d4a5)
1e502623fSagc#! /bin/sh
2e502623fSagc
3e502623fSagc#
4e502623fSagc# Copyright (c) 2009 The NetBSD Foundation, Inc.
5e502623fSagc# All rights reserved.
6e502623fSagc#
7e502623fSagc# This code is derived from software contributed to The NetBSD Foundation
8e502623fSagc# by Alistair Crooks (agc@netbsd.org)
9e502623fSagc#
10e502623fSagc# Redistribution and use in source and binary forms, with or without
11e502623fSagc# modification, are permitted provided that the following conditions
12e502623fSagc# are met:
13e502623fSagc# 1. Redistributions of source code must retain the above copyright
14e502623fSagc#    notice, this list of conditions and the following disclaimer.
15e502623fSagc# 2. Redistributions in binary form must reproduce the above copyright
16e502623fSagc#    notice, this list of conditions and the following disclaimer in the
17e502623fSagc#    documentation and/or other materials provided with the distribution.
18e502623fSagc#
19e502623fSagc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20e502623fSagc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21e502623fSagc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22e502623fSagc# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23e502623fSagc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24e502623fSagc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25e502623fSagc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26e502623fSagc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27e502623fSagc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28e502623fSagc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29e502623fSagc# POSSIBILITY OF SUCH DAMAGE.
30e502623fSagc#
31e502623fSagc
32e502623fSagc# rushed script to call swig and compile the output
33e502623fSagc# Usage: swigit <lang> <module>
34e502623fSagc
356b132381Sagcprefix=$(pkg_info -qp swig | awk '{ print $2 }')
36e502623fSagc
37e502623fSagclang=$1
38e502623fSagcmodule=$2
39e502623fSagc
40e502623fSagccase "$lang" in
41e502623fSagc"")
42e502623fSagc	echo "You need to specify an interpreted language like perl or tcl"
43e502623fSagc	exit 1
44e502623fSagc	;;
45e502623fSagcperl)
46e502623fSagc	dir=$(pkg_info -qL perl | awk '/EXTERN.h/ { gsub("/EXTERN.h$", ""); print }')
47e5e6e153Sagc	cstrings1='#undef SvPOK'
48e5e6e153Sagc	cstrings2='#define SvPOK(x) 1'
49e502623fSagc	incpath='CPPFLAGS+=-I'"$dir"
50e502623fSagc	;;
51e502623fSagcpython)
52*7d576ad9Sagc	swigflags="-shadow"
53e502623fSagc	dir=$(pkg_info -qL 'python*' | awk '/Python.h/ { gsub("/Python.h$", ""); print }')
54e502623fSagc	incpath='CPPFLAGS+=-I'"$dir"
55e502623fSagc	;;
56e502623fSagcesac
57e502623fSagc
58e502623fSagccase "$module" in
59e502623fSagc"")
60e502623fSagc	echo "You need to specify a module"
61e502623fSagc	exit 1
62e502623fSagc	;;
63e502623fSagcesac
64e502623fSagc
65e502623fSagccat << EOF > ${module}${lang}.i
66e502623fSagc%module ${module}${lang}
67e502623fSagc%{
68e502623fSagc#include <${module}.h>
69e5e6e153Sagc${cstrings1}
70e5e6e153Sagc${cstrings2}
71e502623fSagc%}
72e502623fSagc%include ${module}.h
73e502623fSagcEOF
74e502623fSagc
75e502623fSagccp ../../include/${module}.h .
76e502623fSagc
77e502623fSagcswig ${swigflags} -${lang} ${module}${lang}.i
78e502623fSagc
79e502623fSagccat << EOF > Makefile
80e502623fSagc# \$NetBSD\$
81e502623fSagc# Automatically generated by swigit wrapper script
82e502623fSagc
83e502623fSagcPREFIX=${prefix}
84e502623fSagc
85e502623fSagcLIB=${module}${lang}
86e502623fSagcSRCS=${module}${lang}_wrap.c
87e502623fSagcWARNS=0
88e502623fSagcMKMAN=no
89e502623fSagcCPPFLAGS+=-I\${PREFIX}/include
90e502623fSagc${incpath}
91e502623fSagcLDFLAGS+=-L\${PREFIX}/lib
92e502623fSagcLDADD+=-l${module}
93e502623fSagc
94e502623fSagc.include <bsd.lib.mk>
95e502623fSagcEOF
96e502623fSagc
97e5e6e153Sagccat << EOF > shlib_version
98e502623fSagcmajor=0
99e502623fSagcminor=0
100e502623fSagcEOF
101e502623fSagc
102e502623fSagcenv USETOOLS=no make
103*7d576ad9Sagc
104*7d576ad9Sagccase "${lang}" in
105*7d576ad9Sagcpython)
106*7d576ad9Sagc	ln -s lib${module}${lang}.so _${module}${lang}.so
107*7d576ad9Sagc	;;
108*7d576ad9Sagcesac
109