ics-pa-notes.md
· 1.8 KiB · Markdown
Исходник
+++
date = '2025-02-15T16:55:11+08:00'
draft = true
title = 'NJU ICS PA Notes'
+++
One may encounter some hurdles here and there when drilling through [NJU ICS PA 2024](https://nju-projectn.github.io/ics-pa-gitbook/ics2024/), which is surely a very good educational project btw. So here's my two cents.
## Makefiles Spaghetti
- `Q := @`: The `@` symbol in a Makefile is used to suppress the command echoing. When `Q` is used before a command, it prevents the command from being printed to the terminal before execution.
- In a Makefile, `:=` and `=` are used to define variables, but they behave differently:
- `=` (Recursive or Lazy Assignment): The value is expanded when the variable is used, not when it is defined.
- `:=` (Simple or Immediate Assignment): The value is expanded immediately when the variable is defined.
- `::` is a double colon rule, which allows multiple rules for the same target. Each rule is treated independently.
Makefile for compile menuconfig is at `nemu/scripts/config.mk`.
All the source file names are gathered from `filelist.mk` under `nemu/src`.
```makefile
# Include all filelist.mk to merge file lists
FILELIST_MK = $(shell find -L ./src -name "filelist.mk")
include $(FILELIST_MK)
```
And all `.c` files under `DIRS-y` will be added to `SRCS-y`.
```makefile
SRCS-y += $(shell find -L $(DIRS-y) -name "*.c")
```
NEMU Compilation happens at `nemu/scripts/build.mk`.
```makefile
OBJS = $(SRCS:%.c=$(OBJ_DIR)/%.o) $(CXXSRC:%.cc=$(OBJ_DIR)/%.o)
# Compilation patterns
$(OBJ_DIR)/%.o: %.c
@echo + CC $<
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c -o $@ $<
$(call call_fixdep, $(@:.o=.d), $@)
$(OBJ_DIR)/%.o: %.cc
@echo + CXX $<
@mkdir -p $(dir $@)
@$(CXX) $(CFLAGS) $(CXXFLAGS) -c -o $@ $<
$(call call_fixdep, $(@:.o=.d), $@)
```
Which is included by `nemu/scripts/native.mk` along with target `run` and `gdb` etc.
+++ date = '2025-02-15T16:55:11+08:00' draft = true title = 'NJU ICS PA Notes'
+++
One may encounter some hurdles here and there when drilling through NJU ICS PA 2024, which is surely a very good educational project btw. So here's my two cents.
Makefiles Spaghetti
Q := @: The@symbol in a Makefile is used to suppress the command echoing. WhenQis used before a command, it prevents the command from being printed to the terminal before execution.- In a Makefile,
:=and=are used to define variables, but they behave differently:=(Recursive or Lazy Assignment): The value is expanded when the variable is used, not when it is defined.:=(Simple or Immediate Assignment): The value is expanded immediately when the variable is defined.
::is a double colon rule, which allows multiple rules for the same target. Each rule is treated independently.
Makefile for compile menuconfig is at nemu/scripts/config.mk.
All the source file names are gathered from filelist.mk under nemu/src.
# Include all filelist.mk to merge file lists
FILELIST_MK = $(shell find -L ./src -name "filelist.mk")
include $(FILELIST_MK)
And all .c files under DIRS-y will be added to SRCS-y.
SRCS-y += $(shell find -L $(DIRS-y) -name "*.c")
NEMU Compilation happens at nemu/scripts/build.mk.
OBJS = $(SRCS:%.c=$(OBJ_DIR)/%.o) $(CXXSRC:%.cc=$(OBJ_DIR)/%.o)
# Compilation patterns
$(OBJ_DIR)/%.o: %.c
@echo + CC $<
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c -o $@ $<
$(call call_fixdep, $(@:.o=.d), $@)
$(OBJ_DIR)/%.o: %.cc
@echo + CXX $<
@mkdir -p $(dir $@)
@$(CXX) $(CFLAGS) $(CXXFLAGS) -c -o $@ $<
$(call call_fixdep, $(@:.o=.d), $@)
Which is included by nemu/scripts/native.mk along with target run and gdb etc.