#
# Copyright (C)2026 kimapr
#
# This file is part of fcnatfw.
#
# fcnatfw 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.
#
# fcnatfw 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/>.
#

prefix=/usr/local
exec_prefix=$(prefix)
bindir=$(exec_prefix)/bin
libdir=$(exec_prefix)/lib

INSTALL=install
INSTALL_PROGRAM=$(INSTALL)

sinclude config.mk

all: lib/fcnatfwpshare.so bin/fcnatwrap bin/fcnatfw

lib/fcnatfwpshare.so: lib/solib.c
	cd lib && $(CC) $(CFLAGS) -fPIE -shared solib.c -o fcnatfwpshare.so $(LDFLAGS)

bin/prelude:
bin/interpreter:

bin/%: bin/%.in bin/prelude bin/interpreter
	./transform-script $< $@

clean:
	rm -f lib/fcnatfwpshare.so bin/fcnatfw bin/fcnatwrap

install: lib/fcnatfwpshare.so
	mkdir -p $(DESTDIR)$(bindir) $(DESTDIR)$(libdir)
	cd bin && $(INSTALL_PROGRAM) fcnatfw $(DESTDIR)$(bindir)
	cd bin && $(INSTALL_PROGRAM) fcnatwrap $(DESTDIR)$(bindir)
	cd lib && $(INSTALL_PROGRAM) fcnatfwpshare.so $(DESTDIR)$(libdir)

uninstall:
	rm -f $(DESTDIR)$(bindir)/fcnatfw $(DESTDIR)$(bindir)/fcnatwrap $(DESTDIR)$(libdir)/fcnatfwpshare.so

distclean: clean
	rm -f config.mk config.status bin/prelude bin/interpreter

check:

.PHONY: all clean install uninstall distclean check
