bepeephole: Inline be_peephole_new_node() into its only caller.
[libfirm] / Makefile
1 # libfirm Makefile
2 #
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.
5 #
6 # Most variable names are similar to the names used by autoconf...
7 -include config.mak
8
9 # Some build configuration defaults
10 top_srcdir   ?=
11 top_builddir ?= build
12 host         ?= unknown-host
13 variant      ?= debug
14
15 srcdir       ?= $(top_srcdir)
16 builddir     ?= $(top_builddir)/$(variant)
17 docdir       ?= $(top_builddir)/doc
18
19 # This hides the noisy commandline outputs. You can see them with "make Q="
20 Q ?= @
21
22 CC ?= cc
23 DOXYGEN ?= doxygen
24 LINK ?= $(CC)
25 AR ?= ar
26 DLLEXT ?= .so
27
28 # Variants
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
36
37 # General flags
38 CFLAGS    += $(CFLAGS_$(variant))
39 CFLAGS    += -Wall -W -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings
40 LINKFLAGS += $(LINKFLAGS_$(variant)) -lm
41 VPATH = $(srcdir)
42
43 REVISION ?= $(shell git describe --abbrev=40 --always --dirty --match '')
44
45 # Update revision.h if necessary
46 UNUSED := $(shell \
47         REV="\#define libfirm_VERSION_REVISION \"$(REVISION)\""; \
48         echo "$$REV" | cmp -s - firm_revision.h 2> /dev/null || echo "$$REV" > firm_revision.h \
49 )
50
51 all: firm
52 .PHONY: all
53
54 # disable make builtin suffix rules
55 .SUFFIXES:
56
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)
59 %.h:
60         @:
61
62 # A very naive way to create a config.h if it is missing
63 $(srcdir)config.h:
64         @echo MakeConfig $@
65         $(Q)rm -f $@
66         $(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
67         $(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
68         $(Q)echo "#define libfirm_VERSION_MINOR 21" >> $@
69
70 # libFirm
71 libfirm_DIRS := \
72         ir         \
73         ir/adt     \
74         ir/ana     \
75         ir/arch    \
76         ir/common  \
77         ir/debug   \
78         ir/obstack \
79         ir/ident   \
80         ir/net     \
81         ir/ir      \
82         ir/lower   \
83         ir/libcore \
84         ir/lpp     \
85         ir/opt     \
86         ir/st      \
87         ir/stat    \
88         ir/tr      \
89         ir/tv      \
90         ir/kaps    \
91         ir/be
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))
96
97 .PHONY: firm
98 firm: $(libfirm_dll)
99
100 # backends
101 backends = amd64 arm ia32 sparc TEMPLATE
102
103 EMITTER_GENERATOR = $(srcdir)ir/be/scripts/generate_emitter.pl
104 REGALLOC_IF_GENERATOR = $(srcdir)ir/be/scripts/generate_regalloc_if.pl
105 OPCODES_GENERATOR = $(srcdir)ir/be/scripts/generate_new_opcodes.pl
106
107 define backend_template
108 $(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
109 $(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
110 $(1)_GEN_HEADERS =
111
112 $(1)_SPEC = ir/be/$(1)/$(1)_spec.pl
113
114 $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR)
115         @echo GEN $$@
116         $(Q)$$(EMITTER_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
117 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_emitter.c
118 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_emitter.h
119
120 $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
121         @echo GEN $$@
122         $(Q)$$(REGALLOC_IF_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
123 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_regalloc_if.c
124 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_regalloc_if.h
125
126 $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
127         @echo GEN $$@
128         $(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
129 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h
130
131 ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl
132
133 # We need to inform make of the headers it doesn't know yet...
134 $(1)_OBJECTS = $$($(1)_SOURCES:%.c=$$(builddir)/%.o)
135 $$($(1)_OBJECTS): $$($(1)_GEN_HEADERS)
136
137 libfirm_SOURCES += $$($(1)_SOURCES)
138 libfirm_DIRS += ir/be/$(1)
139 endef
140
141 $(foreach backend,$(backends),$(eval $(call backend_template,$(backend))))
142
143 # generators
144 IR_SPEC_GENERATED_FILES := \
145         include/libfirm/nodeops.h \
146         include/libfirm/opcodes.h \
147         ir/ir/gen_ir_cons.c.inl   \
148         ir/ir/gen_irop.c.inl      \
149         ir/ir/gen_irnode.c.inl    \
150         ir/ir/gen_irnode.h
151 IR_SPEC_GENERATOR := scripts/gen_ir.py
152 IR_SPEC := scripts/ir_spec.py
153
154 $(IR_SPEC_GENERATED_FILES): $(IR_SPEC_GENERATOR) $(IR_SPEC) scripts/spec_util.py
155         @echo GEN $@
156         $(Q)$(IR_SPEC_GENERATOR) $(IR_SPEC) ir/ir
157
158 IR_IO_GENERATOR := scripts/gen_ir_io.py
159 IR_IO_GENERATED_FILES := ir/ir/gen_irio.inl
160
161 $(IR_IO_GENERATED_FILES): $(IR_IO_GENERATOR) $(IR_SPEC) scripts/spec_util.py
162         @echo GEN $@
163         $(Q)$(IR_IO_GENERATOR) $(IR_SPEC) ir/ir
164
165 ir/ir/irio.c: $(IR_IO_GENERATED_FILES)
166
167 libfirm_OBJECTS = $(libfirm_SOURCES:%.c=$(builddir)/%.o)
168 libfirm_DEPS    = $(libfirm_OBJECTS:%.o=%.d)
169 -include $(libfirm_DEPS)
170
171 $(libfirm_a): $(libfirm_OBJECTS)
172         @echo AR $@
173         $(Q)$(AR) -cru $@ $^
174
175 $(libfirm_dll): $(libfirm_OBJECTS)
176         @echo LINK $@
177         $(Q)$(LINK) -shared $(LINKFLAGS) -o $@ $^
178
179 # Generic rules
180 UNUSED := $(shell mkdir -p $(libfirm_DIRS:%=$(builddir)/%))
181 $(builddir)/%.o: %.c $(IR_SPEC_GENERATED_FILES) config.h
182         @echo CC $@
183         $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) -MMD -c -o $@ $<
184
185 $(docdir)/libfirm.tag: $(IR_SPEC_GENERATED_FILES) Doxyfile $(wildcard include/libfirm/*.h) $(wildcard include/libfirm/adt/*.h)
186         @echo Doxygen $@
187         $(Q)$(DOXYGEN)
188
189 DOCU_GENERATOR := scripts/gen_docu.py
190 $(docdir)/html/nodes.html: $(docdir)/libfirm.tag $(DOCU_GENERATOR) $(IR_SPEC) scripts/spec_util.py scripts/style.css
191         @echo gen_docu.py $@
192         $(Q)$(DOCU_GENERATOR) $(IR_SPEC) $(docdir)/libfirm.tag "" $@
193         $(Q)cp scripts/style.css $(docdir)/html
194
195 .PHONY: doc
196 doc: $(docdir)/libfirm.tag $(docdir)/html/nodes.html
197
198 .PHONY: clean
199 clean:
200         @echo CLEAN
201         $(Q)rm -f $(libfirm_OBJECTS)
202         $(Q)rm -f $(libfirm_TARGET)
203         $(Q)rm -f $(shell find ir/ -name "gen_*.[ch]")