本次课程
写于 1994 年
开源社区 (百度百科):根据相应的开源软件许可证协议公布软件源代码的网络平台,同时也为网络成员提供一个自由学习交流的空间。
从 GitHub 获取代码
git clone -b 2020 https://github.com/NJU-ProjectN/ics-pa ics2020
git clone https://github.com/NJU-ProjectN/ics-workbench
GitHub is a development platform inspired by the way you work. From open source to business, you can host and review code, manage projects, and build software alongside 50 million developers. (不愧为全球最大的
同性交友网站)
内心独白:
我▇,又要我学一个新东西,劳资不要
RTFM? STFW!
有趣的 “--
”
-rf
”……怎么删除它???-
” 开头、不含空格/符号……体验 Git
我们使用了 “白名单” .gitignore
文件
.c
, .h
和 Makefile
* # 忽略一切文件
!*/ # 除了目录
!*.c # .c
!*.h # ...
!Makefile*
!.gitignore
ls
看不到这个文件?.git
make submit
会下载执行 http://jyywiki.cn/static/submit.sh
bash -c "$(curl -s http://jyywiki.cn/static/submit.sh)"
# submit.sh (服务器)
COURSE=ICS2020
MODULE=$(git rev-parse --abbrev-ref HEAD | tr '[a-z]' '[A-Z]')
NAME=$(basename $(realpath .))
FILE=/tmp/upload.tar.bz2
cd .. && \
tar caf "$FILE" "$NAME/.git" $(find $NAME -maxdepth 1 -name "*.pdf") && \
curl -F "stuid=$STUID" -F "stuname=$STUNAME" \
-F "course=$COURSE" -F "module=$MODULE" \
-F "file=@$FILE" http://jyywiki.cn/upload
另一段神秘代码 (来自 Makefile.lab
)
git:
@git add $(shell find . -name "*.c") \
$(shell find . -name "*.h") -A --ignore-errors
@while (test -e .git/index.lock); do sleep 0.1; done
@(hostnamectl && uptime) | \
git commit -F - -q --author=... --no-verify --allow-empty
@sync # 《操作系统》课程为大家揭秘
在每次 make
执行时
git
目标都会被执行.c
和 .h
添加、强制提交到 Git repo对抄袭代码的一种威慑
Git: 代码快照管理工具
框架代码中的两处非常规 Git 使用
.git
;在服务器执行 git reset
思考题:如何管理自己的代码快照?
回顾:YEMU 模拟器
#include
, #define
, ...)顶层 (top-level) Makefile:
# := -> C #define
NAME := $(shell basename $(PWD))
export MODULE := Lab1
# 变量 -> 字面替换
all: $(NAME)-64 $(NAME)-32
# include -> C #include
include ../Makefile
构建目标
.DEFAULT_GOAL := commit-and-make
commit-and-make: git all
(all 在顶层 Makefile 中定义)multimod-64
: gcc -m64
multimod-32
: gcc -m32
multimod-64.so
: gcc -fPIC -shared -m64
multimod-32.so
: gcc -fPIC -shared -m32
clean
Makefile 真复杂
一个小诀窍
-n
只打印命令不运行-B
强制 make 所有目标make -nB \
| grep -ve '^\(\#\|echo\|mkdir\)' \
| vim -
嘿!其实没那么复杂
gcc -c
(编译) 和一个 gcc
(链接) 诶Read the friendly source code!
更长,更难读
### *Get a more readable version of this Makefile* by `make html` (requires python-markdown)
html:
cat Makefile | sed 's/^\([^#]\)/ \1/g' | \
markdown_py > Makefile.html
.PHONY: html
教会大家 “计算机的正确打开方式”
基本原则:
(RTFM & RTFSC)