Skip to content

Commit

Permalink
Statically link Wren; clean up source tree
Browse files Browse the repository at this point in the history
- Instead of using a separate, upstream Wren, link the specific Wren we
  need directly into wren-vala.  This way I can use, e.g., my fixes to
  wren-lang/wren issue 942 and wren-lang/wren issue 959 even before they are
  upstreamed (or even if they are never upstreamed).

- Refactor list of Vala sources into rules.mk

- Move config.h info to a C file.  Previously, it was not available
  after compile time.  Replace myconfig.vapi with new myconfig.c, and
  declarations in util.vala.
  • Loading branch information
cxw42 committed Apr 25, 2021
1 parent f45724b commit e7a3c6c
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 118 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Generated by configure
Makefile
libwren*.pc
/src/basics.vapi
/src/marshal.vala
/src/trampoline.vala
/src/vm.vala
/src/wrennull.c
/t/common.sh

# Prerequisites
Expand Down
12 changes: 6 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ distcheck-hook:
phony += prettyprint
prettyprint:
-$(AM_V_GEN)uncrustify -l VALA -c $(top_srcdir)/.uncrustifyrc --replace \
src/basics.vapi.in \
src/marshal.vala.in \
src/trampoline.vala.in \
src/vm.vala.in \
src/wrennull.c.in \
$(vala_all_sources) \
t/000-sanity-t.vala \
t/090-util-t.vala \
t/105-tramp-t.vala \
t/100-vmv-t.vala \
t/110-hello-world-s.vala \
Expand All @@ -44,10 +41,13 @@ prettyprint:
t/150-marshal-t.vala \
t/200-expose-class-t.vala \
$(EOL)
-$(AM_V_GEN)uncrustify -c $(top_srcdir)/.uncrustifyrc --replace \
$(c_all_sources) \
$(EOL)

phony += p
p: prettyprint
-ctags -R --exclude='doc/*'
-ctags -R --exclude='doc/*' --exclude='wren-vala-coverage/*'

phony += cleanwren
cleanwren:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ the first three digits.
- Code coverage of the test suite: run `./coverage.sh`, then open
`wren-vala-coverage/index.html` in a Web browser. Requires gcov(1) and
lcov(1).
- Note: You can't run `make distcheck` if you're configured for
coverage. Just re-run `./configure` to go back to non-coverage mode.
- Documentation: run `make html`, then open `doc/valadoc/index.html` in a
Web browser.

Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* config.h.in. Generated from configure.ac by autoheader. */

/* Wren API version */
#undef APIVER

/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H

Expand Down
10 changes: 2 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ AC_MSG_NOTICE([Wren version $WREN_VERSION])

PKG_INSTALLDIR
AC_SUBST([APIVER], [$WREN_VERSION]) dnl Just to reduce typing :)
AC_DEFINE_UNQUOTED([APIVER],["$WREN_VERSION"], [Wren API version])
AC_SUBST([APIVERSH], [AS_TR_SH([$WREN_VERSION])])

dnl === Wren ==============================================================

AC_CHECK_FILE([$srcdir/wren-pkg/wren/README.md], [],
[AC_MSG_ERROR([You asked me to install Wren but the source tree does not appear to be full. Try 'git submodule update --init --recursive" if you have not yet done so.])])

AC_SUBST([WREN_HEADER], [wren-$APIVER.h])
AC_SUBST([MERGED_HEADER], [wren-vala-$APIVER.h])

AC_SEARCH_LIBS([log2], [m],
[], [
Expand Down Expand Up @@ -146,13 +147,6 @@ AC_CONFIG_FILES([
wren-pkg/Makefile
])

dnl Source files: make the generated files RO
AC_CONFIG_FILES([src/basics.vapi], [chmod a-w src/basics.vapi])
AC_CONFIG_FILES([src/marshal.vala], [chmod a-w src/marshal.vala])
AC_CONFIG_FILES([src/trampoline.vala], [chmod a-w src/trampoline.vala])
AC_CONFIG_FILES([src/vm.vala], [chmod a-w src/vm.vala])
AC_CONFIG_FILES([src/wrennull.c], [chmod a-w src/wrennull.c])

dnl pkg-config files: name them after the Wren version
AC_CONFIG_FILES([src/libwren-vala-"${APIVER}".pc:src/libwren-vala.pc.in], [], [APIVER=$APIVER])

Expand Down
5 changes: 1 addition & 4 deletions doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ valadoc:
$(AM_V_GEN)valadoc -o valadoc -b $(top_srcdir)/src --verbose --force \
--package-name='@PACKAGE_TARNAME@' \
--package-version='@PACKAGE_VERSION@' \
$(top_srcdir)/src/basics.vapi \
$(top_srcdir)/src/marshal.vala \
$(top_srcdir)/src/trampoline.vala \
$(top_srcdir)/src/vm.vala \
$(vala_all_sources) \
--doclet=html \
$(MY_VALA_PKGS) \
$(EOL)
Expand Down
20 changes: 19 additions & 1 deletion rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ vapidir = $(datadir)/vala/vapi

# === Variables =========================================================

vala_all_sources = \
$(top_srcdir)/src/basics.vapi \
$(top_srcdir)/src/marshal.vala \
$(top_srcdir)/src/trampoline.vala \
$(top_srcdir)/src/util.vala \
$(top_srcdir)/src/vm.vala \
$(EOL)

c_all_sources = \
$(top_srcdir)/src/myconfig.c \
$(top_srcdir)/src/shim.c \
$(EOL)

# Vala settings.
# - LOCAL_VALA_FLAGS is filled in by each Makefile.am with any other valac
# options that Makefile.am needs.
Expand All @@ -35,7 +48,12 @@ MY_VALA_PKGS = \

# C settings, which are the same throughout. LOCAL_CFLAGS is filled in
# by each Makefile.am.
AM_CFLAGS = $(LOCAL_CFLAGS) $(BASE_CFLAGS) $(CODE_COVERAGE_CFLAGS)
AM_CFLAGS = \
-I$(top_srcdir)/wren-pkg -I$(top_builddir)/wren-pkg \
$(LOCAL_CFLAGS) $(BASE_CFLAGS) \
$(CODE_COVERAGE_CFLAGS) \
$(EOL)

AM_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS)

# Libs. $(LOCAL_LIBS) is added to $(LIBS) in configure.ac.
Expand Down
3 changes: 3 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
*.c
*.h
lib*.vapi

# Hand-made files
!wren-vala-merged.h
116 changes: 94 additions & 22 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,120 @@ EXTRA_DIST = .gitignore

pkgconfig_DATA =
lib_LTLIBRARIES =
noinst_LTLIBRARIES =
dist_vapi_DATA =
include_HEADERS =
dist_include_HEADERS =
dist_noinst_HEADERS =
BUILT_SOURCES =

DISTCLEANFILES =
MAINTAINERCLEANFILES =

# === pkg-config ===

pkgconfig_DATA += \
libwren-vala-@[email protected] \
$(EOL)

DISTCLEANFILES = $(pkgconfig_DATA)
DISTCLEANFILES += $(pkgconfig_DATA)

# === Library ===
# === Library, pass 1 ===
# The Vala files, as a convenience library. This is to get the ordering
# right with respect to wrennull.c.

lib_LTLIBRARIES += libwren-vala.la
noinst_LTLIBRARIES += libinternal.la

libwren_vala_la_SOURCES = \
basics.vapi \
marshal.vala \
myconfig.vapi \
trampoline.vala \
vm.vala \
wrennull.c \
$(EOL)
wren_header = $(top_srcdir)/wren-pkg/wren/src/include/wren.h

libwren_vala_la_LIBADD = \
$(top_builddir)/wren-pkg/libwren-@[email protected] \
libinternal_la_SOURCES = \
$(vala_all_sources) \
wren-vala-merged.h \
$(wren_header) \
$(EOL)

libwren_vala_la_VALAFLAGS = \
--library libwren-vala-@[email protected] -H libwren-vala-@[email protected] \
# XXX not robust against Automake changes
libinternal_stamp = $(srcdir)/libinternal_la_vala.stamp

# Make libinternal get built first. That way $(generated_header) will exist
# when it's time to build wrennull.c.
BUILT_SOURCES += $(libinternal_stamp)

generated_header = $(srcdir)/wren-vala-generated.h
MAINTAINERCLEANFILES += $(generated_header)
dist_noinst_HEADERS += $(generated_header)

# valac makes wren-vala-generated.h. At compile time,
# hand-made wren-vala-merged.h will pull in wren-vala-generated.h and wren.h.
libinternal_la_VALAFLAGS = \
--library libinternal.so -H $(generated_header) \
--vapi libwren-vala.vapi \
$(AM_VALAFLAGS) \
$(EOL)

# === vapi and header ===
libinternal_la_CFLAGS = \
-I$(top_srcdir)/wren-pkg/wren/src/include \
$(AM_CFLAGS) \
$(EOL)

# === Library, pass 2 ===
# This is everything except the Vala files

lib_LTLIBRARIES += libwren-vala-@[email protected]

libwren_vala_@APIVER@_la_SOURCES = \
$(c_all_sources) \
$(EOL)

libwren_vala_@APIVER@_la_CFLAGS = \
-I$(top_srcdir)/wren-pkg/wren/src/include \
$(AM_CFLAGS) \
$(EOL)

libwren_vala_@APIVER@_la_LIBADD = \
libinternal.la \
$(top_builddir)/wren-pkg/libwren-@[email protected] \
$(EOL)

# === Installed header ===
# The client of this library uses a single header with everything in one.
# I make it by hand this way since I was having trouble getting Automake
# to cooperate.

header_for_installation = wren-vala-@[email protected]
DISTCLEANFILES += $(header_for_installation)

$(header_for_installation): $(generated_header) $(wren_header) Makefile.am
$(AM_V_GEN)
$(AM_V_at)echo "/* $@ generated at `date` */" > $@
$(AM_V_at)perl -ne '$$shouldprint = 1../#include.+\bwren.*\.h/; print if $$shouldprint && $$shouldprint !~ /E0/' $(generated_header) >> $@
$(AM_V_at)echo "/* inlining $(wren_header) */" >> $@
$(AM_V_at)cat $(wren_header) >> $@
$(AM_V_at)echo "/* end of inlined $(wren_header) */" >> $@
$(AM_V_at)perl -ne 'print if $$shouldprint; $$shouldprint ||= /#include.+\bwren.*\.h/' $(generated_header) >> $@

# Inline Wren's header into the wren-vala header after we run valac
all-local: $(header_for_installation)

install-data-local: $(header_for_installation)
$(MKDIR_P) "$(DESTDIR)$(includedir)"
$(INSTALL_DATA) "$(header_for_installation)" "$(DESTDIR)$(includedir)"

# XXX not robust against automake changes
uninstall-local:
files="$(header_for_installation)" ; \
dir="$(DESTDIR)$(includedir)"; \
$(am__uninstall_files_from_dir)

# === Installed vapi ===

# Before installing libwren-vala-@[email protected], tack basics.vapi onto the end
# of it. The compiler only writes the declarations from vm.vala into the vapi
# file, but the client needs basics.vapi as well.
libwren-vala-@[email protected]: libwren-vala.vapi basics.vapi
cat $^ > $@
# Also, change the cheader_filename in the vapi.
vapis_to_merge = $(srcdir)/libwren-vala.vapi basics.vapi
$(srcdir)/libwren-vala-@[email protected]: $(vapis_to_merge) Makefile.am $(libinternal_stamp)
rm -f "$@"
perl -pe 's/wren-vala-merged\.h/wren-vala-@[email protected]/g' $(vapis_to_merge) >> "$@"

dist_vapi_DATA += libwren-vala-@[email protected]
DISTCLEANFILES += libwren-vala-@[email protected]
include_HEADERS += libwren-vala-@[email protected]
dist_vapi_DATA += $(srcdir)/libwren-vala-@[email protected]
MAINTAINERCLEANFILES += $(srcdir)/libwren-vala-@[email protected]
6 changes: 2 additions & 4 deletions src/basics.vapi.in → src/basics.vapi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @configure_input@

// basics.vapi: Vala bindings for Wren.
// Documentation is taken from wren.h (license below). This file is in the
// same order as wren.h, as of writing.
Expand All @@ -10,7 +8,7 @@
//
// TODO: check the ownership on Handle instances.

[CCode(cheader_filename = "@WREN_HEADER@", lower_case_cprefix="wren")]
[CCode(cheader_filename = "wren-vala-merged.h", lower_case_cprefix="wren")]
namespace Wren {

[CCode(cname="WREN_VERSION_MAJOR")]
Expand Down Expand Up @@ -154,7 +152,7 @@ namespace Wren {
*
* This class includes all functions taking a WrenVM as the first parameter.
*/
[CCode(cheader_filename = "@WREN_HEADER@", free_function = "wrenFreeVM",
[CCode(cheader_filename = "wren-vala-merged.h", free_function = "wrenFreeVM",
has_type_id = false, cprefix="wren", lower_case_cprefix="wren")]
[Compact]
public class VM
Expand Down
4 changes: 2 additions & 2 deletions src/libwren-vala.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Name: @PACKAGE_TARNAME@
Description: @PACKAGE_NAME@
Version: @PACKAGE_VERSION@

Requires: libwren-@PACKAGE_VERSION@ @AX_PACKAGE_REQUIRES@
Requires: @AX_PACKAGE_REQUIRES@
Requires.private: @AX_PACKAGE_REQUIRES_PRIVATE@

Libs: -L${libdir} -l@PACKAGE_TARNAME@ -lwren-@APIVER@
Libs: -L${libdir} -l@PACKAGE_TARNAME@-@APIVER@
Cflags: -I${includedir}

# vi: set ft=config: #
6 changes: 2 additions & 4 deletions src/marshal.vala.in → src/marshal.vala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// @configure_input@

// marshal.vala: Wren<->Vala marshalling
//
// By Christopher White <[email protected]>
// Copyright (c) 2021 Christopher White. All rights reserved.
// SPDX-License-Identifier: MIT

[CCode(cheader_filename="libwren-vala-@[email protected],@WREN_HEADER@")]
[CCode(cheader_filename="wren-vala-merged.h")]
namespace Wren {

/**
Expand Down Expand Up @@ -43,7 +41,7 @@ namespace Wren {
}
private bool static_init_done = false;

[CCode(cheader_filename="libwren-vala-@[email protected],@WREN_HEADER@")]
[CCode(cheader_filename="wren-vala-merged.h")]
namespace Marshal {

public errordomain MarshalError {
Expand Down
24 changes: 0 additions & 24 deletions src/myconfig.vapi

This file was deleted.

6 changes: 2 additions & 4 deletions src/trampoline.vala.in → src/trampoline.vala
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// @configure_input@

// trampoline.vala: Functions for class bindings
// Part of wren-vala
// By Christopher White <[email protected]>
// SPDX-License-Identifier: MIT

[CCode(cheader_filename="libwren-vala-@[email protected],@WREN_HEADER@")]
[CCode(cheader_filename="wren-vala-merged.h")]
namespace Wren {

/**
Expand All @@ -15,7 +13,7 @@ namespace Wren {
* * has a tramp_ property returning an instance of this class; and
* * implements {@link Wren.HasMethods}
* */
[CCode(cheader_filename="libwren-vala-@[email protected],@WREN_HEADER@")]
[CCode(cheader_filename="wren-vala-merged.h")]
public class Tramp : Object {

/**
Expand Down
Loading

0 comments on commit e7a3c6c

Please sign in to comment.