Makefile 5.85 KB
Newer Older
Matthias Braun's avatar
Matthias Braun committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# libfirm Makefile
#
# This is currently experimental and not fully supported, but we plan to replace
# the jambuild with this at some point in the future.
#
# Most variable names are similar to the names used by autoconf...
-include config.mak

# Some build configuration defaults
top_srcdir   ?=
top_builddir ?= build
host         ?= unknown-host
variant      ?= debug

srcdir       ?= $(top_srcdir)
builddir     ?= $(top_builddir)/$(variant)
Matthias Braun's avatar
Matthias Braun committed
17
docdir       ?= $(top_builddir)/doc
Matthias Braun's avatar
Matthias Braun committed
18
19
20
21
22

# This hides the noisy commandline outputs. You can see them with "make Q="
Q ?= @

CC ?= cc
23
DOXYGEN ?= doxygen
Matthias Braun's avatar
Matthias Braun committed
24
LINK ?= $(CC)
25
AR ?= ar
26
DLLEXT ?= .so
Matthias Braun's avatar
Matthias Braun committed
27
28

# Variants
Christoph Mallon's avatar
Christoph Mallon committed
29
CFLAGS_all        = -std=c99 -fPIC -DHAVE_FIRM_REVISION_H
30
31
CFLAGS_debug      = $(CFLAGS_all) -O0 -g3 -DDEBUG_libfirm
CFLAGS_profile    = $(CFLAGS_all) -O3 -pg -DNDEBUG -fno-inline
32
CFLAGS_coverage   = $(CFLAGS_all) -O0 --coverage -DDEBUG_libfirm
Andreas Zwinkau's avatar
Andreas Zwinkau committed
33
LINKFLAGS_debug    =
34
LINKFLAGS_profile  = -pg
35
36
LINKFLAGS_coverage = --coverage
CFLAGS_optimize   = $(CFLAGS_all) -O3 -fomit-frame-pointer -DNDEBUG
Matthias Braun's avatar
Matthias Braun committed
37
38

# General flags
Andreas Zwinkau's avatar
Andreas Zwinkau committed
39
CPPFLAGS  ?=
Matthias Braun's avatar
Matthias Braun committed
40
41
CFLAGS    += $(CFLAGS_$(variant))
CFLAGS    += -Wall -W -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings
Matthias Braun's avatar
Matthias Braun committed
42
LINKFLAGS += $(LINKFLAGS_$(variant)) -lm
Matthias Braun's avatar
Matthias Braun committed
43
44
VPATH = $(srcdir)

45
46
47
48
49
50
51
52
REVISION ?= $(shell git describe --abbrev=40 --always --dirty --match '')

# Update revision.h if necessary
UNUSED := $(shell \
	REV="\#define libfirm_VERSION_REVISION \"$(REVISION)\""; \
	echo "$$REV" | cmp -s - firm_revision.h 2> /dev/null || echo "$$REV" > firm_revision.h \
)

Matthias Braun's avatar
Matthias Braun committed
53
all: firm
54
55
56
57
.PHONY: all

# disable make builtin suffix rules
.SUFFIXES:
Matthias Braun's avatar
Matthias Braun committed
58

59
60
61
62
63
# This rule is necessary so that make does not abort if headers get deleted
# (the deleted header might still be referenced in a .d file)
%.h:
	@:

Matthias Braun's avatar
Matthias Braun committed
64
65
66
67
68
69
# A very naive way to create a config.h if it is missing
$(srcdir)config.h:
	@echo MakeConfig $@
	$(Q)rm -f $@
	$(Q)echo "#define libfirm_VERSION_MAJOR 1" >> $@
	$(Q)echo "#define libfirm_VERSION_MICRO 0" >> $@
Matthias Braun's avatar
Matthias Braun committed
70
	$(Q)echo "#define libfirm_VERSION_MINOR 21" >> $@
Matthias Braun's avatar
Matthias Braun committed
71
72

# libFirm
73
74
libfirm_SOURCES  = $(wildcard ir/*/*.c)
libfirm_DIRS     = $(sort $(dir $(libfirm_SOURCES)))
Matthias Braun's avatar
Matthias Braun committed
75
libfirm_a        = $(builddir)/libfirm.a
76
libfirm_dll      = $(builddir)/libfirm$(DLLEXT)
Matthias Braun's avatar
Matthias Braun committed
77
78
79
libfirm_CPPFLAGS = -Iinclude/libfirm -Iinclude/libfirm/adt -I. $(foreach dir,$(libfirm_DIRS),-I$(dir))

.PHONY: firm
80
firm: $(libfirm_dll)
Matthias Braun's avatar
Matthias Braun committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

# backends
backends = amd64 arm ia32 sparc TEMPLATE

EMITTER_GENERATOR = $(srcdir)ir/be/scripts/generate_emitter.pl
REGALLOC_IF_GENERATOR = $(srcdir)ir/be/scripts/generate_regalloc_if.pl
OPCODES_GENERATOR = $(srcdir)ir/be/scripts/generate_new_opcodes.pl

define backend_template
$(1)_SOURCES = $$(wildcard ir/be/$(1)/*.c)
$(1)_SOURCES := $$(filter-out ir/be/$(1)/gen_%.c, $$($(1)_SOURCES))
$(1)_GEN_HEADERS =

$(1)_SPEC = ir/be/$(1)/$(1)_spec.pl

96
$$(srcdir)ir/be/$(1)/gen_$(1)_emitter.h $$(srcdir)ir/be/$(1)/gen_$(1)_emitter.c: $$($(1)_SPEC) $$(EMITTER_GENERATOR)
Matthias Braun's avatar
Matthias Braun committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
	@echo GEN $$@
	$(Q)$$(EMITTER_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
$(1)_SOURCES += ir/be/$(1)/gen_$(1)_emitter.c
$(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_emitter.h

$$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.h $$(srcdir)ir/be/$(1)/gen_$(1)_regalloc_if.c: $$($(1)_SPEC) $$(REGALLOC_IF_GENERATOR)
	@echo GEN $$@
	$(Q)$$(REGALLOC_IF_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
$(1)_SOURCES += ir/be/$(1)/gen_$(1)_regalloc_if.c
$(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_regalloc_if.h

$$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.h $$(srcdir)ir/be/$(1)/gen_$(1)_new_nodes.c.inl: $$($(1)_SPEC) $$(OPCODES_GENERATOR)
	@echo GEN $$@
	$(Q)$$(OPCODES_GENERATOR) $$($(1)_SPEC) $$(srcdir)ir/be/$(1)
$(1)_GEN_HEADERS += ir/be/$(1)/gen_$(1)_new_nodes.h

ir/be/$(1)/$(1)_new_nodes.c: ir/be/$(1)/gen_$(1)_new_nodes.c.inl

# We need to inform make of the headers it doesn't know yet...
$(1)_OBJECTS = $$($(1)_SOURCES:%.c=$$(builddir)/%.o)
$$($(1)_OBJECTS): $$($(1)_GEN_HEADERS)

libfirm_SOURCES += $$($(1)_SOURCES)
libfirm_DIRS += ir/be/$(1)
endef

$(foreach backend,$(backends),$(eval $(call backend_template,$(backend))))

# generators
IR_SPEC_GENERATED_FILES := \
	include/libfirm/nodeops.h \
	include/libfirm/opcodes.h \
	ir/ir/gen_ir_cons.c.inl   \
	ir/ir/gen_irop.c.inl      \
	ir/ir/gen_irnode.c.inl    \
	ir/ir/gen_irnode.h
IR_SPEC_GENERATOR := scripts/gen_ir.py
IR_SPEC := scripts/ir_spec.py

$(IR_SPEC_GENERATED_FILES): $(IR_SPEC_GENERATOR) $(IR_SPEC) scripts/spec_util.py
	@echo GEN $@
	$(Q)$(IR_SPEC_GENERATOR) $(IR_SPEC) ir/ir

IR_IO_GENERATOR := scripts/gen_ir_io.py
141
IR_IO_GENERATED_FILES := ir/ir/gen_irio.inl
Matthias Braun's avatar
Matthias Braun committed
142
143
144
145
146
147
148
149
150
151
152
153
154

$(IR_IO_GENERATED_FILES): $(IR_IO_GENERATOR) $(IR_SPEC) scripts/spec_util.py
	@echo GEN $@
	$(Q)$(IR_IO_GENERATOR) $(IR_SPEC) ir/ir

ir/ir/irio.c: $(IR_IO_GENERATED_FILES)

libfirm_OBJECTS = $(libfirm_SOURCES:%.c=$(builddir)/%.o)
libfirm_DEPS    = $(libfirm_OBJECTS:%.o=%.d)
-include $(libfirm_DEPS)

$(libfirm_a): $(libfirm_OBJECTS)
	@echo AR $@
155
	$(Q)$(AR) -cru $@ $^
Matthias Braun's avatar
Matthias Braun committed
156

157
$(libfirm_dll): $(libfirm_OBJECTS)
Matthias Braun's avatar
Matthias Braun committed
158
	@echo LINK $@
Matthias Braun's avatar
Matthias Braun committed
159
	$(Q)$(LINK) -shared $(LINKFLAGS) -o $@ $^
Matthias Braun's avatar
Matthias Braun committed
160
161
162

# Generic rules
UNUSED := $(shell mkdir -p $(libfirm_DIRS:%=$(builddir)/%))
163
164
165
# Determine if we can use cparser-beta for quickcheck
QUICKCHECK ?= $(shell which cparser-beta || echo true) -fsyntax-only

Matthias Braun's avatar
Matthias Braun committed
166
167
$(builddir)/%.o: %.c $(IR_SPEC_GENERATED_FILES) config.h
	@echo CC $@
168
	$(Q)$(QUICKCHECK) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) $<
Matthias Braun's avatar
Matthias Braun committed
169
170
	$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(libfirm_CPPFLAGS) -MMD -c -o $@ $<

171
$(docdir)/libfirm.tag: $(IR_SPEC_GENERATED_FILES) Doxyfile $(wildcard include/libfirm/*.h) $(wildcard include/libfirm/adt/*.h)
Matthias Braun's avatar
Matthias Braun committed
172
	@echo Doxygen $@
173
174
175
	$(Q)$(DOXYGEN)

DOCU_GENERATOR := scripts/gen_docu.py
176
$(docdir)/html/nodes.html: $(docdir)/libfirm.tag $(DOCU_GENERATOR) $(IR_SPEC) scripts/spec_util.py scripts/style.css
Matthias Braun's avatar
Matthias Braun committed
177
	@echo gen_docu.py $@
Matthias Braun's avatar
Matthias Braun committed
178
	$(Q)$(DOCU_GENERATOR) $(IR_SPEC) $(docdir)/libfirm.tag "" $@
179
	$(Q)cp scripts/style.css $(docdir)/html
180

Matthias Braun's avatar
Matthias Braun committed
181
182
.PHONY: doc
doc: $(docdir)/libfirm.tag $(docdir)/html/nodes.html
183

Matthias Braun's avatar
Matthias Braun committed
184
185
186
.PHONY: clean
clean:
	@echo CLEAN
187
	$(Q)rm -fr $(builddir) $(shell find ir/ -name "gen_*.[ch]")