Makefile 7.64 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
export CONFIG_DUALPORT
13

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

20

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

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

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

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

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

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


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

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

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

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

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

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

74

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

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

84 85
all:

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

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

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

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

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

111
# Assembler Flags
112 113
ASFLAGS = -I.

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

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

119
OBJS = $(obj-y)
120

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

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

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

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

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

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

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

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

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

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

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

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

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

186 187 188 189 190 191 192 193
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

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

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

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

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

206
$(AUTOCONF): silentoldconfig gitmodules
207

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

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

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

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

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

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

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

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

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

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

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

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

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

265
.config: silentoldconfig
266

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

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

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

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