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)/doc
19 # This hides the noisy commandline outputs. You can see them with "make Q="
29 CFLAGS_all = -std=c99 -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 CFLAGS_coverage = $(CFLAGS_all) -O0 --coverage -DDEBUG_libfirm
33 LINKFLAGS_profile = -pg
34 LINKFLAGS_coverage = --coverage
35 CFLAGS_optimize = $(CFLAGS_all) -O3 -fomit-frame-pointer -DNDEBUG
38 CFLAGS += $(CFLAGS_$(variant))
39 CFLAGS += -Wall -W -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings
40 LINKFLAGS += $(LINKFLAGS_$(variant)) -lm
43 REVISION ?= $(shell git describe --abbrev=40 --always --dirty --match '')
45 # Update revision.h if necessary
47 REV="\#define libfirm_VERSION_REVISION \"$(REVISION)\""; \
48 echo "$$REV" | cmp -s - firm_revision.h 2> /dev/null || echo "$$REV" > firm_revision.h \
54 # disable make builtin suffix rules
57 # This rule is necessary so that make does not abort if headers get deleted
58 # (the deleted header might still be referenced in a .d file)
62 # A very naive way to create a config.h if it is missing
66 $(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
67 $(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
68 $(Q)echo "#define libfirm_VERSION_MINOR 21" >> $@
92 libfirm_SOURCES = $(foreach dir,$(libfirm_DIRS),$(wildcard $(dir)/*.c))
93 libfirm_a = $(builddir)/libfirm.a
94 libfirm_dll = $(builddir)/libfirm$(DLLEXT)
95 libfirm_CPPFLAGS = -Iinclude/libfirm -Iinclude/libfirm/adt -I. $(foreach dir,$(libfirm_DIRS),-I$(dir))
101 backends = amd64 arm ia32 sparc TEMPLATE
103 EMITTER_GENERATOR = $(srcdir)ir/be/scripts/generate_emitter.pl
104 EMITTER_GENERATOR2 = $(srcdir)ir/be/scripts/generate_emitter_new.pl
105 REGALLOC_IF_GENERATOR = $(srcdir)ir/be/scripts/generate_regalloc_if.pl
106 OPCODES_GENERATOR = $(srcdir)ir/be/scripts/generate_new_opcodes.pl
108 define backend_template
109 $(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
110 $(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
113 $(1)_SPEC = ir/be/$(1)/$(1)_spec.pl
115 $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR) $(EMITTER_GENERATOR2)
117 $(Q)$$(EMITTER_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
118 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_emitter.c
119 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_emitter.h
121 $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
123 $(Q)$$(REGALLOC_IF_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
124 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_regalloc_if.c
125 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_regalloc_if.h
127 $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
129 $(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
130 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h
132 ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl
134 # We need to inform make of the headers it doesn't know yet...
135 $(1)_OBJECTS = $$($(1)_SOURCES:%.c=$$(builddir)/%.o)
136 $$($(1)_OBJECTS): $$($(1)_GEN_HEADERS)
138 libfirm_SOURCES += $$($(1)_SOURCES)
139 libfirm_DIRS += ir/be/$(1)
142 $(foreach backend,$(backends),$(eval $(call backend_template,$(backend))))
145 IR_SPEC_GENERATED_FILES := \
146 include/libfirm/nodeops.h \
147 include/libfirm/opcodes.h \
148 ir/ir/gen_ir_cons.c.inl \
149 ir/ir/gen_irop.c.inl \
150 ir/ir/gen_irnode.c.inl \
152 IR_SPEC_GENERATOR := scripts/gen_ir.py
153 IR_SPEC := scripts/ir_spec.py
155 $(IR_SPEC_GENERATED_FILES): $(IR_SPEC_GENERATOR) $(IR_SPEC) scripts/spec_util.py
157 $(Q)$(IR_SPEC_GENERATOR) $(IR_SPEC) ir/ir
159 IR_IO_GENERATOR := scripts/gen_ir_io.py
160 IR_IO_GENERATED_FILES := ir/ir/gen_irio.inl
162 $(IR_IO_GENERATED_FILES): $(IR_IO_GENERATOR) $(IR_SPEC) scripts/spec_util.py
164 $(Q)$(IR_IO_GENERATOR) $(IR_SPEC) ir/ir
166 ir/ir/irio.c: $(IR_IO_GENERATED_FILES)
168 libfirm_OBJECTS = $(libfirm_SOURCES:%.c=$(builddir)/%.o)
169 libfirm_DEPS = $(libfirm_OBJECTS:%.o=%.d)
170 -include $(libfirm_DEPS)
172 $(libfirm_a): $(libfirm_OBJECTS)
176 $(libfirm_dll): $(libfirm_OBJECTS)
178 $(Q)$(LINK) -shared $(LINKFLAGS) -o $@ $^
181 UNUSED := $(shell mkdir -p $(libfirm_DIRS:%=$(builddir)/%))
182 $(builddir)/%.o: %.c $(IR_SPEC_GENERATED_FILES) config.h
184 $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) -MMD -c -o $@ $<
186 $(docdir)/libfirm.tag: $(IR_SPEC_GENERATED_FILES) Doxyfile $(wildcard include/libfirm/*.h) $(wildcard include/libfirm/adt/*.h)
190 DOCU_GENERATOR := scripts/gen_docu.py
191 $(docdir)/html/nodes.html: $(docdir)/libfirm.tag $(DOCU_GENERATOR) $(IR_SPEC) scripts/spec_util.py scripts/style.css
193 $(Q)$(DOCU_GENERATOR) $(IR_SPEC) $(docdir)/libfirm.tag "" $@
194 $(Q)cp scripts/style.css $(docdir)/html
197 doc: $(docdir)/libfirm.tag $(docdir)/html/nodes.html
202 $(Q)rm -f $(libfirm_OBJECTS)
203 $(Q)rm -f $(libfirm_TARGET)
204 $(Q)rm -f $(shell find ir/ -name "gen_*.[ch]")