fallrain ревизий этого фрагмента . К ревизии
1 file changed, 53 insertions
ics-pa-notes.md(файл создан)
| @@ -0,0 +1,53 @@ | |||
| 1 | + | +++ | |
| 2 | + | date = '2025-02-15T16:55:11+08:00' | |
| 3 | + | draft = true | |
| 4 | + | title = 'NJU ICS PA Notes' | |
| 5 | + | ||
| 6 | + | +++ | |
| 7 | + | ||
| 8 | + | 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. | |
| 9 | + | ||
| 10 | + | ## Makefiles Spaghetti | |
| 11 | + | ||
| 12 | + | - `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. | |
| 13 | + | - In a Makefile, `:=` and `=` are used to define variables, but they behave differently: | |
| 14 | + | - `=` (Recursive or Lazy Assignment): The value is expanded when the variable is used, not when it is defined. | |
| 15 | + | - `:=` (Simple or Immediate Assignment): The value is expanded immediately when the variable is defined. | |
| 16 | + | - `::` is a double colon rule, which allows multiple rules for the same target. Each rule is treated independently. | |
| 17 | + | ||
| 18 | + | Makefile for compile menuconfig is at `nemu/scripts/config.mk`. | |
| 19 | + | ||
| 20 | + | All the source file names are gathered from `filelist.mk` under `nemu/src`. | |
| 21 | + | ||
| 22 | + | ```makefile | |
| 23 | + | # Include all filelist.mk to merge file lists | |
| 24 | + | FILELIST_MK = $(shell find -L ./src -name "filelist.mk") | |
| 25 | + | include $(FILELIST_MK) | |
| 26 | + | ``` | |
| 27 | + | ||
| 28 | + | And all `.c` files under `DIRS-y` will be added to `SRCS-y`. | |
| 29 | + | ||
| 30 | + | ```makefile | |
| 31 | + | SRCS-y += $(shell find -L $(DIRS-y) -name "*.c") | |
| 32 | + | ``` | |
| 33 | + | ||
| 34 | + | NEMU Compilation happens at `nemu/scripts/build.mk`. | |
| 35 | + | ||
| 36 | + | ```makefile | |
| 37 | + | OBJS = $(SRCS:%.c=$(OBJ_DIR)/%.o) $(CXXSRC:%.cc=$(OBJ_DIR)/%.o) | |
| 38 | + | ||
| 39 | + | # Compilation patterns | |
| 40 | + | $(OBJ_DIR)/%.o: %.c | |
| 41 | + | @echo + CC $< | |
| 42 | + | @mkdir -p $(dir $@) | |
| 43 | + | @$(CC) $(CFLAGS) -c -o $@ $< | |
| 44 | + | $(call call_fixdep, $(@:.o=.d), $@) | |
| 45 | + | ||
| 46 | + | $(OBJ_DIR)/%.o: %.cc | |
| 47 | + | @echo + CXX $< | |
| 48 | + | @mkdir -p $(dir $@) | |
| 49 | + | @$(CXX) $(CFLAGS) $(CXXFLAGS) -c -o $@ $< | |
| 50 | + | $(call call_fixdep, $(@:.o=.d), $@) | |
| 51 | + | ``` | |
| 52 | + | ||
| 53 | + | Which is included by `nemu/scripts/native.mk` along with target `run` and `gdb` etc. | |
Новее
Позже