#
# Define these variables from the beginning
#

CLEANFILES =
SUFFIXES =


#
# Miscellaneous rules
#

lol_recursive_rule = \
	@if test -n "$(SUBDIRS)"; then for subdir in $(SUBDIRS); do \
	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $(patsubst %-recursive, %, $@)) || exit 1; \
	done; fi

bench: bench-recursive
bench-recursive:
	$(lol_recursive_rule)

lolcheck: lolcheck-recursive
lolcheck-recursive:
	$(lol_recursive_rule)


#
# Flex and Bison files build rule
#

generated: generated-recursive
generated-recursive:
	$(lol_recursive_rule)
	@if test -n "$(filter %-scanner.l, $(EXTRA_DIST))"; then \
	  echo $(MKDIR_P) generated; \
	  $(MKDIR_P) generated; \
	  rm -f generated/[a-zA-Z]*; \
	  for scanner in $(patsubst %-scanner.l, %, $(filter %-scanner.l, $(EXTRA_DIST))); do \
	    b="`basename $$scanner`"; \
	    echo flex -v -o "generated/$$b-scanner.cpp" "$$scanner-scanner.l"; \
	    flex -v -o "generated/$$b-scanner.cpp" "$$scanner-scanner.l" || exit 1; \
	  done; \
	  for parser in $(patsubst %-parser.y, %, $(filter %-parser.y, $(EXTRA_DIST))); do \
	    b="`basename $$parser`"; \
	    echo bison -o "generated/$$b-parser.cpp" --defines="generated/$$b-parser.h" -d -b "generated/$$b" "$$parser-parser.y"; \
	    bison -o "generated/$$b-parser.cpp" --defines="generated/$$b-parser.h" -d -b "generated/$$b" "$$parser-parser.y" || exit 1; \
	  done; \
	fi


#
# .lolfx build rule
#

lolfx_gen = $(lolfx_gen_$(V))
lolfx_gen_ = $(lolfx_gen_$(AM_DEFAULT_VERBOSITY))
lolfx_gen_0 = @echo "  LOLFX " $@;

SUFFIXES += .lolfx
.lolfx.o:
	$(lolfx_gen)
	$(AM_V_at)(echo "char const *"; \
         echo "lolfx_resource_$(notdir $(basename $(filter %.lolfx, $^))) ="; \
	 $(SED) 's/"/\\"/g' $(filter %.lolfx, $^) | $(SED) 's/\([^\r]*\).*/"\1\\n"/'; \
	 echo ";") \
	| $(CXXCOMPILE) -xc++ -c - -o $@


#
# PS3 fself support rules
#

fself_gen = $(fself_gen_$(V))
fself_gen_ = $(fself_gen_$(AM_DEFAULT_VERBOSITY))
fself_gen_0 = echo "  FSELF " $${x}.self;
fself_gen_1 = echo make_fself $${x}$(EXEEXT) $${x}.self;

all-local: all-local-ps3
all-local-ps3: $(PROGRAMS) $(noinst_PROGRAMS)
	@if test -n "$^"; then for x in $(^:%$(EXEEXT)=%); do \
	  if test x$(MAKE_FSELF) != xno; then \
	    $(fself_gen) \
	    make_fself $${x}$(EXEEXT) $${x}.self; \
	  fi; \
	done; fi

CLEANFILES += $(PROGRAMS:%$(EXEEXT)=%.self) \
              $(PROGRAMS:%$(EXEEXT)=%.elf) \
              $(noinst_PROGRAMS:%$(EXEEXT)=%.self) \
              $(noinst_PROGRAMS:%$(EXEEXT)=%.elf)


#
# Win32 rules
#

# This is here in case we forget to make clean after a Windows build
CLEANFILES += $(PROGRAMS:%$(EXEEXT)=%.exe) \
              $(noinst_PROGRAMS:%$(EXEEXT)=%.exe)


#
# Additional rules
#

.PHONY: bench lolcheck generated