# Makefile for `wget' utility
# Copyright (C) 1995-2011, 2015, 2018-2024 Free Software Foundation,
# Inc.

# 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 Wget.  If not, see <http://www.gnu.org/licenses/>.

# Additional permission under GNU GPL version 3 section 7

# If you modify this program, or any covered work, by linking or
# combining it with the OpenSSL project's OpenSSL library (or a
# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
# grants you additional permission to convey the resulting work.
# Corresponding Source for a non-source form of such a combination
# shall include the source code for the parts of OpenSSL used as well
# as that of the covered work.

#
# Version: @VERSION@
#


# The following line is losing on some versions of make!
DEFS     = @DEFS@ -DSYSTEM_WGETRC=\"$(sysconfdir)/wgetrc\" -DLOCALEDIR=\"$(localedir)\"

EXTRA_DIST = css.l css.c css_.c build_info.c.in build_info.c

bin_PROGRAMS = wget
wget_SOURCES = connect.c convert.c cookies.c ftp.c	\
		css_.c css-url.c	\
		ftp-basic.c ftp-ls.c hash.c host.c hsts.c html-parse.c html-url.c	\
		http.c init.c log.c main.c netrc.c progress.c ptimer.c	\
		recur.c res.c retr.c spider.c url.c warc.c	\
		utils.c exits.c build_info.c	\
		css-url.h css-tokens.h connect.h convert.h cookies.h	\
		ftp.h hash.h host.h hsts.h  html-parse.h html-url.h	\
		http.h init.h log.h netrc.h	\
		options.h progress.h ptimer.h recur.h res.h retr.h	\
		spider.h ssl.h sysdep.h url.h warc.h utils.h wget.h	\
		exits.h version.h

if WITH_IRI
wget_SOURCES += iri.c iri.h
endif

if WITH_XATTR
wget_SOURCES += xattr.c xattr.h
endif

if WITH_METALINK
wget_SOURCES += metalink.c metalink.h
endif

if WITH_OPIE
wget_SOURCES += ftp-opie.c
endif

if OS_MSWINDOWS
wget_SOURCES += mswindows.c mswindows.h
endif

if WITH_NTLM
wget_SOURCES += http-ntlm.c http-ntlm.h
endif

if WITH_OPENSSL
wget_SOURCES += openssl.c
endif

if WITH_GNUTLS
wget_SOURCES += gnutls.c
endif

nodist_wget_SOURCES = version.c
EXTRA_wget_SOURCES = iri.c metalink.c xattr.c
LDADD = $(CODE_COVERAGE_LIBS) $(LIBOBJS) ../lib/libgnu.a $(GETADDRINFO_LIB) $(HOSTENT_LIB)\
 $(INET_NTOP_LIB) $(LIBSOCKET) $(LIB_CLOCK_GETTIME) $(LIB_CRYPTO)\
 $(LIB_NANOSLEEP) $(LIB_POSIX_SPAWN) $(LIB_SELECT) $(LIBICONV) $(LIBINTL)\
 $(LIBTHREAD) $(LIBUNISTRING) $(SERVENT_LIB)
AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib $(CODE_COVERAGE_CPPFLAGS)
AM_CFLAGS = $(WERROR_CFLAGS) $(WARN_CFLAGS) $(CODE_COVERAGE_CFLAGS)

../lib/libgnu.a:
	cd ../lib && $(MAKE) $(AM_MAKEFLAGS)

build_info.c: $(srcdir)/Makefile.am $(srcdir)/build_info.c.in
	if test -n "$(VPATH)"; then cp "$(srcdir)/build_info.c.in" .; fi
	$(PERL) "$(top_srcdir)/build-aux/build_info.pl" \
	    "$(top_builddir)/src/build_info.c"
	if test -n "$(VPATH)"; then rm -f build_info.c.in; fi

ESCAPEQUOTE = sed -e 's/[\\"]/\\&/g' -e 's/\\"/"/' -e 's/\\";$$/";/'
version.c:  $(wget_SOURCES) ../lib/libgnu.a
	echo '/* version.c */' > $@
	echo '/* Autogenerated by Makefile - DO NOT EDIT */' >> $@
	echo '' >> $@
	echo '#include "version.h"' >> $@
	echo 'const char *version_string = "@VERSION@";' >> $@
	echo 'const char *compilation_string = "'$(COMPILE)'";' \
	    | $(ESCAPEQUOTE) >> $@
	echo 'const char *link_string = "'$(CCLD) $(AM_CFLAGS) $(CFLAGS) \
	$(AM_LDFLAGS) $(LDFLAGS) $(LIBS) $(wget_LDADD)'";' \
	    | $(ESCAPEQUOTE) >> $@

css.c: $(srcdir)/css.l
	$(LEX) $(LFLAGS) -o$@ $^

css_.c: css.c
	echo '#include "wget.h"' > $@
	cat css.c >> $@

distclean-local:
	rm -f css.c css_.c

check_LIBRARIES = libunittest.a
libunittest_a_SOURCES = $(wget_SOURCES) build_info.c
nodist_libunittest_a_SOURCES = version.c
libunittest_a_CPPFLAGS = -DTESTING "-I$(top_builddir)/lib" "-I$(top_srcdir)/lib" $(CODE_COVERAGE_CPPLAGS)
libunittest_a_LIBADD = $(LIBOBJS)

CLEANFILES = *~ *.bak core core.[0-9]* build_info.c version.c
