xref: /DragonOS/Makefile (revision 2813126e3190c9b3c1a836a647b259a7adbe0cf3)
10aec6827SfslongjinSUBDIRS = kernel user
20aec6827Sfslongjin
3416a802bSfslongjin# ifndef $(EMULATOR)
4416a802bSfslongjinifeq ($(EMULATOR), )
5416a802bSfslongjinexport EMULATOR=__NO_EMULATION__
6416a802bSfslongjinendif
7*2813126eSlogin# todo: 增加参数,判断是否在QEMU中仿真,若是,则启用该环境变量
8*2813126eSlogin# 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/
42*2813126eSlogin	$(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
48*2813126eSlogin	$(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
66*2813126eSlogin
67*2813126eSlogin# 写入磁盘镜像
68*2813126eSloginwrite_diskimage:
69*2813126eSlogin	sudo sh -c "cd tools && bash $(ROOT_PATH)/tools/write_disk_image.sh && cd .."
70*2813126eSlogin
71*2813126eSlogin# 不编译,直接启动QEMU
72*2813126eSloginqemu:
73*2813126eSlogin	sh -c "cd tools && bash run-qemu.sh && cd .."
74*2813126eSlogin
75*2813126eSlogin# 编译并写入磁盘镜像
76*2813126eSloginbuild:
77*2813126eSlogin	$(MAKE) all -j $(NPROCS)
78*2813126eSlogin	$(MAKE) write_diskimage || exit 1
79*2813126eSlogin
80*2813126eSlogin# 在docker中编译,并写入磁盘镜像
81*2813126eSlogindocker:
82*2813126eSlogin	@echo "使用docker构建"
83*2813126eSlogin	sudo bash tools/build_in_docker.sh || exit 1
84*2813126eSlogin
85*2813126eSlogin# 编译并启动QEMU
86*2813126eSloginrun:
87*2813126eSlogin	$(MAKE) all -j $(NPROCS)
88*2813126eSlogin	$(MAKE) write_diskimage || exit 1
89*2813126eSlogin	$(MAKE) qemu
90*2813126eSlogin
91*2813126eSlogin# 在docker中编译,并启动QEMU
92*2813126eSloginrun-docker:
93*2813126eSlogin	@echo "使用docker构建并运行"
94*2813126eSlogin	sudo bash tools/build_in_docker.sh || exit 1
95*2813126eSlogin	$(MAKE) qemu
96