# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
# Copyright (c) 2020-2023 Brett Sheffield <bacs@librecast.net>

SHELL = @SHELL@

.SUFFIXES:
.SUFFIXES: .c .o

CC = @CC@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
LDFLAGS = @LDFLAGS@
LDLIBS = @LIBS@
PACKAGE = @PACKAGE_NAME@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PROGRAMS = lcshare lcsync
PROGRAMS_CAP = lcshare
SHELL = @SHELL@
bindir = @bindir@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
exec_prefix = @exec_prefix@
mandir = @mandir@
prefix = @prefix@
srcdir = @srcdir@

LDLIBS = @LIBS@

OBJS = lcsync.o globals.o help.o log.o opt.o sec.o sync.o @VEC_O@
SETCAP_PROGRAM ?= setcap

all:		src

src:		$(PROGRAMS)

lcshare:	$(OBJS) arg_share.o
		$(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRAFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)

lcsync:		$(OBJS) arg_sync.o
		$(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRAFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)

arg_share.o:	arg.c arg.h
		$(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRAFLAGS) -DLCSHARE -c -o $@ $<

arg_sync.o:	arg.c arg.h
		$(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRAFLAGS) -DLCSYNC -c -o $@ $<

%.o:            %.c %.h
		$(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRAFLAGS) -c -o $@ $<

misc.o:		misc.h

install:        src
		$(INSTALL) -d $(DESTDIR)$(bindir)
		$(INSTALL_PROGRAM) $(PROGRAMS) $(DESTDIR)$(bindir)
		$(foreach p,$(PROGRAMS_CAP), @SETCAP_PROGRAM@ $(DESTDIR)$(bindir)/$(p))

.PHONY: clean realclean setcap

clean:
	$(RM) *.o

realclean: clean
	$(RM) $(PROGRAMS)

setcap: $(PROGRAMS_CAP)
	$(foreach p,$(PROGRAMS_CAP), $(SETCAP_PROGRAM) cap_net_raw=eip $(p))
