Commit 2883f53c authored by Tristan Gingold's avatar Tristan Gingold

Makefile: generate dependencies

Avoid use of phony targets (like tools): be explicit
parent 6b74d488
...@@ -68,13 +68,12 @@ dump_mem_ppsi_wrpc.o: CFLAGS+=-Itools -fno-lto ...@@ -68,13 +68,12 @@ dump_mem_ppsi_wrpc.o: CFLAGS+=-Itools -fno-lto
dump-info.o: CFLAGS+=-Ippsi/tools -fno-lto dump-info.o: CFLAGS+=-Ippsi/tools -fno-lto
# our linker script is preprocessed, so have a rule here # our linker script is preprocessed, so have a rule here
%.ld: %.ld.S $(AUTOCONF) .config %.ld: %.ld.S $(AUTOCONF)
$(CC) -include $(AUTOCONF) -E -P $*.ld.S -o $@ $(CC) -include $(AUTOCONF) -E -P $*.ld.S -o $@
cflags-y = -ffreestanding -include $(AUTOCONF) -Iinclude \ cflags-y = -MMD -ffreestanding -include $(AUTOCONF)
-I. -Isoftpll -Iipc cflags-y += -Iinclude -I. -Isoftpll -Iipc -Ipp_printf
cflags-y += -Ipp_printf
cflags-$(CONFIG_LTO) += -flto cflags-$(CONFIG_LTO) += -flto
# Only for lm32 # Only for lm32
...@@ -159,7 +158,7 @@ CFLAGS = $(cflags-y) -Wall -Werror -Wstrict-prototypes \ ...@@ -159,7 +158,7 @@ CFLAGS = $(cflags-y) -Wall -Werror -Wstrict-prototypes \
ldflags-$(CONFIG_LTO) += -flto ldflags-$(CONFIG_LTO) += -flto
# Assembler Flags # Assembler Flags
ASFLAGS = -I. $(asflags-y) ASFLAGS = -MD -I. $(asflags-y)
LDFLAGS = $(ldflags-y) \ LDFLAGS = $(ldflags-y) \
-Wl,--gc-sections -Os -lgcc -lc -Wl,--gc-sections -Os -lgcc -lc
...@@ -184,7 +183,7 @@ all: libertm ...@@ -184,7 +183,7 @@ all: libertm
all: tools $(OUTPUT).elf $(arch-files-y) all: tools $(OUTPUT).elf $(arch-files-y)
.PRECIOUS: %.elf %.bin .PRECIOUS: %.elf %.bin
.PHONY: all tools clean gitmodules extest liblinux .PHONY: all tools clean extest liblinux
.PHONY: libertm boards-clean .PHONY: libertm boards-clean
# we need to remove "ptpdump" support for ppsi if RAM size is small and # we need to remove "ptpdump" support for ppsi if RAM size is small and
...@@ -199,13 +198,6 @@ ifeq ($(CONFIG_LTO),y) ...@@ -199,13 +198,6 @@ ifeq ($(CONFIG_LTO),y)
PPSI_USER_CFLAGS += -flto PPSI_USER_CFLAGS += -flto
endif endif
$(obj-ppsi): gitmodules
$(MAKE) -C $(PPSI) ppsi.a WRPCSW_ROOT=.. \
CROSS_COMPILE=$(CROSS_COMPILE) CONFIG_NO_PRINTF=y \
CONFIG_LTO=$(CONFIG_LTO) \
USER_CFLAGS="$(PPSI_USER_CFLAGS)" \
CPU_ARCH=$(CPU_ARCH) \
$(OUTPUT).elf: $(LDS-y) $(AUTOCONF) gitmodules config.o $(OBJS) $(OUTPUT).elf: $(LDS-y) $(AUTOCONF) gitmodules config.o $(OBJS)
$(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\"" -Wno-error -c revision.c $(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\"" -Wno-error -c revision.c
${CC} -Wl,-Map,$(OUTPUT).map -o $@ revision.o config.o $(OBJS) $(LDFLAGS) ${CC} -Wl,-Map,$(OUTPUT).map -o $@ revision.o config.o $(OBJS) $(LDFLAGS)
...@@ -218,7 +210,7 @@ OBJCOPY-TARGET-$(CONFIG_ARCH_LM32) = -O elf32-lm32 -B lm32 ...@@ -218,7 +210,7 @@ OBJCOPY-TARGET-$(CONFIG_ARCH_LM32) = -O elf32-lm32 -B lm32
OBJCOPY-TARGET-$(CONFIG_ARCH_RISCV) = -O elf32-littleriscv -B riscv OBJCOPY-TARGET-$(CONFIG_ARCH_RISCV) = -O elf32-littleriscv -B riscv
OBJCOPY-TARGET-$(CONFIG_HOST_PROCESS) = -O elf64-x86-64 -B i386 OBJCOPY-TARGET-$(CONFIG_HOST_PROCESS) = -O elf64-x86-64 -B i386
config.o: .config $(AUTOCONF) config.o: .config
grep CONFIG .config > .config.bin grep CONFIG .config > .config.bin
dd bs=1 count=1 if=/dev/zero 2> /dev/null >> .config.bin dd bs=1 count=1 if=/dev/zero 2> /dev/null >> .config.bin
$(OBJCOPY) -I binary $(OBJCOPY-TARGET-y) .config.bin $@ $(OBJCOPY) -I binary $(OBJCOPY-TARGET-y) .config.bin $@
...@@ -230,22 +222,21 @@ GENRAM_ENDIAN_FLAG-$(CONFIG_ARCH_RISCV) = -l ...@@ -230,22 +222,21 @@ GENRAM_ENDIAN_FLAG-$(CONFIG_ARCH_RISCV) = -l
%.bin: %.elf %.bin: %.elf
${OBJCOPY} -O binary $< $@ ${OBJCOPY} -O binary $< $@
%.bram: %.bin tools %.bram: %.bin tools/genraminit
./tools/genraminit $(GENRAM_ENDIAN_FLAG-y) $< $(CONFIG_RAMSIZE) > $@ ./tools/genraminit $(GENRAM_ENDIAN_FLAG-y) $< $(CONFIG_RAMSIZE) > $@
%.vhd: tools %.bin %.vhd: %.bin tools/genramvhd
./tools/genramvhd -s $(CONFIG_RAMSIZE) $*.bin > $@ ./tools/genramvhd -s $(CONFIG_RAMSIZE) $*.bin > $@
%.mif: tools %.bin %.mif: %.bin tools/genrammif
./tools/genrammif $(GENRAM_ENDIAN_FLAG-y) $*.bin $(CONFIG_RAMSIZE) > $@ ./tools/genrammif $(GENRAM_ENDIAN_FLAG-y) $*.bin $(CONFIG_RAMSIZE) > $@
$(AUTOCONF): silentoldconfig gitmodules
clean: boards-clean clean: boards-clean
rm -f $(OBJS) config.o pconfig.o revision.o $(OUTPUT).elf \ rm -f $(OBJS) config.o pconfig.o revision.o $(OUTPUT).elf \
$(LDS) \ $(LDS) \
$(OUTPUT).bin rules-*.bin \ $(OUTPUT).bin rules-*.bin \
$(OUTPUT).bram $(OUTPUT).vhd $(OUTPUT).mif $(OUTPUT)_disasm.S $(OUTPUT).bram $(OUTPUT).vhd $(OUTPUT).mif $(OUTPUT)_disasm.S
rm -f $(OBJS:.o=.d)
$(MAKE) -C $(PPSI) clean $(MAKE) -C $(PPSI) clean
$(MAKE) -C tools clean $(MAKE) -C tools clean
$(MAKE) -C liblinux clean $(MAKE) -C liblinux clean
...@@ -270,7 +261,7 @@ libertm: ...@@ -270,7 +261,7 @@ libertm:
extest: extest:
$(MAKE) -C liblinux/extest CC=cc $(MAKE) -C liblinux/extest CC=cc
tools: .config gitmodules liblinux extest tools/gensdbfs tools/pfilter-builder tools/genraminit tools/genramvhd tools/genrammif tools: .config $(AUTOCONF) gitmodules liblinux extest
$(MAKE) -C tools $(MAKE) -C tools
tools-diag: liblinux extest tools-diag: liblinux extest
...@@ -279,8 +270,9 @@ tools-diag: liblinux extest ...@@ -279,8 +270,9 @@ tools-diag: liblinux extest
# if needed, check out the submodules (first time only), so users # if needed, check out the submodules (first time only), so users
# who didn't read carefully the manual won't get confused # who didn't read carefully the manual won't get confused
gitmodules: gitmodules:
@test -d ppsi/arch-wrpc || echo "Checking out submodules" @echo "Checking out submodules"
@test -d ppsi/arch-wrpc || git submodule update --init git submodule update --init
touch gitmodules
# Explicit rule for $(CURDIR)/.config # Explicit rule for $(CURDIR)/.config
# needed since -include XXX triggers build for XXX # needed since -include XXX triggers build for XXX
...@@ -316,7 +308,15 @@ scripts_basic config: ...@@ -316,7 +308,15 @@ scripts_basic config:
defconfig: defconfig:
$(MAKE) quiet=quiet_ -f Makefile.kconfig spec_defconfig $(MAKE) quiet=quiet_ -f Makefile.kconfig spec_defconfig
.config: silentoldconfig # silentoldconfig is needed to regenerate autoconf.h
$(AUTOCONF): .config
@mkdir -p include/config include/generated
$(MAKE) -f Makefile.kconfig silentoldconfig
# Re-configure in case of Kconfig change
.config: Kconfig $(PPSI)/Kconfig_ppsi
@mkdir -p include/config include/generated
$(MAKE) -f Makefile.kconfig silentoldconfig
# This forces more compilations than needed, but it's useful # This forces more compilations than needed, but it's useful
# (we depend on .config and not on include/generated/autoconf.h # (we depend on .config and not on include/generated/autoconf.h
...@@ -342,3 +342,7 @@ load: ...@@ -342,3 +342,7 @@ load:
# print output name (used by MAKEALL) # print output name (used by MAKEALL)
output_name: output_name:
echo $(OUTPUT) echo $(OUTPUT)
$(OBJS): $(AUTOCONF)
-include $(OBJS:.o=.d)
...@@ -24,10 +24,10 @@ obj-$(CONFIG_TARGET_WR2RF_VME) += boards/wr2rf-vme/board.o boards/wr2rf-vme/sdb ...@@ -24,10 +24,10 @@ obj-$(CONFIG_TARGET_WR2RF_VME) += boards/wr2rf-vme/board.o boards/wr2rf-vme/sdb
boards/ertm14/sdbfs-custom-image.o: boards/ertm14/sdbfs-custom-image.h boards/ertm14/sdbfs-custom-image.o: boards/ertm14/sdbfs-custom-image.h
boards/wr2rf-vme/sdbfs-custom-image.o: boards/wr2rf-vme/sdbfs-custom-image.h boards/wr2rf-vme/sdbfs-custom-image.o: boards/wr2rf-vme/sdbfs-custom-image.h
boards/ertm14/sdbfs-custom-image.h: boards/ertm14/sdbfs tools boards/ertm14/sdbfs-custom-image.h: boards/ertm14/sdbfs tools/gensdbfs
./tools/gensdbfs $(sdbfs_swap_bytes-y) -c boards/ertm14/sdbfs-custom-image.h boards/ertm14/sdbfs boards/ertm14/sdbfs-custom-image.bin ./tools/gensdbfs $(sdbfs_swap_bytes-y) -c boards/ertm14/sdbfs-custom-image.h boards/ertm14/sdbfs boards/ertm14/sdbfs-custom-image.bin
boards/wr2rf-vme/sdbfs-custom-image.h: boards/wr2rf-vme/sdbfs tools boards/wr2rf-vme/sdbfs-custom-image.h: boards/wr2rf-vme/sdbfs tools/gensdbfs
./tools/gensdbfs $(sdbfs_swap_bytes-y) -c boards/wr2rf-vme/sdbfs-custom-image.h boards/wr2rf-vme/sdbfs boards/wr2rf-vme/sdbfs-custom-image.bin ./tools/gensdbfs $(sdbfs_swap_bytes-y) -c boards/wr2rf-vme/sdbfs-custom-image.h boards/wr2rf-vme/sdbfs boards/wr2rf-vme/sdbfs-custom-image.bin
boards-clean: boards-clean:
......
...@@ -90,8 +90,8 @@ dev/ep_pfilter.o: $(pfilter-y) ...@@ -90,8 +90,8 @@ dev/ep_pfilter.o: $(pfilter-y)
dev/storage.o: $(sdbfsimg-y) dev/storage.o: $(sdbfsimg-y)
$(pfilter-y): tools $(pfilter-y): tools/pfilter-builder
./tools/pfilter-builder include/generated/ ./tools/pfilter-builder include/generated/
$(sdbfsimg-y): tools $(sdbfsimg-y): tools/gensdbfs
./tools/gensdbfs $(sdbfs_swap_bytes-y) -c include/generated/sdbfs-default.h tools/sdbfs tools/sdbfs-default.bin ./tools/gensdbfs $(sdbfs_swap_bytes-y) -c include/generated/sdbfs-default.h tools/sdbfs tools/sdbfs-default.bin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment