# $Id: root.in 14590 2006-09-12 17:26:44Z coke $

# Makefile for languages/m4

# Setup of some commands
PARROT         = ../../parrot@exe@
PERL           = @perl@
RM_RF          = @rm_rf@
O              = @o@

# Compile commands and flags
CC             = @cc@
CFLAGS         = @ccflags@ -I../../include
CC_SHARED      = @cc_shared@ # e.g. -fpic
DEBUG          = @cc_debug@
WARN           = @ccwarn@

# Shared-library building
LD             = @ld@
LDFLAGS        = @ldflags@
LD_SHARE_FLAGS = @ld_share_flags@ # e.g. -shared
LIBS        = @libs@
#CONDITIONED_LINE(parrot_exe_def):LIBPARROT      = @build_dir@/parrot@a@
#INVERSE_CONDITIONED_LINE(parrot_exe_def):LIBPARROT      =

# some constants
M4_EVALUATE_SO = ../../runtime/parrot/dynext/m4_evaluate@share_ext@

default: all
all: build 

help:
	@echo ""
	@echo "Following targets are available for the user:"
	@echo ""
	@echo "  all:               m4.pbc"
	@echo "                     This is the default."
	@echo "Testing:"
	@echo "  test:              Run the test suite."
	@echo ""
	@echo "Cleaning:"
	@echo "  clean:             Basic cleaning up."
	@echo "  realclean:         Removes also files generated by 'Configure.pl'"
	@echo "  distclean:         Removes also anything built, in theory."
	@echo ""
	@echo "Misc:"
	@echo "  help:              Print this help message."
	@echo "  html:              Generate HTML documentation."
	@echo "  perlcritic:        Look at the Perl code with Perl::Critic."
	@echo ""

test: build
	$(PERL) -Ilib -I../../lib t/harness
# TODO: reenable testing of GNU m4, by setting env 
#CONDITIONED_LINE(has_gnu_m4):	PARROT_M4_TEST_PROG='m4' $(PERL) -Ilib -I../../lib t/harness $(USE_GNU_M4)

build: $(M4_EVALUATE_SO) m4.pbc 

m4.pbc: src/m4.pir
	$(PARROT) -o m4.pbc src/m4.pir 

$(M4_EVALUATE_SO): src/eval.c
	$(CC) $(CFLAGS) $(CC_SHARED) $(DEBUG) $(WARN) -c src/eval.c
	$(LD) $(LD_SHARE_FLAGS) $(LDFLAGS) $(LIBS) @ld_out@$@ eval$(O) $(LIBPARROT)

src/m4.pir: src/builtin.pir src/freeze.pir src/input.pir src/macro.pir src/output.pir 
	touch $@ 

html: 
	mkdir docs/html 
	pod2html docs/*.pod -o docs/html
 
perlcritic:
	$(PERL) tools/scrutinize.pl
 
clean:
	$(RM_RF) \
m4.pbc \
"*.pdb" \
"*.obj" \
"src/*.pbc" \
"src/*~" \
"t/*/*.m4" \
"t/*/*.pir_out" \
"t/*/*.gnu_out" \
"t/*/*.pir" \
$(M4_EVALUATE_SO) 

realclean: clean
	$(RM_RF) Makefile

distclean: realclean
