1#! /bin/sh 2# Copyright (C) 2012-2021 Free Software Foundation, Inc. 3# 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 2, or (at your option) 7# any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17# Building libraries (libtool and static) from Vala sources. 18# And use of vapi files to call C code from Vala. 19 20required="valac cc pkg-config libtoolize GNUmake" 21am_create_testdir=empty 22. test-init.sh 23 24cat >> configure.ac << 'END' 25AC_INIT([valalibs],[0.1]) 26 27AC_CONFIG_MACRO_DIR([m4]) 28 29AM_INIT_AUTOMAKE 30AM_PROG_AR 31LT_INIT 32 33AC_PROG_CC 34 35AM_PROG_VALAC([0.7.3]) 36PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4]) 37 38AC_CONFIG_FILES([Makefile src/Makefile]) 39AC_OUTPUT 40END 41 42 43cat > Makefile.am << 'END' 44SUBDIRS=src 45END 46 47mkdir src 48 49cat > src/Makefile.am << 'END' 50AUTOMAKE_OPTIONS = subdir-objects 51lib_LTLIBRARIES = libservice.la 52libservice_la_SOURCES = service.vala cservice.c cservice.h 53libservice_la_CPPFLAGS = -DOKOKIMDEFINED=1 54libservice_la_VALAFLAGS = --vapidir=$(srcdir) --pkg cservice --library service 55AM_CFLAGS = $(GOBJECT_CFLAGS) 56END 57 58libtoolize 59$ACLOCAL 60$AUTOCONF 61$AUTOMAKE -a 62 63cat > src/cservice.c << 'END' 64#include "cservice.h" 65int c_service_mu_call (void) 66{ 67 return OKOKIMDEFINED; 68} 69END 70 71cat > src/cservice.h << 'END' 72int c_service_mu (void); 73END 74 75cat > src/cservice.vapi <<'END' 76namespace CService { 77 public class Mu { 78 [CCode (cheader_filename = "cservice.h", cname = "c_service_mu_call")] 79 public int call (); 80 } 81} 82END 83 84cat > src/service.vala << 'END' 85namespace CService { 86public class Generator : Object { 87 public Generator () { 88 stdout.printf ("construct generator"); 89 } 90 public void init () { 91 stdout.printf ("init generator"); 92 } 93} 94} 95END 96 97mkdir build 98cd build 99../configure 100 101$MAKE 102pwd 103test -f src/libservice_la_vala.stamp 104test -f src/libservice.la 105 106: 107