# -*- mode: makefile -*-

.PHONY: algol68

# General hook

algol68: a681$(exeext)
.PHONY: algol68

# Use maximal warnings for this front end.
algol68-warn = $(STRICT_WARN)

a68spec.o: $(srcdir)/algol68/a68spec.c $(SYSTEM_H) coretypes.h $(TM_H) $(GCC_H) \
     $(CONFIG_H) opts.h
	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(DRIVER_DEFINES) \
                $(INCLUDES) $(srcdir)/algol68/a68spec.c

GAC_OBJS = $(GCC_OBJS) a68spec.o intl.o prefix.o version.o
gac$(exeext): $(GAC_OBJS) $(EXTRA_GCC_OBJS) $(LIBDEPS)
	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
          $(GAC_OBJS) $(EXTRA_GCC_OBJS) $(LIBS)

ALGOL68_OBJS = algol68/a681.o \
               algol68/gccaliens.o \
               algol68/a68lang.o \
               attribs.o

algol68_OBJS = $(ALGOL68_OBJS)

# Compiler proper

a681$(exeext): $(ALGOL68_OBJS) attribs.o $(BACKEND) $(LIBDEPS)
	$(CC) $(ALL_CFLAGS) -o $@ \
              $(ALGOL68_OBJS) $(BACKEND) $(LIBS) $(BACKENDLIBS) \
              -la68s -la68 -lm -lc

algol68/tfspec.o: $(srcdir)/algol68/tfspec.c \
                     $(SYSTEM_H) coretypes.h $(TM_H) $(GCC_H) $(CONFIG_H) $(TREE_H)

gt-algol68-a681-lang.h: s-gtype; @true

algol68/a681.o: algol68/a681.c gt-algol68-a681-lang.h gtype-algol68.h

algol68/a68lang.o: algol68/a68lang.c
algol68/a68lang.c: algol68/a68lang.a68 algol68/gccaliens.a68
	ca68 -M algol68 -d algol68 -C -u AAAAGCC $<
	mv a68lang.c a68lang.m algol68/
	sed -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68init\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68convert\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookinitoption\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookhandleoption\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookpostoptions\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookparsefile\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookwriteglobals\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookglobalbindingsp\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookpushdecl\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhooktypeforsize\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookbuiltinfunction\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookgetdecls\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhooktypeformode\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookgimplifyexpr\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68langhookprintablename\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68gimplifyexpr\)/\1/g' \
            -e 's/[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]_\(algol68printablename\)/\1/g' \
            -e 's/.*ON_EXIT.*//' \
            -e 's/\(void \)\([A-Z]*\)\((void).*initialise DECS a68lang.*\)/\1algol68_decs_init\3/' \
        > algol68/a68lang.c.new < algol68/a68lang.c
	mv algol68/a68lang.c.new algol68/a68lang.c

algol68/gccaliens.o: algol68/gccaliens.c
algol68/gccaliens.c: algol68/gccaliens.a68 \
                       $(GO_SYSTEM_H) coretypes.h opts.h $(TREE_H) \
                       $(GIMPLE_H) $(GCC_H) toplev.h debug.h options.h $(FLAGS_H) convert.h    \
                       langhooks.h langhooks-def.h $(TARGET_H) $(DIAGNOSTIC_H) $(GO_CH_H)
	ca68 -C -M algol68 -u AAAGCCA $(ALL_CPPFLAGS) $< 
	mv gccaliens.c gccaliens.m algol68/

#	ca68 -s 0A $(ALL_CPPFLAGS) $<

algol68.srcextra:

# Build hooks:

algol68.all.cross: gac$(exeext)
algol68.start.encap: gac$(exeect)
algol68.rest.encap:
algol68.info:
algol68.install-info:
algol68.dvi:
algol68.pdf:
algol68.install-pdf:
algol68.html:
algol68.man:
algol68.srcinfo:
algol68.srcman:
algol68.install-plugin:

algol68.tags: force
	cd $(srcdir)/algol68; etags -o TAGS.sub *.c *.h; \
	etags --include TAGS.sub --include ../TAGS.sub

lang_checks += check-algol68

#
# Install hooks:
# bf1obj is installed elsewhere as part of $(COMPILERS).

algol68.install-common: installdirs
	-rm -f $(DESTDIR)$(bindir)/gac$(exeext)
	$(INSTALL_PROGRAM) gac$(exeext) $(DESTDIR)$(bindir)/gac$(exeext)

algol68.install-man:

algol68.uninstall:
#
# Clean hooks:
# A lot of the ancillary files are deleted by the main makefile.
# We just have to delete files specific to us.
algol68.mostlyclean:
	-rm -f algol68/*$(objext) algol68/xforward algol68/fflags
	-rm -f algol68/*$(coverageexts)
algol68.clean: algol68.mostlyclean
	-rm -rf algol68-headers
	-rm -f a68lang.c
	-rm -f gccaliens.c gccaliens.m
	-rm -f gcchoks.h
algol68.distclean:
	-rm -f algol68/Makefile algol68/Make-host algol68/Make-target
	-rm -f algol68/config.status algol68/config.cache
algol68.maintainer-clean:

#
# Stage hooks:

algol68.stage1: stage1-start
	-mv algol68/*$(objext) stage1/algol68
algol68.stage2: stage2-start
	-mv algol68/*$(objext) stage2/algol68
algol68.stage3: stage3-start
	-mv algol68/*$(objext) stage3/algol68
algol68.stage4: stage4-start
	-mv algol68/*$(objext) stage4/algol68
algol68.stageprofile: stageprofile-start
	-mv algol68/*$(objext) stageprofile/algol68
algol68.stagefeedback: stagefeedback-start
	-mv algol68/*$(objext) stagefeedback/algol68