if WITH_SLURMRESTD
SUBDIRS = plugins
endif

AUTOMAKE_OPTIONS = foreign
CLEANFILES = core.* *.bino

REF = usage.txt

SRCS = \
	http.c http.h \
	operations.c operations.h \
	slurmrestd.c \
	rest_auth.h rest_auth.c

if WITH_SLURMRESTD
AM_CPPFLAGS = -I$(top_srcdir) $(HTTP_PARSER_CPPFLAGS)
BIN_REF = $(REF:.txt=.bino)
BIN_REF2 = $(BIN_REF:.json=.bino)

sbin_PROGRAMS = slurmrestd

%.bino: %.txt
	$(AM_V_GEN)pushd $(abs_srcdir); $(LD) -r -o "$(abs_builddir)/$*.bino" -z noexecstack --format=binary "$(notdir $<)"; popd
	$(AM_V_at)@OBJCOPY@ --rename-section .data=.rodata,alloc,load,readonly,data,contents "$*.bino"

%.bino: %.json
	$(AM_V_GEN)pushd $(abs_srcdir); $(LD) -r -o "$(abs_builddir)/$*.bino" -z noexecstack --format=binary "$(notdir $<)"; popd
	$(AM_V_at)@OBJCOPY@ --rename-section .data=.rodata,alloc,load,readonly,data,contents "$*.bino"

libslurmrest_ref.lo: $(BIN_REF2)
	$(AM_V_at)echo "# $@ - a libtool object file" >"$@"
	$(AM_V_at)echo "# Generated by $(shell @LIBTOOL@ --version | head -n 1)" >>"$@"
	$(AM_V_at)echo "#" >>"$@"
	$(AM_V_at)echo "# Please DO NOT delete this file!" >>"$@"
	$(AM_V_at)echo "# It is necessary for linking the library." >>"$@"
	$(AM_V_at)echo >>"$@"
	$(AM_V_at)echo "# Name of the PIC object." >>"$@"
	$(AM_V_at)echo "pic_object='$(BIN_REF2)'" >>"$@"
	$(AM_V_at)echo >>"$@"
	$(AM_V_at)echo "# Name of the non-PIC object" >>"$@"
	$(AM_V_at)echo "non_pic_object=''" >>"$@"
	$(AM_V_at)echo >>"$@"

# making a .la
noinst_LTLIBRARIES = libslurmrest_ref.la
libslurmrest_ref_la_SOURCES =
slurmrestd_SOURCES = $(SRCS)
convenience_libs = $(LIB_SLURM) $(DL_LIBS)
slurmrestd_DEPENDENCIES = $(LIB_SLURM_BUILD) libslurmrest_ref.la
slurmrestd_LDFLAGS = -export-dynamic $(CMD_LDFLAGS)

libslurmrest_ref_la_LIBADD = libslurmrest_ref.lo
slurmrestd_LDADD = \
	$(convenience_libs) $(HTTP_PARSER_LDFLAGS) \
	libslurmrest_ref.la
endif
force:
$(convenience_libs) : force
	@cd `dirname $@` && $(MAKE) `basename $@`
