Merge pull request #11 from mithro/file-dont-change
Only require rebuild on actual changes
This commit is contained in:
commit
ffc342f49c
|
@ -23,6 +23,9 @@ def write_to_file(filename, contents, force_unix=False):
|
|||
newline = None
|
||||
if force_unix:
|
||||
newline = "\n"
|
||||
if os.path.exists(filename):
|
||||
if open(filename, "r", newline=newline).read() == contents:
|
||||
return
|
||||
with open(filename, "w", newline=newline) as f:
|
||||
f.write(contents)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import subprocess
|
|||
import struct
|
||||
import shutil
|
||||
|
||||
from litex.build.tools import write_to_file
|
||||
from litex.soc.integration import cpu_interface, soc_sdram, sdram_init
|
||||
|
||||
|
||||
|
@ -66,29 +67,38 @@ class Builder:
|
|||
buildinc_dir = os.path.join(self.output_dir, "software", "include")
|
||||
generated_dir = os.path.join(buildinc_dir, "generated")
|
||||
os.makedirs(generated_dir, exist_ok=True)
|
||||
with open(os.path.join(generated_dir, "variables.mak"), "w") as f:
|
||||
def define(k, v):
|
||||
f.write("{}={}\n".format(k, _makefile_escape(v)))
|
||||
for k, v in cpu_interface.get_cpu_mak(cpu_type):
|
||||
define(k, v)
|
||||
define("SOC_DIRECTORY", soc_directory)
|
||||
define("BUILDINC_DIRECTORY", buildinc_dir)
|
||||
for name, src_dir in self.software_packages:
|
||||
define(name.upper() + "_DIRECTORY", src_dir)
|
||||
|
||||
with open(os.path.join(generated_dir, "output_format.ld"), "w") as f:
|
||||
f.write(cpu_interface.get_linker_output_format(cpu_type))
|
||||
with open(os.path.join(generated_dir, "regions.ld"), "w") as f:
|
||||
f.write(cpu_interface.get_linker_regions(memory_regions))
|
||||
variables_contents = []
|
||||
def define(k, v):
|
||||
variables_contents.append("{}={}\n".format(k, _makefile_escape(v)))
|
||||
for k, v in cpu_interface.get_cpu_mak(cpu_type):
|
||||
define(k, v)
|
||||
define("SOC_DIRECTORY", soc_directory)
|
||||
define("BUILDINC_DIRECTORY", buildinc_dir)
|
||||
for name, src_dir in self.software_packages:
|
||||
define(name.upper() + "_DIRECTORY", src_dir)
|
||||
write_to_file(
|
||||
os.path.join(generated_dir, "variables.mak"),
|
||||
"".join(variables_contents))
|
||||
|
||||
with open(os.path.join(generated_dir, "mem.h"), "w") as f:
|
||||
f.write(cpu_interface.get_mem_header(memory_regions, flash_boot_address))
|
||||
with open(os.path.join(generated_dir, "csr.h"), "w") as f:
|
||||
f.write(cpu_interface.get_csr_header(csr_regions, constants))
|
||||
write_to_file(
|
||||
os.path.join(generated_dir, "output_format.ld"),
|
||||
cpu_interface.get_linker_output_format(cpu_type))
|
||||
write_to_file(
|
||||
os.path.join(generated_dir, "regions.ld"),
|
||||
cpu_interface.get_linker_regions(memory_regions))
|
||||
|
||||
write_to_file(
|
||||
os.path.join(generated_dir, "mem.h"),
|
||||
cpu_interface.get_mem_header(memory_regions, flash_boot_address))
|
||||
write_to_file(
|
||||
os.path.join(generated_dir, "csr.h"),
|
||||
cpu_interface.get_csr_header(csr_regions, constants))
|
||||
|
||||
if sdram_phy_settings is not None:
|
||||
with open(os.path.join(generated_dir, "sdram_phy.h"), "w") as f:
|
||||
f.write(sdram_init.get_sdram_phy_header(sdram_phy_settings))
|
||||
write_to_file(
|
||||
os.path.join(generated_dir, "sdram_phy.h"),
|
||||
sdram_init.get_sdram_phy_header(sdram_phy_settings))
|
||||
|
||||
def _generate_csr_csv(self):
|
||||
memory_regions = self.soc.get_memory_regions()
|
||||
|
@ -97,8 +107,9 @@ class Builder:
|
|||
|
||||
csr_dir = os.path.dirname(self.csr_csv)
|
||||
os.makedirs(csr_dir, exist_ok=True)
|
||||
with open(self.csr_csv, "w") as f:
|
||||
f.write(cpu_interface.get_csr_csv(csr_regions, constants, memory_regions))
|
||||
write_to_file(
|
||||
self.csr_csv,
|
||||
cpu_interface.get_csr_csv(csr_regions, constants, memory_regions))
|
||||
|
||||
def _prepare_software(self):
|
||||
for name, src_dir in self.software_packages:
|
||||
|
|
|
@ -22,8 +22,8 @@ bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS)
|
|||
-lnet -lbase-nofloat -lcompiler_rt
|
||||
chmod -x $@
|
||||
|
||||
main.o: $(BIOS_DIRECTORY)/main.c
|
||||
$(compile)
|
||||
# pull in dependency info for *existing* .o files
|
||||
-include $(OBJECTS:.o=.d)
|
||||
|
||||
%.o: $(BIOS_DIRECTORY)/%.c
|
||||
$(compile)
|
||||
|
@ -34,4 +34,4 @@ main.o: $(BIOS_DIRECTORY)/main.c
|
|||
clean:
|
||||
$(RM) $(OBJECTS) bios.elf bios.bin .*~ *~
|
||||
|
||||
.PHONY: all clean main.o
|
||||
.PHONY: all clean
|
||||
|
|
Loading…
Reference in New Issue