aboutsummaryrefslogtreecommitdiff
path: root/Makefile.main
blob: 46af374f23cd4a329e30387abf129969d65f820e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# -*-Makefile-*-
#
# This is the main Makefile

# Target tools
CC=$(CROSS)gcc$(POSTFIX)
LD=$(CROSS)ld$(POSTFIX)
AS=$(CROSS)as
AR=$(CROSS)ar
NM=$(CROSS)nm
OBJCOPY=$(CROSS)objcopy
OBJDUMP=$(CROSS)objdump
SIZE=$(CROSS)size
LD_TEXT=0x0
NM += --synthetic

# Base warnings
CWARNS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
	  -Werror-implicit-function-declaration -Wdeclaration-after-statement \
	  -Wno-pointer-sign -Wextra -Wno-sign-compare \
	  -Wmissing-prototypes -Wmissing-declarations \
	  -Wwrite-strings -Wcast-align -Wjump-misses-init \
	  -Winit-self \
	  -Wsuggest-attribute=const \
	  -Wsuggest-attribute=noreturn \
	  -Wframe-larger-than=2048 \
	  -Wstack-usage=4096

# Host tools and options
HOSTCC=gcc
HOSTEND=$(shell uname -m | sed -e 's/^i.*86$$/LITTLE/' -e 's/^x86.*/LITTLE/' -e 's/^ppc.*/BIG/')
HOSTCFLAGS=-O1 $(CWARNS) -DHAVE_$(HOSTEND)_ENDIAN
VALGRIND=valgrind -q --show-reachable=yes --error-exitcode=99

# Target options

OPTS=-Os -ffunction-sections
DBG=-g

CPPFLAGS := -I$(SRC)/include -Iinclude -MMD -include $(SRC)/include/config.h
CPPFLAGS += -I$(SRC)/libfdt -I$(SRC)/libflash -I$(SRC)/libc/include -I$(SRC)
ifeq ($(PORE),1)
CPPFLAGS += -I$(SRC)/libpore -D__HAVE_LIBPORE__
endif
CPPFLAGS += -D__SKIBOOT__ -nostdinc
CPPFLAGS += -isystem $(shell $(CC) -print-file-name=include)
CPPFLAGS += -DBITS_PER_LONG=64 -m64 -DHAVE_BIG_ENDIAN
# We might want to remove our copy of stdint.h
# but that means uint64_t becomes an ulong instead of an ullong
# causing all our printf's to warn
CPPFLAGS += -ffreestanding

CFLAGS := -fno-strict-aliasing -fstack-protector-all -pie

ifeq ($(STACK_CHECK),1)
CFLAGS += -fstack-protector-all -pg
CPPFLAGS += -DSTACK_CHECK_ENABLED
else
# XXX Add -fstack-protector-strong on gcc 4.9
CFLAGS += -fstack-protector
endif

CFLAGS += $(CWARNS) $(OPTS) $(DBG)

LDFLAGS := -m64 -static -nostdlib -Wl,--gc-sections -pie
LDFLAGS += -Wl,-Ttext-segment,$(LD_TEXT) -Wl,-N -Wl,--build-id=none
LDFLAGS += -Wl,--no-multi-toc
LDRFLAGS=-melf64ppc
# Debug stuff
#LDFLAGS += -Wl,-v -Wl,-Map,foomap 

AFLAGS := -D__ASSEMBLY__ 

# Special tool flags:
# Do not use the floating point unit
CFLAGS += -msoft-float
# Do not use string instructions
CFLAGS += -mno-string
# do not use load/store multiple word instrcutions
CFLAGS += -mno-multiple
# Do not use load/store update. You REALLY do not want to use this!
# The async safety of the ABI stack depends on the atomicity
# of update on store.
#CFLAGS += -mno-update

ifneq ($(KERNEL),)
CPPFLAGS += -DBUILTIN_KERNEL="\"$(KERNEL)\""
endif

.SECONDARY:

vpath %.c $(SRC)
vpath %.S $(SRC)

default: all

include/asm-offsets.h: asm/asm-offsets.s
	@mkdir -p include
	$(call Q,GN, $(SRC)/make_offsets.sh $< >$@, $@)

TARGET = skiboot

include $(SRC)/asm/Makefile.inc
include $(SRC)/core/Makefile.inc
include $(SRC)/hw/Makefile.inc
include $(SRC)/platforms/Makefile.inc
include $(SRC)/libfdt/Makefile.inc
include $(SRC)/libflash/Makefile.inc
include $(SRC)/libpore/Makefile.inc
include $(SRC)/libc/Makefile.inc
include $(SRC)/ccan/Makefile.inc
include $(SRC)/$(DEVSRC)/Makefile.inc

all: $(SUBDIRS) $(TARGET).lid $(TARGET).map

OBJS := $(ASM) $(CORE) $(HW) $(PLATFORMS) $(LIBFDT) $(LIBFLASH)
ifeq ($(PORE),1)
OBJS += $(LIBPORE)
endif
OBJS += $(LIBC) $(CCAN) $(DEVSRC_OBJ)
OBJS_NO_VER = $(OBJS)
ALL_OBJS = $(OBJS) version.o

ALL_OBJS_1 = $(ALL_OBJS) asm/dummy_map.o
ALL_OBJS_2 = $(ALL_OBJS) asm/real_map.o

$(TARGET).lid: $(TARGET).elf
	$(call Q,OBJCOPY, $(OBJCOPY) -O binary -S $^ $@, $@)

$(TARGET).tmp.elf: $(ALL_OBJS_1) $(TARGET).lds $(KERNEL)
	$(call Q,LD, $(CC) $(LDFLAGS) -T $(TARGET).lds $(ALL_OBJS_1) -o $@, $@)

asm/real_map.o : $(TARGET).tmp.map

$(TARGET).elf: $(ALL_OBJS_2) $(TARGET).lds $(KERNEL)
	$(call Q,LD, $(CC) $(LDFLAGS) -T $(TARGET).lds $(ALL_OBJS_2) -o $@, $@)

$(SUBDIRS):
	$(call Q,MKDIR,mkdir $@, $@)

-include $(wildcard *.d)
-include $(wildcard $(SUBDIRS:%=%/*.d))

# Set V=1 if you want to see everything.
include $(SRC)/Makefile.rules

VERSION ?= $(shell cd $(SRC); GIT_DIR=$(SRC)/.git $(SRC)/make_version.sh)

.PHONY: VERSION-always
.version: VERSION-always
	@echo $(VERSION) > $@.tmp
	@cmp -s $@ $@.tmp || cp $@.tmp $@
	@rm -f $@.tmp

version.c: make_version.sh $(OBJS_NO_VER) .version
	@(if [ "a$(VERSION)" = "a" ]; then \
		echo "#error You need to set SKIBOOT_VERSION environment variable" > $@ ;\
        else \
                echo "const char version[] = \"$(VERSION)\";" ;\
        fi) > $@

.PHONY: coverage
include $(shell find $(SRC)/* -name Makefile.check)

coverage-report: skiboot.info
	genhtml -q -o $@ $<

skiboot.info: coverage
	lcov -q -c -d . -o $@


tags:
	find . -name '*.[chS]' | xargs ctags

TAGS:
	find . -name '*.[chS]' | xargs etags

.PHONY: tags TAGS check

cscope:
	find . -name '*.[chS]' | xargs cscope

clean:
	$(RM) *.[odsa] $(SUBDIRS:%=%/*.[odsa])
	$(RM) *.elf $(TARGET).lid *.map $(TARGET).lds
	$(RM) include/asm-offsets.h version.c

distclean: clean
	$(RM) *~ $(SUBDIRS:%=%/*~) include/*~