allow specification of dll-extension
[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 # A very naive way to create a config.h if it is missing
43 $(srcdir)config.h:
44         @echo MakeConfig $@
45         $(Q)rm -f $@
46         $(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
47         $(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
48         $(Q)echo "#define libfirm_VERSION_MINOR 20" >> $@
49         $(Q)echo "#define HAVE_LONG_DOUBLE 1" >> $@
50         $(Q)echo "#define FIRM_STATISTICS" >> $@
51
52 # libFirm
53 libfirm_DIRS := \
54         ir         \
55         ir/adt     \
56         ir/ana     \
57         ir/arch    \
58         ir/common  \
59         ir/debug   \
60         ir/obstack \
61         ir/ident   \
62         ir/net     \
63         ir/ir      \
64         ir/lower   \
65         ir/libcore \
66         ir/opt     \
67         ir/st      \
68         ir/stat    \
69         ir/tr      \
70         ir/tv      \
71         ir/be
72 libfirm_SOURCES  = $(foreach dir,$(libfirm_DIRS),$(wildcard $(dir)/*.c))
73 libfirm_a        = $(builddir)/libfirm.a
74 libfirm_dll      = $(builddir)/libfirm$(DLLEXT)
75 libfirm_CPPFLAGS = -Iinclude/libfirm -Iinclude/libfirm/adt -I. $(foreach dir,$(libfirm_DIRS),-I$(dir))
76
77 .PHONY: firm
78 firm: $(libfirm_dll)
79
80 # backends
81 backends = amd64 arm ia32 sparc TEMPLATE
82
83 EMITTER_GENERATOR = $(srcdir)ir/be/scripts/generate_emitter.pl
84 REGALLOC_IF_GENERATOR = $(srcdir)ir/be/scripts/generate_regalloc_if.pl
85 OPCODES_GENERATOR = $(srcdir)ir/be/scripts/generate_new_opcodes.pl
86 MACHINE_GENERATOR = $(srcdir)ir/be/scripts/generate_machine.pl
87
88 define backend_template
89 $(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
90 $(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
91 $(1)_GEN_HEADERS =
92
93 $(1)_SPEC = ir/be/$(1)/$(1)_spec.pl
94
95 $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR)
96         @echo GEN $$@
97         $(Q)$$(EMITTER_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
98 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_emitter.c
99 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_emitter.h
100
101 $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
102         @echo GEN $$@
103         $(Q)$$(REGALLOC_IF_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
104 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_regalloc_if.c
105 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_regalloc_if.h
106
107 $$(srcdir)ir/be/$(1)/gen_$(1)_machine.h $$(srcdir)ir/be/$(1)/gen_$(1)_machine.c: $$($(1)_SPEC) $$(MACHINE_GENERATOR)
108         @echo GEN $$@
109         $(Q)$$(MACHINE_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
110 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_machine.c
111 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_machine.h
112
113 $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
114         @echo GEN $$@
115         $(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
116 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h
117
118 ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl
119
120 # We need to inform make of the headers it doesn't know yet...
121 $(1)_OBJECTS = $$($(1)_SOURCES:%.c=$$(builddir)/%.o)
122 $$($(1)_OBJECTS): $$($(1)_GEN_HEADERS)
123
124 libfirm_SOURCES += $$($(1)_SOURCES)
125 libfirm_DIRS += ir/be/$(1)
126 endef
127
128 $(foreach backend,$(backends),$(eval $(call backend_template,$(backend))))
129
130 # generators
131 IR_SPEC_GENERATED_FILES := \
132         include/libfirm/nodeops.h \
133         include/libfirm/opcodes.h \
134         ir/ir/gen_ir_cons.c.inl   \
135         ir/ir/gen_irop.c.inl      \
136         ir/ir/gen_irnode.c.inl    \
137         ir/ir/gen_irnode.h
138 IR_SPEC_GENERATOR := scripts/gen_ir.py
139 IR_SPEC := scripts/ir_spec.py
140
141 $(IR_SPEC_GENERATED_FILES): $(IR_SPEC_GENERATOR) $(IR_SPEC) scripts/spec_util.py
142         @echo GEN $@
143         $(Q)$(IR_SPEC_GENERATOR) $(IR_SPEC) ir/ir
144
145 IR_IO_GENERATOR := scripts/gen_ir_io.py
146 IR_IO_GENERATED_FILES := \
147         ir/ir/gen_irio_import.inl \
148         ir/ir/gen_irio_export.inl \
149         ir/ir/gen_irio_lex.inl
150
151 $(IR_IO_GENERATED_FILES): $(IR_IO_GENERATOR) $(IR_SPEC) scripts/spec_util.py
152         @echo GEN $@
153         $(Q)$(IR_IO_GENERATOR) $(IR_SPEC) ir/ir
154
155 ir/ir/irio.c: $(IR_IO_GENERATED_FILES)
156
157 libfirm_OBJECTS = $(libfirm_SOURCES:%.c=$(builddir)/%.o)
158 libfirm_DEPS    = $(libfirm_OBJECTS:%.o=%.d)
159 -include $(libfirm_DEPS)
160
161 $(libfirm_a): $(libfirm_OBJECTS)
162         @echo AR $@
163         $(Q)$(AR) ru $@ $^
164         @echo RANLIB $@
165         $(Q)$(RANLIB) $@
166
167 $(libfirm_dll): $(libfirm_OBJECTS)
168         @echo LINK $@
169         $(Q)$(LINK) -shared -o $@ $^
170
171 # Generic rules
172 UNUSED := $(shell mkdir -p $(libfirm_DIRS:%=$(builddir)/%))
173 $(builddir)/%.o: %.c $(IR_SPEC_GENERATED_FILES) config.h
174         @echo CC $@
175         $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) -MMD -c -o $@ $<
176
177 .PHONY: clean
178 clean:
179         @echo CLEAN
180         $(Q)rm -f $(libfirm_OBJECTS)
181         $(Q)rm -f $(libfirm_TARGET)