Makefile 7.62 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
export CONFIG_ABSCAL
12

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

19

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

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

24 25 26
# list of file extensions to be copied for MAKEALL script
MAKEALL_COPY_LIST=.bin .elf

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

33
obj-$(CONFIG_WR_NODE)   += wrc_main.o
34
obj-$(CONFIG_WR_NODE_SIM) += wrc_main_sim.o
35
obj-$(CONFIG_WR_SWITCH) += wrs_main.o
36
obj-$(CONFIG_WR_SWITCH) += ipc/minipc-mem-server.o ipc/rt_ipc.o
37

38
obj-y += dump-info.o
39
# our linker script is preprocessed, so have a rule here
40
%.ld: %.ld.S $(AUTOCONF) .config
41 42 43
	$(CC) -include $(AUTOCONF) -E -P $*.ld.S -o $@


44
cflags-y =	-ffreestanding -include $(AUTOCONF) -Iinclude \
45
			-I. -Isoftpll -Iipc
46
cflags-y +=	-I$(CURDIR)/pp_printf
47
cflags-$(CONFIG_LM32) +=  -Iinclude/std
48

49
cflags-$(CONFIG_PPSI) += \
50
	-include include/ppsi-wrappers.h \
51
	-I$(PPSI)/arch-wrpc \
52 53 54
	-I$(PPSI)/proto-ext-whiterabbit \
	-Iboards/spec

55 56 57 58 59
# 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

60 61
obj-ppsi = $(PPSI)/ppsi.o
obj-$(CONFIG_PPSI) += $(obj-ppsi)
62

63 64
# Below, CONFIG_PPSI is wrong, as we can't build these for the host
obj-$(CONFIG_EMBEDDED_NODE) += \
65
	monitor/monitor_ppsi.o \
66
	lib/ppsi-wrappers.o
67

68 69
cflags-$(CONFIG_LM32) += -mmultiply-enabled -mbarrel-shift-enabled
ldflags-$(CONFIG_LM32) = -mmultiply-enabled -mbarrel-shift-enabled \
70
	-nostdlib -T $(LDS-y)
71
arch-files-$(CONFIG_LM32) = $(OUTPUT).bram $(OUTPUT).vhd $(OUTPUT).mif
72

73

74
# packet-filter rules: for CONFIG_VLAN we use both sets
75
pfilter-y                     := rules-novlan.bin
76
pfilter-$(CONFIG_VLAN)        += rules-vlan.bin
77 78
export pfilter-y

79 80 81 82
# sdbfs image
sdbfsimg-y	:=	sdbfs-default.bin
export sdbfsimg-y

83 84
all:

85
include shell/shell.mk
86
include lib/lib.mk
87
include pp_printf/printf.mk
88
include dev/dev.mk
89
include softpll/softpll.mk
90
include host/host.mk
91

92
# ppsi already has div64 (the same one), so only pick it if not using ppsi.
93
ifndef CONFIG_PPSI
94
  obj-y += pp_printf/div64.o
95 96
endif
# And always complain if we pick the libgcc division: 64/32 = 32 is enough here.
97
obj-$(CONFIG_LM32) += check-error.o
98

99 100 101
# add system check functions like stack overflow and check reset
obj-y += system_checks.o

102
# WR node has SDB support, WR switch does not
103 104
obj-$(CONFIG_WR_NODE) += sdb-lib/libsdbfs.a
cflags-$(CONFIG_WR_NODE) += -Isdb-lib
105

106
CFLAGS = $(cflags-y) -Wall -Wstrict-prototypes \
107
	-ffunction-sections -fdata-sections -Os -Wmissing-prototypes \
108
	-include include/wrc.h -ggdb
109

110
# Assembler Flags
111 112
ASFLAGS = -I.

113
LDFLAGS = $(ldflags-y) \
114
	-Wl,--gc-sections -Os -lgcc -lc
115

116 117
WRC-O-FLAGS-$(CONFIG_LM32) = --gc-sections -e _start

118
OBJS = $(obj-y)
119

120 121 122
OUTPUT-$(CONFIG_WR_NODE)   = wrc
OUTPUT-$(CONFIG_WR_SWITCH) = rt_cpu
OUTPUT := $(OUTPUT-y)
123

124
GIT_VER = $(shell git describe --always --dirty | sed  's;^wr-switch-sw-;;')
Adam Wujek's avatar
Adam Wujek committed
125
GIT_USR = $(shell git config --get-all user.name)
126 127
export GIT_VER
export GIT_USR
Adam Wujek's avatar
Adam Wujek committed
128 129 130 131 132

# if user.name is not available from git use user@hostname
ifeq ($(GIT_USR),)
GIT_USR = $(shell whoami)@$(shell hostname)
endif
133

134
all: tools $(OUTPUT).elf $(arch-files-y)
135

136
.PRECIOUS: %.elf %.bin
137
.PHONY: all tools clean gitmodules $(PPSI)/ppsi.o extest liblinux
138

139 140
# we need to remove "ptpdump" support for ppsi if RAM size is small and
# we include etherbone
141
ifneq ($(CONFIG_RAMSIZE),131072)
142
  ifdef CONFIG_IP
143 144 145 146
    PPSI_USER_CFLAGS = -DCONFIG_NO_PTPDUMP
  endif
endif

147
PPSI-CFG-y = wrpc_defconfig
148
PPSI-CFG-$(CONFIG_P2P) = wrpc_pdelay_defconfig
149
PPSI-CFG-$(CONFIG_HOST_PROCESS) = unix_defconfig
150 151
PPSI-FLAGS-$(CONFIG_LM32) = CONFIG_NO_PRINTF=y

152
$(obj-ppsi): gitmodules
153
	test -s $(PPSI)/.config || $(MAKE) -C $(PPSI) $(PPSI-CFG-y)
154 155 156 157 158
	@if [ "$(CONFIG_PPSI_FORCE_CONFIG)" = "y" ]; then \
		$(MAKE) -C $(PPSI) $(PPSI-CFG-y); \
	else \
		echo "Warning: keeping previous ppsi configuration" >& 2; \
	fi
159 160
	$(MAKE) -C $(PPSI) ppsi.o WRPCSW_ROOT=.. \
		CROSS_COMPILE=$(CROSS_COMPILE) CONFIG_NO_PRINTF=y
161
		USER_CFLAGS="$(PPSI_USER_CFLAGS)"
162

163 164
sdb-lib/libsdbfs.a:
	$(MAKE) -C sdb-lib
165

166
$(OUTPUT).elf: $(LDS-y) $(AUTOCONF) gitmodules $(OUTPUT).o config.o pconfig.o
Adam Wujek's avatar
Adam Wujek committed
167
	$(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\"" -c revision.c
168
	${CC} -o $@ revision.o config.o pconfig.o $(OUTPUT).o $(LDFLAGS)
169
	${OBJDUMP} -d $(OUTPUT).elf > $(OUTPUT)_disasm.S
170
	$(SIZE) $@
171
	./save_size.sh $(SIZE) $@
172

173
$(OUTPUT).o: $(OBJS)
174 175 176
	$(LD) $(WRC-O-FLAGS-y) -r $(OBJS) -T bigobj.lds -o $@

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

179
config.o: .config $(AUTOCONF)
180
	grep CONFIG .config > .config.bin
181
	dd bs=1 count=1 if=/dev/zero 2> /dev/null >> .config.bin
182
	$(OBJCOPY) -I binary $(OBJCOPY-TARGET-y) .config.bin $@
183 184
	rm -f .config.bin

185 186 187 188 189 190 191 192
ppsi/.config: $(obj-ppsi)

pconfig.o: ppsi/.config
	grep CONFIG ppsi/.config > .ppsiconfig.bin
	dd bs=1 count=1 if=/dev/zero 2> /dev/null >> .ppsiconfig.bin
	$(OBJCOPY) -I binary $(OBJCOPY-TARGET-y) .ppsiconfig.bin $@
	rm -f .ppsiconfig.bin

193 194 195
%.bin: %.elf
	${OBJCOPY} -O binary $^ $@

196 197
%.bram: tools %.bin
	./tools/genraminit $*.bin $(CONFIG_RAMSIZE) > $@
198 199

%.vhd: tools %.bin
200
	./tools/genramvhd -s $(CONFIG_RAMSIZE) $*.bin > $@
201 202

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

205
$(AUTOCONF): silentoldconfig gitmodules
206

207
clean:
208 209
	rm -f $(OBJS) $(OUTPUT).o config.o pconfig.o revision.o $(OUTPUT).elf \
		$(LDS) \
210 211
		$(OUTPUT).bin rules-*.bin \
		$(OUTPUT).bram $(OUTPUT).vhd $(OUTPUT).mif $(OUTPUT)_disasm.S
212
	$(MAKE) -C $(PPSI) clean
213
	$(MAKE) -C sdb-lib clean
Theodor-Adrian Stana's avatar
Theodor-Adrian Stana committed
214
	$(MAKE) -C tools clean
215 216
	$(MAKE) -C liblinux clean
	$(MAKE) -C liblinux/extest clean
217

218 219 220
distclean: clean
	rm -rf include/config
	rm -rf include/generated
221
	rm -f $(addprefix *,$(MAKEALL_COPY_LIST))
222
	$(MAKE) -C $(PPSI) distclean
223

224
%.o:		%.c
225
	${CC} $(CFLAGS) $(PTPD_CFLAGS) $(INCLUDE_DIR) $(LIB_DIR) -c $*.c -o $@
226

227
liblinux:
228
	$(MAKE) -C liblinux CC=cc
229 230

extest:
231
	$(MAKE) -C liblinux/extest CC=cc
232 233

tools: .config gitmodules liblinux extest
234
	$(MAKE) -C tools
235

236 237 238
tools-diag: liblinux extest
	$(MAKE) -C tools wrpc-diags wrpc-vuart wr-streamers

239 240 241
# if needed, check out the submodules (first time only), so users
# who didn't read carefully the manual won't get confused
gitmodules:
242
	@test -d ppsi/arch-wrpc || echo "Checking out submodules"
243
	@test -d ppsi/arch-wrpc || git submodule update --init
244

245 246 247 248
# Explicit rule for $(CURDIR)/.config
# needed since -include XXX triggers build for XXX
$(CURDIR)/.config:
	@# Keep this dummy comment
249

250 251 252
# following targets from Makefile.kconfig
silentoldconfig:
	@mkdir -p include/config
253
	$(MAKE) quiet=quiet_ -f Makefile.kconfig $@
254

255
scripts_basic config:
256
	$(MAKE) quiet=quiet_ -f Makefile.kconfig $@
257

258
%config:
259
	$(MAKE) quiet=quiet_ -f Makefile.kconfig $@
260

261
defconfig:
262
	$(MAKE) quiet=quiet_ -f Makefile.kconfig spec_defconfig
263

264
.config: silentoldconfig
265

266 267 268 269
# 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)
270

271 272 273 274
# if DEFCONFIG_NAME is not defined assign anything to it.
# It will limit matching of the target below
DEFCONFIG_NAME?="some_unique_dummy_name"

275
# copy compiled files for MAKEALL script
276 277
# files like $(DEFCONFIG_NAME).[elf|bin] etc.
$(addprefix $(DEFCONFIG_NAME),$(MAKEALL_COPY_LIST)):
278 279 280
	@cp -f $(OUTPUT)$(suffix $@) $@

makeall_copy: $(addprefix $(DEFCONFIG_NAME),$(MAKEALL_COPY_LIST))