Merge Fix: Spills have ProjMs now
[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
18 # This hides the noisy commandline outputs. You can see them with "make Q="
19 Q ?= @
20
21 CC ?= cc
22 LINK ?= $(CC)
23 AR ?= ar ru
24 RANLIB ?= ranlib
25 DLLEXT ?= .so
26
27 # Variants
28 CFLAGS_debug      = -O0 -g3 -DDEBUG_libfirm
29 CFLAGS_profile    = -O3 -pg -DNDEBUG -fno-inline
30 LINKFLAGS_profile = -pg
31 CFLAGS_optimize   = -O3 -DNDEBUG
32
33 # General flags
34 CFLAGS    += $(CFLAGS_$(variant))
35 CFLAGS    += -Wall -W -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings
36 LINKFLAGS += $(LINKFLAGS_$(variant))
37 VPATH = $(srcdir)
38
39 .PHONY: all
40 all: firm
41
42 # This rule is necessary so that make does not abort if headers get deleted
43 # (the deleted header might still be referenced in a .d file)
44 %.h:
45         @:
46
47 # A very naive way to create a config.h if it is missing
48 $(srcdir)config.h:
49         @echo MakeConfig $@
50         $(Q)rm -f $@
51         $(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
52         $(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
53         $(Q)echo "#define libfirm_VERSION_MINOR 20" >> $@
54
55 # libFirm
56 libfirm_DIRS := \
57         ir         \
58         ir/adt     \
59         ir/ana     \
60         ir/arch    \
61         ir/common  \
62         ir/debug   \
63         ir/obstack \
64         ir/ident   \
65         ir/net     \
66         ir/ir      \
67         ir/lower   \
68         ir/libcore \
69         ir/lpp     \
70         ir/opt     \
71         ir/st      \
72         ir/stat    \
73         ir/tr      \
74         ir/tv      \
75         ir/kaps    \
76         ir/be
77 libfirm_SOURCES  = $(foreach dir,$(libfirm_DIRS),$(wildcard $(dir)/*.c))
78 libfirm_a        = $(builddir)/libfirm.a
79 libfirm_dll      = $(builddir)/libfirm$(DLLEXT)
80 libfirm_CPPFLAGS = -Iinclude/libfirm -Iinclude/libfirm/adt -I. $(foreach dir,$(libfirm_DIRS),-I$(dir))
81
82 .PHONY: firm
83 firm: $(libfirm_dll)
84
85 # backends
86 backends = amd64 arm ia32 sparc TEMPLATE
87
88 EMITTER_GENERATOR = $(srcdir)ir/be/scripts/generate_emitter.pl
89 REGALLOC_IF_GENERATOR = $(srcdir)ir/be/scripts/generate_regalloc_if.pl
90 OPCODES_GENERATOR = $(srcdir)ir/be/scripts/generate_new_opcodes.pl
91 MACHINE_GENERATOR = $(srcdir)ir/be/scripts/generate_machine.pl
92
93 define backend_template
94 $(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
95 $(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
96 $(1)_GEN_HEADERS =
97
98 $(1)_SPEC = ir/be/$(1)/$(1)_spec.pl
99
100 $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR)
101         @echo GEN $$@
102         $(Q)$$(EMITTER_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
103 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_emitter.c
104 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_emitter.h
105
106 $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
107         @echo GEN $$@
108         $(Q)$$(REGALLOC_IF_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
109 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_regalloc_if.c
110 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_regalloc_if.h
111
112 $$(srcdir)ir/be/$(1)/gen_$(1)_machine.h $$(srcdir)ir/be/$(1)/gen_$(1)_machine.c: $$($(1)_SPEC) $$(MACHINE_GENERATOR)
113         @echo GEN $$@
114         $(Q)$$(MACHINE_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
115 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_machine.c
116 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_machine.h
117
118 $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
119         @echo GEN $$@
120         $(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
121 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h
122
123 ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl
124
125 # We need to inform make of the headers it doesn't know yet...
126 $(1)_OBJECTS = $$($(1)_SOURCES:%.c=$$(builddir)/%.o)
127 $$($(1)_OBJECTS): $$($(1)_GEN_HEADERS)
128
129 libfirm_SOURCES += $$($(1)_SOURCES)
130 libfirm_DIRS += ir/be/$(1)
131 endef
132
133 $(foreach backend,$(backends),$(eval $(call backend_template,$(backend))))
134
135 # generators
136 IR_SPEC_GENERATED_FILES := \
137         include/libfirm/nodeops.h \
138         include/libfirm/opcodes.h \
139         ir/ir/gen_ir_cons.c.inl   \
140         ir/ir/gen_irop.c.inl      \
141         ir/ir/gen_irnode.c.inl    \
142         ir/ir/gen_irnode.h
143 IR_SPEC_GENERATOR := scripts/gen_ir.py
144 IR_SPEC := scripts/ir_spec.py
145
146 $(IR_SPEC_GENERATED_FILES): $(IR_SPEC_GENERATOR) $(IR_SPEC) scripts/spec_util.py
147         @echo GEN $@
148         $(Q)$(IR_SPEC_GENERATOR) $(IR_SPEC) ir/ir
149
150 IR_IO_GENERATOR := scripts/gen_ir_io.py
151 IR_IO_GENERATED_FILES := \
152         ir/ir/gen_irio_import.inl \
153         ir/ir/gen_irio_export.inl \
154         ir/ir/gen_irio_lex.inl
155
156 $(IR_IO_GENERATED_FILES): $(IR_IO_GENERATOR) $(IR_SPEC) scripts/spec_util.py
157         @echo GEN $@
158         $(Q)$(IR_IO_GENERATOR) $(IR_SPEC) ir/ir
159
160 ir/ir/irio.c: $(IR_IO_GENERATED_FILES)
161
162 libfirm_OBJECTS = $(libfirm_SOURCES:%.c=$(builddir)/%.o)
163 libfirm_DEPS    = $(libfirm_OBJECTS:%.o=%.d)
164 -include $(libfirm_DEPS)
165
166 $(libfirm_a): $(libfirm_OBJECTS)
167         @echo AR $@
168         $(Q)$(AR) ru $@ $^
169         @echo RANLIB $@
170         $(Q)$(RANLIB) $@
171
172 $(libfirm_dll): $(libfirm_OBJECTS)
173         @echo LINK $@
174         $(Q)$(LINK) -shared -o $@ $^
175
176 # Generic rules
177 UNUSED := $(shell mkdir -p $(libfirm_DIRS:%=$(builddir)/%))
178 $(builddir)/%.o: %.c $(IR_SPEC_GENERATED_FILES) config.h
179         @echo CC $@
180         $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) -MMD -c -o $@ $<
181
182 .PHONY: clean
183 clean:
184         @echo CLEAN
185         $(Q)rm -f $(libfirm_OBJECTS)
186         $(Q)rm -f $(libfirm_TARGET)