Makefile 4.61 KB
Newer Older
1 2
# Tomasz Wlostowski for CERN, 2011,2012

3
CROSS_COMPILE ?= lm32-elf-
4

5
CC =		$(CROSS_COMPILE)gcc
6
LD =		$(CROSS_COMPILE)ld
7 8 9 10
OBJDUMP =	$(CROSS_COMPILE)objdump
OBJCOPY =	$(CROSS_COMPILE)objcopy
SIZE =		$(CROSS_COMPILE)size

11 12
-include $(CURDIR)/.config

13
AUTOCONF = $(CURDIR)/include/generated/autoconf.h
14

15
PTP_NOPOSIX = ptp-noposix
16
PPSI = ppsi
Grzegorz Daniluk's avatar
Grzegorz Daniluk committed
17

18
# we miss CONFIG_ARCH_LM32 as we have no other archs by now
19
obj-y = arch/lm32/crt0.o arch/lm32/irq.o arch/lm32/debug.o
20
LDS = arch/lm32/ram.ld
21

22
obj-y += wrc_main.o
23 24 25
obj-y += softpll/softpll_ng.o


26 27 28 29 30
# our linker script is preprocessed, so have a rule here
%.ld: %.ld.S $(AUTOCONF)
	$(CC) -include $(AUTOCONF) -E -P $*.ld.S -o $@


31 32
cflags-y =	-ffreestanding -include $(AUTOCONF) -Iinclude -I. -Isoftpll
cflags-y +=	-I$(CURDIR)/pp_printf
33

34
cflags-$(CONFIG_PTP_NOPOSIX) += \
35 36 37 38 39 40 41 42 43
	-DPTPD_FREESTANDING \
	-DWRPC_EXTRA_SLIM \
	-DPTPD_MSBF \
	-DPTPD_DBG \
	-DPTPD_NO_DAEMON \
	-DNEW_SINGLE_WRFSM \
	-DPTPD_TRACE_MASK=0 \
	-include $(PTP_NOPOSIX)/compat.h \
	-include $(PTP_NOPOSIX)/PTPWRd/dep/trace.h \
44 45 46
	-include $(PTP_NOPOSIX)/libposix/ptpd-wrappers.h \
	-I$(PTP_NOPOSIX)/libptpnetif \
	-I$(PTP_NOPOSIX)/PTPWRd
47

48
obj-$(CONFIG_PTP_NOPOSIX) += wrc_ptp_noposix.o \
49
	monitor/monitor.o \
50
	lib/ptp-noposix-wrappers.o \
51
	$(PTP_NOPOSIX)/PTPWRd/arith.o \
52 53 54 55 56 57 58 59 60
	$(PTP_NOPOSIX)/PTPWRd/bmc.o \
	$(PTP_NOPOSIX)/PTPWRd/dep/msg.o \
	$(PTP_NOPOSIX)/PTPWRd/dep/net.o \
	$(PTP_NOPOSIX)/PTPWRd/dep/sys.o \
	$(PTP_NOPOSIX)/PTPWRd/dep/timer.o \
	$(PTP_NOPOSIX)/PTPWRd/dep/wr_servo.o \
	$(PTP_NOPOSIX)/PTPWRd/dep/servo.o \
	$(PTP_NOPOSIX)/PTPWRd/protocol.o \
	$(PTP_NOPOSIX)/PTPWRd/wr_protocol.o \
61
	$(PTP_NOPOSIX)/libposix/freestanding-startup.o
Grzegorz Daniluk's avatar
Grzegorz Daniluk committed
62

63 64
cflags-$(CONFIG_PPSI) += \
	-ffreestanding \
65
	-include include/ppsi-wrappers.h \
66 67
	-Iinclude \
	-I$(PPSI)/include \
68 69
	-I$(PPSI)/arch-wrpc \
	-I$(PPSI)/arch-wrpc/include \
70 71 72
	-I$(PPSI)/proto-ext-whiterabbit \
	-Iboards/spec

73
# FIXME: The following is temporary, until we clean up
74 75 76 77
cflags-$(CONFIG_PPSI) += \
	-I$(PTP_NOPOSIX)/PTPWRd \
	-include $(PTP_NOPOSIX)/PTPWRd/dep/trace.h \

78 79 80 81
obj-ppsi = \
	$(PPSI)/ppsi.o \
	$(PPSI)/proto-standard/libstd.a

82
obj-$(CONFIG_PPSI) += \
83
	monitor/monitor_ppsi.o \
84
	lib/ppsi-wrappers.o \
85
	$(obj-ppsi)
86

87
CFLAGS_PLATFORM  = -mmultiply-enabled -mbarrel-shift-enabled
88
LDFLAGS_PLATFORM = -mmultiply-enabled -mbarrel-shift-enabled \
89
	-nostdlib -T $(LDS)
90

91
include shell/shell.mk
92
include lib/lib.mk
93
include pp_printf/printf.mk
94
include sockitowm/sockitowm.mk
95
include dev/dev.mk
96

97

98 99
obj-y += check-error.o

100
CFLAGS = $(CFLAGS_PLATFORM) $(cflags-y) -Wall \
101
	-ffunction-sections -fdata-sections -Os \
102
	-include include/trace.h -ggdb
103 104

LDFLAGS = $(LDFLAGS_PLATFORM) \
105
	-Wl,--gc-sections -Os -lgcc -lc
106

107
OBJS = $(obj-y)
108

109 110 111
OUTPUT = wrc

REVISION=$(shell git describe --dirty --always)
112

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

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

118
$(obj-ppsi):
119
	$(MAKE) -C $(PPSI) ARCH=wrpc PROTO_EXT=whiterabbit \
120 121 122
		CROSS_COMPILE=$(CROSS_COMPILE) CONFIG_NO_PRINTF=y \
		USER_CFLAGS="-DDIAG_PUTS=uart_sw_write_string"

123

124
$(OUTPUT).elf: $(LDS) $(AUTOCONF) gitmodules $(OUTPUT).o config.o
125
	$(CC) $(CFLAGS) -DGIT_REVISION=\"$(REVISION)\" -c revision.c
126
	${CC} -o $@ revision.o config.o $(OUTPUT).o $(LDFLAGS)
127
	${OBJDUMP} -d $(OUTPUT).elf > $(OUTPUT)_disasm.S
128 129
	$(SIZE) $@

130
$(OUTPUT).o: $(OBJS)
131
	$(LD) --gc-sections -e _start -r $(OBJS) -T bigobj.lds -o $@
132

133 134 135 136 137 138 139
config.o: .config
	sed '1,3d' .config > .config.bin
	dd bs=1 count=1 if=/dev/zero 2> /dev/null >> .config.bin
	$(OBJCOPY) -I binary -O elf32-lm32 -B lm32 \
		--rename-section .data=.data.config  .config.bin $@
	rm -f .config.bin

140 141 142 143 144 145 146
%.bin: %.elf
	${OBJCOPY} -O binary $^ $@

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

%.vhd: tools %.bin
147 148 149 150
	./tools/genramvhd -s `. ./.config; echo $$CONFIG_RAMSIZE` $*.bin > $@

%.mif: tools %.bin
	./tools/genrammif $*.bin `. ./.config; echo $$CONFIG_RAMSIZE` > $@
Grzegorz Daniluk's avatar
Grzegorz Daniluk committed
151

152 153
$(AUTOCONF): silentoldconfig

154
clean:
155
	rm -f $(OBJS) $(OUTPUT).elf $(OUTPUT).bin $(OUTPUT).ram $(LDS)
156
	$(MAKE) -C $(PPSI) clean
157 158

%.o:		%.c
159
	${CC} $(CFLAGS) $(PTPD_CFLAGS) $(INCLUDE_DIR) $(LIB_DIR) -c $*.c -o $@
160 161

tools:
162
	$(MAKE) -C tools
163

164 165 166 167
# if needed, check out the submodules (first time only), so users
# who didn't read carefully the manual won't get confused
gitmodules:
	@test -d ptp-noposix/libposix || echo "Checking out submodules"
168
	@test -d ptp-noposix/libposix || git submodule update --init
169
	@test -d ppsi/arch-wrpc || git submodule update --init
170 171


172 173 174 175 176
# following targets from Makefile.kconfig
silentoldconfig:
	@mkdir -p include/config
	$(MAKE) -f Makefile.kconfig $@

177 178 179 180
scripts_basic config:
	$(MAKE) -f Makefile.kconfig $@

%config:
181
	$(MAKE) -f Makefile.kconfig $@
182

183 184 185
defconfig:
	$(MAKE) -f Makefile.kconfig spec_defconfig

186
.config: silentoldconfig
187