Use -std=c99.
[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 LINKFLAGS_profile = -pg
33 CFLAGS_optimize   = $(CFLAGS_all) -O3 -DNDEBUG
34
35 # General flags
36 CFLAGS    += $(CFLAGS_$(variant))
37 CFLAGS    += -Wall -W -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings
38 LINKFLAGS += $(LINKFLAGS_$(variant)) -lm
39 VPATH = $(srcdir)
40
41 REVISION ?= $(shell git describe --abbrev=40 --always --dirty --match '')
42
43 # Update revision.h if necessary
44 UNUSED := $(shell \
45         REV="\#define libfirm_VERSION_REVISION \"$(REVISION)\""; \
46         echo "$$REV" | cmp -s - firm_revision.h 2> /dev/null || echo "$$REV" > firm_revision.h \
47 )
48
49 .PHONY: all
50 all: firm
51
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)
54 %.h:
55         @:
56
57 # A very naive way to create a config.h if it is missing
58 $(srcdir)config.h:
59         @echo MakeConfig $@
60         $(Q)rm -f $@
61         $(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
62         $(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
63         $(Q)echo "#define libfirm_VERSION_MINOR 20" >> $@
64
65 # libFirm
66 libfirm_DIRS := \
67         ir         \
68         ir/adt     \
69         ir/ana     \
70         ir/arch    \
71         ir/common  \
72         ir/debug   \
73         ir/obstack \
74         ir/ident   \
75         ir/net     \
76         ir/ir      \
77         ir/lower   \
78         ir/libcore \
79         ir/lpp     \
80         ir/opt     \
81         ir/st      \
82         ir/stat    \
83         ir/tr      \
84         ir/tv      \
85         ir/kaps    \
86         ir/be
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))
91
92 .PHONY: firm
93 firm: $(libfirm_dll)
94
95 # backends
96 backends = amd64 arm ia32 sparc TEMPLATE
97
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
102
103 define backend_template
104 $(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
105 $(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
106 $(1)_GEN_HEADERS =
107
108 $(1)_SPEC = ir/be/$(1)/$(1)_spec.pl
109
110 $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR) $(EMITTER_GENERATOR2)
111         @echo GEN $$@
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
115
116 $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
117         @echo GEN $$@
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
121
122 $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
123         @echo GEN $$@
124         $(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
125 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h
126
127 ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl
128
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)
132
133 libfirm_SOURCES += $$($(1)_SOURCES)
134 libfirm_DIRS += ir/be/$(1)
135 endef
136
137 $(foreach backend,$(backends),$(eval $(call backend_template,$(backend))))
138
139 # generators
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    \
146         ir/ir/gen_irnode.h
147 IR_SPEC_GENERATOR := scripts/gen_ir.py
148 IR_SPEC := scripts/ir_spec.py
149
150 $(IR_SPEC_GENERATED_FILES): $(IR_SPEC_GENERATOR) $(IR_SPEC) scripts/spec_util.py
151         @echo GEN $@
152         $(Q)$(IR_SPEC_GENERATOR) $(IR_SPEC) ir/ir
153
154 IR_IO_GENERATOR := scripts/gen_ir_io.py
155 IR_IO_GENERATED_FILES := ir/ir/gen_irio.inl
156
157 $(IR_IO_GENERATED_FILES): $(IR_IO_GENERATOR) $(IR_SPEC) scripts/spec_util.py
158         @echo GEN $@
159         $(Q)$(IR_IO_GENERATOR) $(IR_SPEC) ir/ir
160
161 ir/ir/irio.c: $(IR_IO_GENERATED_FILES)
162
163 libfirm_OBJECTS = $(libfirm_SOURCES:%.c=$(builddir)/%.o)
164 libfirm_DEPS    = $(libfirm_OBJECTS:%.o=%.d)
165 -include $(libfirm_DEPS)
166
167 $(libfirm_a): $(libfirm_OBJECTS)
168         @echo AR $@
169         $(Q)$(AR) -cru $@ $^
170
171 $(libfirm_dll): $(libfirm_OBJECTS)
172         @echo LINK $@
173         $(Q)$(LINK) -shared $(LINKFLAGS) -o $@ $^
174
175 # Generic rules
176 UNUSED := $(shell mkdir -p $(libfirm_DIRS:%=$(builddir)/%))
177 $(builddir)/%.o: %.c $(IR_SPEC_GENERATED_FILES) config.h
178         @echo CC $@
179         $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) -MMD -c -o $@ $<
180
181 $(docdir)/libfirm.tag: $(IR_SPEC_GENERATED_FILES) Doxyfile $(wildcard include/libfirm/*.h) $(wildcard include/libfirm/adt/*.h)
182         @echo Doxygen $@
183         $(Q)$(DOXYGEN)
184
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
187         @echo gen_docu.py $@
188         $(Q)$(DOCU_GENERATOR) $(docdir)/libfirm.tag "" $@
189         $(Q)cp scripts/style.css $(docdir)/html
190
191 .PHONY: doc
192 doc: $(docdir)/libfirm.tag $(docdir)/html/nodes.html
193
194 .PHONY: clean
195 clean:
196         @echo CLEAN
197         $(Q)rm -f $(libfirm_OBJECTS)
198         $(Q)rm -f $(libfirm_TARGET)
199         $(Q)rm -f $(shell find ir/ -name "gen_*.[ch]")