# Guile-GnuTLS --- Guile bindings for GnuTLS.
# Copyright (C) 2007-2025 Free Software Foundation, Inc.
#
# This file is part of Guile-GnuTLS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

GUILE_FOR_BUILD =						\
  GUILE_AUTO_COMPILE=0 $(GUILE) -L $(top_srcdir)/guile/modules

noinst_HEADERS = errors.h utils.h

EXTRA_DIST =					\
  make-enum-map.scm make-smob-types.scm		\
  make-enum-header.scm make-smob-header.scm

# Files generated by the (gnutls build ...) modules.
GENERATED_BINDINGS =				\
  enum-map.i.c smob-types.i.c enums.h smobs.h

BUILT_SOURCES =					\
  $(GENERATED_BINDINGS)				\
  core.x errors.x

CLEANFILES = $(BUILT_SOURCES)

guileextension_LTLIBRARIES  = guile-gnutls-v-2.la

# Use '-module' to build a "dlopenable module", in Libtool terms.
# Use '-undefined' to placate Libtool on Windows; see
# <https://lists.gnutls.org/pipermail/gnutls-devel/2014-December/007294.html>.
guile_gnutls_v_2_la_LDFLAGS = -module -no-undefined

guile_gnutls_v_2_la_SOURCES = core.c errors.c utils.c
guile_gnutls_v_2_la_CFLAGS =			\
  $(AM_CFLAGS) $(GNULIB_CFLAGS) $(GUILE_CFLAGS) $(GNUTLS_CFLAGS)
guile_gnutls_v_2_la_LIBADD = \
	$(GNUTLS_LIBS) \
	$(GUILE_LDFLAGS)

AM_CPPFLAGS = \
	-I$(top_srcdir)/lib/includes \
	-I$(top_builddir)/lib/includes	\
	-I$(top_srcdir)/extra/includes \
	-I$(top_builddir) \
	-I$(builddir)

if HAVE_GCC

AM_CFLAGS = -Wall -Wextra

# Generated `.x' files and Guile's `scm_c_define_gsubr ()' require
# `-Wno-strict-prototypes'.  This trick makes sure `-Wno-s-p' appears
# after `-Ws-p'.
AM_CFLAGS += -Wno-strict-prototypes

# Functions generated from 'SCM_SMOB_PRINT' & co. typically have
# unused parameters.
AM_CFLAGS += -Wno-unused-parameter

# The `-fgnu89-inline' option appeared in GCC 4.1.3.
if HAVE_GCC_GNU89_INLINE_OPTION

# Guile and GMP currently rely on GNU inline semantics, not C99 inline.
AM_CFLAGS += -fgnu89-inline

endif HAVE_GCC_GNU89_INLINE_OPTION

endif HAVE_GCC


enums.h: $(srcdir)/make-enum-header.scm $(top_srcdir)/guile/modules/gnutls/build/enums.scm
	$(AM_V_GEN)$(GUILE_FOR_BUILD) "$<" > "$@.tmp"
	$(AM_V_at)mv "$@.tmp" "$@"

enum-map.i.c: $(srcdir)/make-enum-map.scm $(top_srcdir)/guile/modules/gnutls/build/enums.scm
	$(AM_V_GEN)$(GUILE_FOR_BUILD) "$<" > "$@.tmp"
	$(AM_V_at)mv "$@.tmp" "$@"

smobs.h: $(srcdir)/make-smob-header.scm $(top_srcdir)/guile/modules/gnutls/build/smobs.scm
	$(AM_V_GEN)$(GUILE_FOR_BUILD) "$<" > "$@.tmp"
	$(AM_V_at)mv "$@.tmp" "$@"

smob-types.i.c: $(srcdir)/make-smob-types.scm $(top_srcdir)/guile/modules/gnutls/build/smobs.scm
	$(AM_V_GEN)$(GUILE_FOR_BUILD) "$<" > "$@.tmp"
	$(AM_V_at)mv "$@.tmp" "$@"


# C file snarfing.

# `$(GUILE_CFLAGS)' may contain a series of `-I' switches so it must be
# included here, even though we'd really want `$(GUILE_CPPFLAGS)'.
snarfcppopts = $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
	       $(CFLAGS) $(guile_gnutls_v_2_la_CFLAGS)

# Note: we cannot use the portable ".c.x" form, since that leads
# prerequisites to be ignored:
# <https://lists.gnutls.org/pipermail/gnutls-devel/2013-September/006453.html>.
%.x: %.c $(GENERATED_BINDINGS)
	$(AM_V_GEN)$(guile_snarf) -o $@ $< $(snarfcppopts)

# Target used by doc/Makefile, to create all built sources necessary
# for generating the manual.

.PHONY: built-sources
built-sources: $(BUILT_SOURCES)
