xref: /DragonOS/Makefile (revision 7f439c5ddbd2ecffc112149d16983975f523052c)
10aec6827SfslongjinSUBDIRS = kernel user
20aec6827Sfslongjin
3416a802bSfslongjin# ifndef $(EMULATOR)
4416a802bSfslongjinifeq ($(EMULATOR), )
5416a802bSfslongjinexport EMULATOR=__NO_EMULATION__
6416a802bSfslongjinendif
72813126eSlogin# todo: 增加参数,判断是否在QEMU中仿真,若是,则启用该环境变量
82813126eSlogin# export EMULATOR=__QEMU_EMULATION__
90aec6827Sfslongjin
10d328bfceSlogin# 计算cpu核心数
11d328bfceSloginNPROCS:=1
12d328bfceSloginOS:=$(shell uname -s)
13d328bfceSlogin
14d328bfceSloginifeq ($(OS),Linux)
15d328bfceSlogin  NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
16d328bfceSloginendif
17d328bfceSloginifeq ($(OS),Darwin) # Assume Mac OS X
18d328bfceSlogin  NPROCS:=$(shell system_profiler | awk '/Number Of CPUs/{print $4}{next;}')
19d328bfceSloginendif
200aec6827Sfslongjin
21edb21695Sfslongjinexport ARCH=__x86_64__
220aec6827Sfslongjinexport ROOT_PATH=$(shell pwd)
230aec6827Sfslongjin
24e0021523Sloginexport RUSTC=$(shell which rustc)
25e0021523Slogin
260aec6827Sfslongjinexport DEBUG=DEBUG
27416a802bSfslongjinexport GLOBAL_CFLAGS := -mcmodel=large -fno-builtin -m64  -fno-stack-protector -D $(ARCH) -D $(EMULATOR) -O1
280aec6827Sfslongjin
290aec6827Sfslongjinifeq ($(DEBUG), DEBUG)
300aec6827SfslongjinGLOBAL_CFLAGS += -g
310aec6827Sfslongjinendif
32f479f321Sfslongjin
33fbe1e23eSlongjinexport CC=gcc
34416a802bSfslongjin
35f479f321Sfslongjin.PHONY: all
361ab51cb3Sfslongjinall: kernel user
371ab51cb3Sfslongjin
381ab51cb3Sfslongjin
391ab51cb3Sfslongjin.PHONY: kernel
401ab51cb3Sfslongjinkernel:
410b0cce93Sfslongjin	mkdir -p bin/kernel/
422813126eSlogin	$(MAKE) -C ./kernel all || (sh -c "echo 内核编译失败" && exit 1)
43f479f321Sfslongjin
44e2a59dbdSfslongjin.PHONY: user
45e2a59dbdSfslongjinuser:
46e2a59dbdSfslongjin	mkdir -p bin/user/
47d60f1a8fSfslongjin	mkdir -p bin/tmp/user
482813126eSlogin	$(MAKE) -C ./user all || (sh -c "echo 用户程序编译失败" && exit 1)
49e2a59dbdSfslongjin
50f479f321Sfslongjin.PHONY: clean
51f479f321Sfslongjinclean:
52f479f321Sfslongjin	@list='$(SUBDIRS)'; for subdir in $$list; do \
53f479f321Sfslongjin		echo "Clean in dir: $$subdir";\
5405dc7ac7Sfslongjin		cd $$subdir && $(MAKE) clean;\
55f479f321Sfslongjin		cd .. ;\
56f479f321Sfslongjin	done
57e667fff2Sfslongjin
58d328bfceSlogincppcheck-xml:
59d328bfceSlogin	cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) --xml 2> cppcheck.xml
60d328bfceSlogin
61d328bfceSlogincppcheck:
62d328bfceSlogin	cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS)
63d328bfceSlogin
64e667fff2Sfslongjingdb:
65e667fff2Sfslongjin	gdb -n -x tools/.gdbinit
662813126eSlogin
672813126eSlogin# 写入磁盘镜像
682813126eSloginwrite_diskimage:
69*7f439c5dSYJwu2023	sudo sh -c "cd tools && bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=legacy && cd .."
702813126eSlogin
71*7f439c5dSYJwu2023# 写入磁盘镜像(uefi)
72*7f439c5dSYJwu2023write_diskimage-uefi:
73*7f439c5dSYJwu2023	sudo sh -c "cd tools && bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .."
742813126eSlogin# 不编译,直接启动QEMU
752813126eSloginqemu:
76*7f439c5dSYJwu2023	sh -c "cd tools && bash run-qemu.sh --bios=legacy && cd .."
77*7f439c5dSYJwu2023# 不编译,直接启动QEMU(UEFI)
78*7f439c5dSYJwu2023qemu-uefi:
79*7f439c5dSYJwu2023	sh -c "cd tools && bash run-qemu.sh --bios=uefi && cd .."
802813126eSlogin
812813126eSlogin# 编译并写入磁盘镜像
822813126eSloginbuild:
832813126eSlogin	$(MAKE) all -j $(NPROCS)
842813126eSlogin	$(MAKE) write_diskimage || exit 1
852813126eSlogin
862813126eSlogin# 在docker中编译,并写入磁盘镜像
872813126eSlogindocker:
882813126eSlogin	@echo "使用docker构建"
892813126eSlogin	sudo bash tools/build_in_docker.sh || exit 1
902813126eSlogin
91*7f439c5dSYJwu2023# uefi方式启动
92*7f439c5dSYJwu2023run-uefi:
93*7f439c5dSYJwu2023	$(MAKE) all -j $(NPROCS)
94*7f439c5dSYJwu2023	$(MAKE) write_diskimage-uefi || exit 1
95*7f439c5dSYJwu2023	$(MAKE) qemu-uefi
96*7f439c5dSYJwu2023
972813126eSlogin# 编译并启动QEMU
982813126eSloginrun:
992813126eSlogin	$(MAKE) all -j $(NPROCS)
1002813126eSlogin	$(MAKE) write_diskimage || exit 1
1012813126eSlogin	$(MAKE) qemu
1022813126eSlogin
1032813126eSlogin# 在docker中编译,并启动QEMU
1042813126eSloginrun-docker:
1052813126eSlogin	@echo "使用docker构建并运行"
1062813126eSlogin	sudo bash tools/build_in_docker.sh || exit 1
1072813126eSlogin	$(MAKE) qemu
108