Makefile 5.63 KB
Newer Older
1
# Tomasz Wlostowski for CERN, 2011,2012
2
-include $(CURDIR)/.config
3

4
CROSS_COMPILE ?= lm32-elf-
5

6 7 8 9
ifdef CONFIG_HOST_PROCESS
  CROSS_COMPILE =
endif

10
export CROSS_COMPILE
11

12
CC =		$(CROSS_COMPILE)gcc
13
LD =		$(CROSS_COMPILE)ld
14 15 16 17
OBJDUMP =	$(CROSS_COMPILE)objdump
OBJCOPY =	$(CROSS_COMPILE)objcopy
SIZE =		$(CROSS_COMPILE)size

18

19
AUTOCONF = $(CURDIR)/include/generated/autoconf.h
20

21
PPSI = ppsi
Grzegorz Daniluk's avatar
Grzegorz Daniluk committed
22

23
# we miss CONFIG_ARCH_LM32 as we have no other archs by now
24
obj-$(CONFIG_LM32) = arch/lm32/crt0.o arch/lm32/irq.o
25 26
LDS-$(CONFIG_WR_NODE)   = arch/lm32/ram.ld
LDS-$(CONFIG_WR_SWITCH) = arch/lm32/ram-wrs.ld
27
LDS-$(CONFIG_HOST_PROCESS) =
28

29 30
obj-$(CONFIG_WR_NODE)   += wrc_main.o
obj-$(CONFIG_WR_SWITCH) += wrs_main.o
31
obj-$(CONFIG_WR_SWITCH) += ipc/minipc-mem-server.o ipc/rt_ipc.o
32

33
obj-y += dump-info.o
34
# our linker script is preprocessed, so have a rule here
35
%.ld: %.ld.S $(AUTOCONF) .config
36 37 38
	$(CC) -include $(AUTOCONF) -E -P $*.ld.S -o $@


39
cflags-y =	-ffreestanding -include $(AUTOCONF) -Iinclude \
40
			-I. -Isoftpll -Iipc
41
cflags-y +=	-I$(CURDIR)/pp_printf
42
cflags-$(CONFIG_LM32) +=  -Iinclude/std
43

44
cflags-$(CONFIG_PPSI) += \
45
	-include include/ppsi-wrappers.h \
46
	-I$(PPSI)/arch-wrpc \
47 48 49
	-I$(PPSI)/proto-ext-whiterabbit \
	-Iboards/spec

50 51 52 53 54
# in order to build tools/wrpc-dump, we need these flags, even for wrs builds
cflags-y += \
	-I$(PPSI)/arch-wrpc/include \
	-I$(PPSI)/include

55 56
obj-ppsi = $(PPSI)/ppsi.o
obj-$(CONFIG_PPSI) += $(obj-ppsi)
57

58 59
# Below, CONFIG_PPSI is wrong, as we can't build these for the host
obj-$(CONFIG_EMBEDDED_NODE) += \
60
	monitor/monitor_ppsi.o \
61
	lib/ppsi-wrappers.o
62

63 64
cflags-$(CONFIG_LM32) += -mmultiply-enabled -mbarrel-shift-enabled
ldflags-$(CONFIG_LM32) = -mmultiply-enabled -mbarrel-shift-enabled \
65
	-nostdlib -T $(LDS-y)
66

67
# packet-filter rules: for CONFIG_VLAN we use both sets
68
pfilter-y                     := rules-novlan.bin
69
pfilter-$(CONFIG_VLAN)        += rules-vlan.bin
70 71 72 73
export pfilter-y

all:

74
include shell/shell.mk
75
include lib/lib.mk
76
include pp_printf/printf.mk
77
include dev/dev.mk
78
include softpll/softpll.mk
79
include host/host.mk
80

81
# ppsi already has div64 (the same one), so only pick it if not using ppsi.
82
ifndef CONFIG_PPSI
83
  obj-y += pp_printf/div64.o
84 85
endif
# And always complain if we pick the libgcc division: 64/32 = 32 is enough here.
86
obj-$(CONFIG_LM32) += check-error.o
87

88 89 90
# add system check functions like stack overflow and check reset
obj-y += system_checks.o

91
# WR node has SDB support, WR switch does not
92 93
obj-$(CONFIG_WR_NODE) += sdb-lib/libsdbfs.a
cflags-$(CONFIG_WR_NODE) += -Isdb-lib
94

95
CFLAGS = $(cflags-y) -Wall -Wstrict-prototypes \
96
	-ffunction-sections -fdata-sections -Os -Wmissing-prototypes \
97
	-include include/wrc.h -ggdb
98

99
LDFLAGS = $(ldflags-y) \
100
	-Wl,--gc-sections -Os -lgcc -lc
101

102 103
WRC-O-FLAGS-$(CONFIG_LM32) = --gc-sections -e _start

104
OBJS = $(obj-y)
105

106 107 108
OUTPUT-$(CONFIG_WR_NODE)   = wrc
OUTPUT-$(CONFIG_WR_SWITCH) = rt_cpu
OUTPUT := $(OUTPUT-y)
109

110
GIT_VER = $(shell git describe --always --dirty | sed  's;^wr-switch-sw-;;')
111

112
all: tools $(OUTPUT).ram $(OUTPUT).vhd $(OUTPUT).mif
113

114
.PRECIOUS: %.elf %.bin
115
.PHONY: all tools clean gitmodules $(PPSI)/ppsi.o
116

117 118
# we need to remove "ptpdump" support for ppsi if RAM size is small and
# we include etherbone
119
ifneq ($(CONFIG_RAMSIZE),131072)
120
  ifdef CONFIG_IP
121 122 123 124 125 126
    PPSI_USER_CFLAGS = -DCONFIG_NO_PTPDUMP
  endif
endif

PPSI_USER_CFLAGS += -DDIAG_PUTS=uart_sw_write_string

127
PPSI-CFG-y = wrpc_defconfig
128
PPSI-CFG-$(CONFIG_HOST_PROCESS) = unix_defconfig
129 130
PPSI-FLAGS-$(CONFIG_LM32) = CONFIG_NO_PRINTF=y

131
$(obj-ppsi):
132 133 134
	test -f $(PPSI)/.config || $(MAKE) -C $(PPSI) $(PPSI-CFG-y)
	$(MAKE) -C $(PPSI) ppsi.o WRPCSW_ROOT=.. \
		CROSS_COMPILE=$(CROSS_COMPILE) CONFIG_NO_PRINTF=y
135
		USER_CFLAGS="$(PPSI_USER_CFLAGS)"
136

137 138
sdb-lib/libsdbfs.a:
	$(MAKE) -C sdb-lib
139

140
$(OUTPUT).elf: $(LDS-y) $(AUTOCONF) gitmodules $(OUTPUT).o config.o
141
	$(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -c revision.c
142
	${CC} -o $@ revision.o config.o $(OUTPUT).o $(LDFLAGS)
143
	${OBJDUMP} -d $(OUTPUT).elf > $(OUTPUT)_disasm.S
144 145
	$(SIZE) $@

146
$(OUTPUT).o: $(OBJS)
147 148 149
	$(LD) $(WRC-O-FLAGS-y) -r $(OBJS) -T bigobj.lds -o $@

OBJCOPY-TARGET-$(CONFIG_LM32) = -O elf32-lm32 -B lm32
150
OBJCOPY-TARGET-$(CONFIG_HOST_PROCESS) = -O elf64-x86-64 -B i386
151

152 153 154
config.o: .config
	sed '1,3d' .config > .config.bin
	dd bs=1 count=1 if=/dev/zero 2> /dev/null >> .config.bin
155
	$(OBJCOPY) -I binary $(OBJCOPY-TARGET-y) \
156 157 158
		--rename-section .data=.data.config  .config.bin $@
	rm -f .config.bin

159 160 161 162 163 164 165
%.bin: %.elf
	${OBJCOPY} -O binary $^ $@

%.ram: tools %.bin
	./tools/genraminit $*.bin 0 > $@

%.vhd: tools %.bin
166
	./tools/genramvhd -s $(CONFIG_RAMSIZE) $*.bin > $@
167 168

%.mif: tools %.bin
169
	./tools/genrammif $*.bin $(CONFIG_RAMSIZE) > $@
Grzegorz Daniluk's avatar
Grzegorz Daniluk committed
170

171 172
$(AUTOCONF): silentoldconfig

173
clean:
174
	rm -f $(OBJS) $(OUTPUT).elf $(OUTPUT).bin $(OUTPUT).ram \
175
		$(LDS)  rules-*.bin
176
	$(MAKE) -C $(PPSI) clean
177
	$(MAKE) -C sdb-lib clean
Theodor-Adrian Stana's avatar
Theodor-Adrian Stana committed
178
	$(MAKE) -C tools clean
179 180

%.o:		%.c
181
	${CC} $(CFLAGS) $(PTPD_CFLAGS) $(INCLUDE_DIR) $(LIB_DIR) -c $*.c -o $@
182

183
tools: .config
184
	$(MAKE) -C tools
185

186 187 188
# if needed, check out the submodules (first time only), so users
# who didn't read carefully the manual won't get confused
gitmodules:
189
	@test -d ppsi/arch-wrpc || echo "Checking out submodules"
190
	@test -d ppsi/arch-wrpc || git submodule update --init
191 192


193 194 195
# following targets from Makefile.kconfig
silentoldconfig:
	@mkdir -p include/config
196
	$(MAKE) quiet=quiet_ -f Makefile.kconfig $@
197

198
scripts_basic config:
199
	$(MAKE) quiet=quiet_ -f Makefile.kconfig $@
200 201

%config:
202
	$(MAKE) quiet=quiet_ -f Makefile.kconfig $@
203

204
defconfig:
205
	$(MAKE) quiet=quiet_ -f Makefile.kconfig spec_defconfig
206

207
.config: silentoldconfig
208

209 210 211 212
# This forces more compilations than needed, but it's useful
# (we depend on .config and not on include/generated/autoconf.h
# because the latter is touched by silentoldconfig at each build)
$(obj-y): .config $(wildcard include/*.h)