+# disable make builtin suffix rules
+.SUFFIXES:
+
+# This rule is necessary so that make does not abort if headers get deleted
+# (the deleted header might still be referenced in a .d file)
+%.h:
+ @:
+
+# A very naive way to create a config.h if it is missing
+$(srcdir)config.h:
+ @echo MakeConfig $@
+ $(Q)rm -f $@
+ $(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
+ $(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
+ $(Q)echo "#define libfirm_VERSION_MINOR 21" >> $@
+
+# libFirm
+libfirm_DIRS := \
+ ir \
+ ir/adt \
+ ir/ana \
+ ir/arch \
+ ir/common \
+ ir/debug \
+ ir/obstack \
+ ir/ident \
+ ir/net \
+ ir/ir \
+ ir/lower \
+ ir/libcore \
+ ir/lpp \
+ ir/opt \
+ ir/st \
+ ir/stat \
+ ir/tr \
+ ir/tv \
+ ir/kaps \
+ ir/be
+libfirm_SOURCES = $(foreach dir,$(libfirm_DIRS),$(wildcard $(dir)/*.c))
+libfirm_a = $(builddir)/libfirm.a
+libfirm_dll = $(builddir)/libfirm$(DLLEXT)
+libfirm_CPPFLAGS = -Iinclude/libfirm -Iinclude/libfirm/adt -I. $(foreach dir,$(libfirm_DIRS),-I$(dir))
+
+.PHONY: firm
+firm: $(libfirm_dll)
+
+# backends
+backends = amd64 arm ia32 sparc TEMPLATE
+
+EMITTER_GENERATOR = $(srcdir)ir/be/scripts/generate_emitter.pl
+REGALLOC_IF_GENERATOR = $(srcdir)ir/be/scripts/generate_regalloc_if.pl
+OPCODES_GENERATOR = $(srcdir)ir/be/scripts/generate_new_opcodes.pl
+
+define backend_template
+$(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
+$(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
+$(1)_GEN_HEADERS =
+
+$(1)_SPEC = ir/be/$(1)/$(1)_spec.pl
+
+$$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR)
+ @echo GEN $$@
+ $(Q)$$(EMITTER_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
+$(1)_SOURCES += ir/be/$(1)/gen_$(1)_emitter.c
+$(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_emitter.h
+
+$$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
+ @echo GEN $$@
+ $(Q)$$(REGALLOC_IF_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
+$(1)_SOURCES += ir/be/$(1)/gen_$(1)_regalloc_if.c
+$(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_regalloc_if.h
+
+$$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
+ @echo GEN $$@
+ $(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
+$(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h
+
+ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl
+
+# We need to inform make of the headers it doesn't know yet...
+$(1)_OBJECTS = $$($(1)_SOURCES:%.c=$$(builddir)/%.o)
+$$($(1)_OBJECTS): $$($(1)_GEN_HEADERS)