3 # This is currently experimental and not fully supported, but we plan to replace
4 # the jambuild with this at some point in the future.
6 # Most variable names are similar to the names used by autoconf...
9 # Some build configuration defaults
15 srcdir ?= $(top_srcdir)
16 builddir ?= $(top_builddir)/$(variant)
17 docdir ?= $(top_builddir)/firm-doc
19 # This hides the noisy commandline outputs. You can see them with "make Q="
29 CFLAGS_all = -fPIC -DHAVE_FIRM_REVISION_H
30 CFLAGS_debug = $(CFLAGS_all) -O0 -g3 -DDEBUG_libfirm
31 CFLAGS_profile = $(CFLAGS_all) -O3 -pg -DNDEBUG -fno-inline
32 LINKFLAGS_profile = -pg
33 CFLAGS_optimize = $(CFLAGS_all) -O3 -DNDEBUG
36 CFLAGS += $(CFLAGS_$(variant))
37 CFLAGS += -Wall -W -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings
38 LINKFLAGS += $(LINKFLAGS_$(variant)) -lm
41 REVISION ?= $(shell git describe --abbrev=40 --always --dirty --match '')
43 # Update revision.h if necessary
45 REV="\#define libfirm_VERSION_REVISION \"$(REVISION)\""; \
46 echo "$$REV" | cmp -s - firm_revision.h 2> /dev/null || echo "$$REV" > firm_revision.h \
52 # This rule is necessary so that make does not abort if headers get deleted
53 # (the deleted header might still be referenced in a .d file)
57 # A very naive way to create a config.h if it is missing
61 $(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
62 $(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
63 $(Q)echo "#define libfirm_VERSION_MINOR 20" >> $@
87 libfirm_SOURCES = $(foreach dir,$(libfirm_DIRS),$(wildcard $(dir)/*.c))
88 libfirm_a = $(builddir)/libfirm.a
89 libfirm_dll = $(builddir)/libfirm$(DLLEXT)
90 libfirm_CPPFLAGS = -Iinclude/libfirm -Iinclude/libfirm/adt -I. $(foreach dir,$(libfirm_DIRS),-I$(dir))
96 backends = amd64 arm ia32 sparc TEMPLATE
98 EMITTER_GENERATOR = $(srcdir)ir/be/scripts/generate_emitter.pl
99 EMITTER_GENERATOR2 = $(srcdir)ir/be/scripts/generate_emitter_new.pl
100 REGALLOC_IF_GENERATOR = $(srcdir)ir/be/scripts/generate_regalloc_if.pl
101 OPCODES_GENERATOR = $(srcdir)ir/be/scripts/generate_new_opcodes.pl
103 define backend_template
104 $(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
105 $(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
108 $(1)_SPEC = ir/be/$(1)/$(1)_spec.pl
110 $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR) $(EMITTER_GENERATOR2)
112 $(Q)$$(EMITTER_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
113 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_emitter.c
114 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_emitter.h
116 $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
118 $(Q)$$(REGALLOC_IF_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
119 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_regalloc_if.c
120 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_regalloc_if.h
122 $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
124 $(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
125 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h
127 ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl
129 # We need to inform make of the headers it doesn't know yet...
130 $(1)_OBJECTS = $$($(1)_SOURCES:%.c=$$(builddir)/%.o)
131 $$($(1)_OBJECTS): $$($(1)_GEN_HEADERS)
133 libfirm_SOURCES += $$($(1)_SOURCES)
134 libfirm_DIRS += ir/be/$(1)
137 $(foreach backend,$(backends),$(eval $(call backend_template,$(backend))))
140 IR_SPEC_GENERATED_FILES := \
141 include/libfirm/nodeops.h \
142 include/libfirm/opcodes.h \
143 ir/ir/gen_ir_cons.c.inl \
144 ir/ir/gen_irop.c.inl \
145 ir/ir/gen_irnode.c.inl \
147 IR_SPEC_GENERATOR := scripts/gen_ir.py
148 IR_SPEC := scripts/ir_spec.py
150 $(IR_SPEC_GENERATED_FILES): $(IR_SPEC_GENERATOR) $(IR_SPEC) scripts/spec_util.py
152 $(Q)$(IR_SPEC_GENERATOR) $(IR_SPEC) ir/ir
154 IR_IO_GENERATOR := scripts/gen_ir_io.py
155 IR_IO_GENERATED_FILES := ir/ir/gen_irio.inl
157 $(IR_IO_GENERATED_FILES): $(IR_IO_GENERATOR) $(IR_SPEC) scripts/spec_util.py
159 $(Q)$(IR_IO_GENERATOR) $(IR_SPEC) ir/ir
161 ir/ir/irio.c: $(IR_IO_GENERATED_FILES)
163 libfirm_OBJECTS = $(libfirm_SOURCES:%.c=$(builddir)/%.o)
164 libfirm_DEPS = $(libfirm_OBJECTS:%.o=%.d)
165 -include $(libfirm_DEPS)
167 $(libfirm_a): $(libfirm_OBJECTS)
171 $(libfirm_dll): $(libfirm_OBJECTS)
173 $(Q)$(LINK) -shared $(LINKFLAGS) -o $@ $^
176 UNUSED := $(shell mkdir -p $(libfirm_DIRS:%=$(builddir)/%))
177 $(builddir)/%.o: %.c $(IR_SPEC_GENERATED_FILES) config.h
179 $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) -MMD -c -o $@ $<
181 $(docdir)/libfirm.tag: $(IR_SPEC_GENERATED_FILES) Doxyfile $(wildcard include/libfirm/*.h) $(wildcard include/libfirm/adt/*.h)
185 DOCU_GENERATOR := scripts/gen_docu.py
186 $(docdir)/html/nodes.html: $(docdir)/libfirm.tag $(DOCU_GENERATOR) $(IR_SPEC) scripts/spec_util.py scripts/style.css
188 $(Q)$(DOCU_GENERATOR) $(docdir)/libfirm.tag "" $@
189 $(Q)cp scripts/style.css $(docdir)/html
191 .PHONY: documentation
192 documentation: $(docdir)/libfirm.tag $(docdir)/html/nodes.html
197 $(Q)rm -f $(libfirm_OBJECTS)
198 $(Q)rm -f $(libfirm_TARGET)
199 $(Q)rm -f $(shell find ir/ -name "gen_*.[ch]")