Skip to content

Commit f374bd3

Browse files
ezeliolithommythomaso
authored andcommitted
Makefile: integrate Makefiles and simplify
1 parent 8125556 commit f374bd3

File tree

2 files changed

+67
-176
lines changed

2 files changed

+67
-176
lines changed

Makefile

Lines changed: 67 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -4,108 +4,78 @@
44
#
55
# Authors:
66
# - Philippe Sauter <[email protected]>
7-
8-
# Tools
9-
BENDER ?= bender
7+
# - Enrico Zelioli <[email protected]>
108

119
# Directories
1210
# directory of the path to the last called Makefile (this one)
13-
PROJ_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
14-
15-
16-
default: help
17-
18-
################
19-
# Dependencies #
20-
################
21-
# Download RCX file used for parasitic extraction from ORFS (configuration got ok by IHP)
22-
IHP_RCX_URL := "https://raw.githubusercontent.com/The-OpenROAD-Project/OpenROAD-flow-scripts/7747f88f70daaeb63f43ce36e71829707b7e3fa7/flow/platforms/ihp-sg13g2/IHP_rcx_patterns.rules"
23-
IHP_RCX_FILE := $(PROJ_DIR)/openroad/IHP_rcx_patterns.rules
24-
25-
## Checkout/update dependencies using Bender
26-
checkout: $(IHP_RCX_FILE)
27-
$(BENDER) checkout
28-
git submodule update --init --recursive
29-
30-
$(IHP_RCX_FILE):
31-
curl -L -o $@ $(IHP_RCX_URL)
32-
33-
## Reset dependencies (without updating Bender.lock)
34-
clean-deps:
35-
rm -rf .bender
36-
git submodule deinit -f --all
37-
38-
.PHONY: checkout clean-deps
39-
40-
41-
############
42-
# Software #
43-
############
44-
SW_HEX ?= sw/bin/helloworld.hex
45-
46-
$(SW_HEX): sw/*.c sw/*.h sw/*.S sw/*.ld
47-
$(MAKE) -C sw/ compile
11+
PROJ_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
12+
SW_DIR := $(PROJ_DIR)/sw
13+
SRC_DIR := $(SW_DIR)/lib/src
14+
INC_DIR := $(SW_DIR)/lib/inc
15+
BIN_DIR := $(SW_DIR)/bin
16+
17+
# Toolchain
18+
RISCV_PREFIX ?= riscv64-unknown-elf-
19+
RISCV_CC := $(RISCV_PREFIX)gcc
20+
RISCV_OBJDUMP := $(RISCV_PREFIX)objdump
21+
RISCV_OBJCOPY := $(RISCV_PREFIX)objcopy
22+
RISCV_LD := $(RISCV_PREFIX)ld
23+
24+
# Compilation and linking flags
25+
RISCV_FLAGS := -march=rv32i_zicsr -mabi=ilp32 -mcmodel=medany -static -std=gnu99 -Os -nostdlib -fno-builtin -ffreestanding
26+
RISCV_CCFLAGS := $(RISCV_FLAGS) -I$(INC_DIR) -I$(SW_DIR)
27+
RISCV_LDFLAGS := $(RISCV_FLAGS) -static -nostartfiles -lm -lgcc
28+
29+
# Build files
30+
CRT0 := $(SW_DIR)/crt0.S
31+
LINK := $(SW_DIR)/link.ld
32+
LIB_SOURCES := $(wildcard $(SRC_DIR)/*.[cS])
33+
LIB_OBJS := $(LIB_SOURCES:$(SRC_DIR)/%=$(SRC_DIR)/%.o)
34+
35+
# Build all assembly and C files in the top level as seperate binaries
36+
TOP_SOURCES := $(filter-out $(CRT0), $(wildcard $(SW_DIR)/*.[cS]))
37+
TOP_BASENAMES := $(basename $(notdir $(TOP_SOURCES)))
38+
ALL_TARGETS := $(TOP_BASENAMES:%=$(BIN_DIR)/%.dump) $(TOP_BASENAMES:%=$(BIN_DIR)/%.hex)
39+
40+
# Default make target
41+
.PHONY: default
42+
default: all
43+
44+
# Create output bin directory
45+
$(BIN_DIR):
46+
mkdir -p $(BIN_DIR)
47+
48+
# Compile assembly file
49+
%.S.o: %.S
50+
$(RISCV_CC) $(RISCV_CCFLAGS) -c $< -o $@
51+
52+
# Compile C file
53+
%.c.o: %.c
54+
$(RISCV_CC) $(RISCV_CCFLAGS) -c $< -o $@
55+
56+
# Link assembly application
57+
$(BIN_DIR)/%.elf: $(SW_DIR)/%.S.o $(CRT0).o $(LIB_OBJS) | $(BIN_DIR)
58+
$(RISCV_CC) -o $@ $^ $(RISCV_LDFLAGS) -T$(LINK)
59+
60+
# Link C application
61+
$(BIN_DIR)/%.elf: $(SW_DIR)/%.c.o $(CRT0).o $(LIB_OBJS) | $(BIN_DIR)
62+
$(RISCV_CC) -o $@ $^ $(RISCV_LDFLAGS) -T$(LINK)
63+
64+
# Create dis-assembled version of ELF binary
65+
$(BIN_DIR)/%.dump: $(BIN_DIR)/%.elf
66+
$(RISCV_OBJDUMP) -D -s $< >$@
67+
68+
# Create hex version of ELF binary
69+
$(BIN_DIR)/%.hex: $(BIN_DIR)/%.elf
70+
$(RISCV_OBJCOPY) -O verilog $< $@
4871

4972
## Build all top-level programs in sw/
50-
software: $(SW_HEX)
51-
52-
sw: $(SW_HEX)
53-
54-
.PHONY: software sw
55-
56-
#############
57-
# Finishing #
58-
#############
59-
ihp13/pdk.patched:
60-
- cd ihp13/pdk; git apply ../patches/0001-Filling-improvements.patch
61-
touch $@
62-
63-
klayout/out/croc_chip_sealed.gds.gz: ihp13/pdk.patched openroad/out/croc.def klayout/scripts/*.py klayout/scripts/*.sh
64-
bash klayout/scripts/finishing.sh
65-
66-
finishing: klayout/out/croc_chip_sealed.gds.gz
67-
.PHONY: finishing
68-
69-
#################
70-
# Documentation #
71-
#################
72-
73-
help: Makefile
74-
@printf "Available targets:\n------------------\n"
75-
@for mkfile in $(MAKEFILE_LIST); do \
76-
awk '/^[a-zA-Z\-\_0-9]+:/ { \
77-
helpMessage = match(lastLine, /^## (.*)/); \
78-
if (helpMessage) { \
79-
helpCommand = substr($$1, 0, index($$1, ":")-1); \
80-
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
81-
printf "%-20s %s\n", helpCommand, helpMessage; \
82-
} \
83-
} \
84-
{ lastLine = $$0 }' $$mkfile; \
85-
done
86-
87-
.PHONY: help
88-
89-
###########
90-
# Format #
91-
###########
92-
CLANG_FORMAT_EXECUTABLE ?= clang-format
93-
94-
## Automatically format the code using clang-format and black
95-
format:
96-
@echo -e "\033[1m-> Formatting Python Code...\033[0m"
97-
@black */*.py
98-
@echo -e "\033[1m-> Formatting C Code...\033[0m"
99-
@python scripts/run_clang_format.py -ir sw/ --clang-format-executable=$(CLANG_FORMAT_EXECUTABLE)
100-
101-
.PHONY: format
102-
103-
###########
104-
# Cleanup #
105-
###########
73+
.PHONY: all
74+
all: $(ALL_TARGETS)
10675

10776
## Delete generated files and directories
108-
clean:
109-
$(MAKE) -C sw clean
110-
11177
.PHONY: clean
78+
clean:
79+
rm -rf $(BIN_DIR)
80+
rm -f $(PROJ_DIR)/sw/*.o
81+
rm -f $(PROJ_DIR)/sw/lib/src/*.o

sw/Makefile

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)