Add -c to ar to remove a diagnostic, when the archive is created.
[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
24 DLLEXT ?= .so
25
26 # Variants
27 CFLAGS_all        = -fPIC
28 CFLAGS_debug      = $(CFLAGS_all) -O0 -g3 -DDEBUG_libfirm
29 CFLAGS_profile    = $(CFLAGS_all) -O3 -pg -DNDEBUG -fno-inline
30 LINKFLAGS_profile = -pg
31 CFLAGS_optimize   = $(CFLAGS_all) -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 REVISION ?= $(shell git describe --abbrev=40 --always --dirty --match '')
40
41 # Update revision.h if necessary
42 UNUSED := $(shell \
43         REV="\#define libfirm_VERSION_REVISION \"$(REVISION)\""; \
44         echo "$$REV" | cmp -s - firm_revision.h 2> /dev/null || echo "$$REV" > firm_revision.h \
45 )
46
47 .PHONY: all
48 all: firm
49
50 # This rule is necessary so that make does not abort if headers get deleted
51 # (the deleted header might still be referenced in a .d file)
52 %.h:
53         @:
54
55 # A very naive way to create a config.h if it is missing
56 $(srcdir)config.h:
57         @echo MakeConfig $@
58         $(Q)rm -f $@
59         $(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
60         $(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
61         $(Q)echo "#define libfirm_VERSION_MINOR 20" >> $@
62
63 # libFirm
64 libfirm_DIRS := \
65         ir         \
66         ir/adt     \
67         ir/ana     \
68         ir/arch    \
69         ir/common  \
70         ir/debug   \
71         ir/obstack \
72         ir/ident   \
73         ir/net     \
74         ir/ir      \
75         ir/lower   \
76         ir/libcore \
77         ir/lpp     \
78         ir/opt     \
79         ir/st      \
80         ir/stat    \
81         ir/tr      \
82         ir/tv      \
83         ir/kaps    \
84         ir/be
85 libfirm_SOURCES  = $(foreach dir,$(libfirm_DIRS),$(wildcard $(dir)/*.c))
86 libfirm_a        = $(builddir)/libfirm.a
87 libfirm_dll      = $(builddir)/libfirm$(DLLEXT)
88 libfirm_CPPFLAGS = -Iinclude/libfirm -Iinclude/libfirm/adt -I. $(foreach dir,$(libfirm_DIRS),-I$(dir))
89
90 .PHONY: firm
91 firm: $(libfirm_dll)
92
93 # backends
94 backends = amd64 arm ia32 sparc TEMPLATE
95
96 EMITTER_GENERATOR = $(srcdir)ir/be/scripts/generate_emitter.pl
97 EMITTER_GENERATOR2 = $(srcdir)ir/be/scripts/generate_emitter_new.pl
98 REGALLOC_IF_GENERATOR = $(srcdir)ir/be/scripts/generate_regalloc_if.pl
99 OPCODES_GENERATOR = $(srcdir)ir/be/scripts/generate_new_opcodes.pl
100
101 define backend_template
102 $(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
103 $(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
104 $(1)_GEN_HEADERS =
105
106 $(1)_SPEC = ir/be/$(1)/$(1)_spec.pl
107
108 $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR) $(EMITTER_GENERATOR2)
109         @echo GEN $$@
110         $(Q)$$(EMITTER_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
111 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_emitter.c
112 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_emitter.h
113
114 $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
115         @echo GEN $$@
116         $(Q)$$(REGALLOC_IF_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
117 $(1)_SOURCES += ir/be/$(1)/gen_$(1)_regalloc_if.c
118 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_regalloc_if.h
119
120 $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
121         @echo GEN $$@
122         $(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
123 $(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h
124
125 ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl
126
127 # We need to inform make of the headers it doesn't know yet...
128 $(1)_OBJECTS = $$($(1)_SOURCES:%.c=$$(builddir)/%.o)
129 $$($(1)_OBJECTS): $$($(1)_GEN_HEADERS)
130
131 libfirm_SOURCES += $$($(1)_SOURCES)
132 libfirm_DIRS += ir/be/$(1)
133 endef
134
135 $(foreach backend,$(backends),$(eval $(call backend_template,$(backend))))
136
137 # generators
138 IR_SPEC_GENERATED_FILES := \
139         include/libfirm/nodeops.h \
140         include/libfirm/opcodes.h \
141         ir/ir/gen_ir_cons.c.inl   \
142         ir/ir/gen_irop.c.inl      \
143         ir/ir/gen_irnode.c.inl    \
144         ir/ir/gen_irnode.h
145 IR_SPEC_GENERATOR := scripts/gen_ir.py
146 IR_SPEC := scripts/ir_spec.py
147
148 $(IR_SPEC_GENERATED_FILES): $(IR_SPEC_GENERATOR) $(IR_SPEC) scripts/spec_util.py
149         @echo GEN $@
150         $(Q)$(IR_SPEC_GENERATOR) $(IR_SPEC) ir/ir
151
152 IR_IO_GENERATOR := scripts/gen_ir_io.py
153 IR_IO_GENERATED_FILES := ir/ir/gen_irio.inl
154
155 $(IR_IO_GENERATED_FILES): $(IR_IO_GENERATOR) $(IR_SPEC) scripts/spec_util.py
156         @echo GEN $@
157         $(Q)$(IR_IO_GENERATOR) $(IR_SPEC) ir/ir
158
159 ir/ir/irio.c: $(IR_IO_GENERATED_FILES)
160
161 libfirm_OBJECTS = $(libfirm_SOURCES:%.c=$(builddir)/%.o)
162 libfirm_DEPS    = $(libfirm_OBJECTS:%.o=%.d)
163 -include $(libfirm_DEPS)
164
165 $(libfirm_a): $(libfirm_OBJECTS)
166         @echo AR $@
167         $(Q)$(AR) -cru $@ $^
168
169 $(libfirm_dll): $(libfirm_OBJECTS)
170         @echo LINK $@
171         $(Q)$(LINK) -shared -o $@ $^
172
173 # Generic rules
174 UNUSED := $(shell mkdir -p $(libfirm_DIRS:%=$(builddir)/%))
175 $(builddir)/%.o: %.c $(IR_SPEC_GENERATED_FILES) config.h
176         @echo CC $@
177         $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) -MMD -c -o $@ $<
178
179 .PHONY: clean
180 clean:
181         @echo CLEAN
182         $(Q)rm -f $(libfirm_OBJECTS)
183         $(Q)rm -f $(libfirm_TARGET)
184         $(Q)rm -f $(shell find ir/ -name "gen_*.[ch]")