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 240aec6827Sfslongjinexport DEBUG=DEBUG 25416a802bSfslongjinexport GLOBAL_CFLAGS := -mcmodel=large -fno-builtin -m64 -fno-stack-protector -D $(ARCH) -D $(EMULATOR) -O1 260aec6827Sfslongjin 270aec6827Sfslongjinifeq ($(DEBUG), DEBUG) 280aec6827SfslongjinGLOBAL_CFLAGS += -g 290aec6827Sfslongjinendif 30f479f321Sfslongjin 315ed4cd46Sguanjinquan# ifeq ($(DragonOS_GCC), ) 325ed4cd46Sguanjinquan# $(error 尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装) 335ed4cd46Sguanjinquan# endif 345ed4cd46Sguanjinquan 355ed4cd46Sguanjinquanexport CC=$(DragonOS_GCC)/x86_64-elf-gcc 365ed4cd46Sguanjinquanexport LD=ld 375ed4cd46Sguanjinquanexport AS=$(DragonOS_GCC)/x86_64-elf-as 385ed4cd46Sguanjinquanexport NM=$(DragonOS_GCC)/x86_64-elf-nm 39d4f3de93Sloginexport AR=$(DragonOS_GCC)/x86_64-elf-ar 405ed4cd46Sguanjinquanexport OBJCOPY=$(DragonOS_GCC)/x86_64-elf-objcopy 415ed4cd46Sguanjinquan 42416a802bSfslongjin 43f479f321Sfslongjin.PHONY: all 441ab51cb3Sfslongjinall: kernel user 451ab51cb3Sfslongjin 461ab51cb3Sfslongjin 471ab51cb3Sfslongjin.PHONY: kernel 481ab51cb3Sfslongjinkernel: 490b0cce93Sfslongjin mkdir -p bin/kernel/ 50*74bde36eSguanjinquan @if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi 512813126eSlogin $(MAKE) -C ./kernel all || (sh -c "echo 内核编译失败" && exit 1) 52f479f321Sfslongjin 53e2a59dbdSfslongjin.PHONY: user 54e2a59dbdSfslongjinuser: 55e2a59dbdSfslongjin mkdir -p bin/user/ 56d60f1a8fSfslongjin mkdir -p bin/tmp/user 57*74bde36eSguanjinquan @if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi 582813126eSlogin $(MAKE) -C ./user all || (sh -c "echo 用户程序编译失败" && exit 1) 59e2a59dbdSfslongjin 60f479f321Sfslongjin.PHONY: clean 61f479f321Sfslongjinclean: 62f479f321Sfslongjin @list='$(SUBDIRS)'; for subdir in $$list; do \ 63f479f321Sfslongjin echo "Clean in dir: $$subdir";\ 6405dc7ac7Sfslongjin cd $$subdir && $(MAKE) clean;\ 65f479f321Sfslongjin cd .. ;\ 66f479f321Sfslongjin done 67e667fff2Sfslongjin 68d328bfceSlogincppcheck-xml: 69d328bfceSlogin cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) --xml 2> cppcheck.xml 70d328bfceSlogin 71d328bfceSlogincppcheck: 72d328bfceSlogin cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) 73d328bfceSlogin 74e667fff2Sfslongjingdb: 75e667fff2Sfslongjin gdb -n -x tools/.gdbinit 762813126eSlogin 772813126eSlogin# 写入磁盘镜像 782813126eSloginwrite_diskimage: 795ed4cd46Sguanjinquan bash -c "cd tools && bash grub_auto_install.sh && sudo bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=legacy && cd .." 802813126eSlogin 817f439c5dSYJwu2023# 写入磁盘镜像(uefi) 827f439c5dSYJwu2023write_diskimage-uefi: 835ed4cd46Sguanjinquan bash -c "cd tools && bash grub_auto_install.sh && sudo bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .." 842813126eSlogin# 不编译,直接启动QEMU 852813126eSloginqemu: 867f439c5dSYJwu2023 sh -c "cd tools && bash run-qemu.sh --bios=legacy && cd .." 877f439c5dSYJwu2023# 不编译,直接启动QEMU(UEFI) 887f439c5dSYJwu2023qemu-uefi: 897f439c5dSYJwu2023 sh -c "cd tools && bash run-qemu.sh --bios=uefi && cd .." 902813126eSlogin 912813126eSlogin# 编译并写入磁盘镜像 922813126eSloginbuild: 932813126eSlogin $(MAKE) all -j $(NPROCS) 942813126eSlogin $(MAKE) write_diskimage || exit 1 952813126eSlogin 962813126eSlogin# 在docker中编译,并写入磁盘镜像 972813126eSlogindocker: 982813126eSlogin @echo "使用docker构建" 992813126eSlogin sudo bash tools/build_in_docker.sh || exit 1 1005ed4cd46Sguanjinquan $(MAKE) write_diskimage || exit 1 1012813126eSlogin 1027f439c5dSYJwu2023# uefi方式启动 1037f439c5dSYJwu2023run-uefi: 1047f439c5dSYJwu2023 $(MAKE) all -j $(NPROCS) 1057f439c5dSYJwu2023 $(MAKE) write_diskimage-uefi || exit 1 1067f439c5dSYJwu2023 $(MAKE) qemu-uefi 1077f439c5dSYJwu2023 1082813126eSlogin# 编译并启动QEMU 1092813126eSloginrun: 1102813126eSlogin $(MAKE) all -j $(NPROCS) 1112813126eSlogin $(MAKE) write_diskimage || exit 1 1122813126eSlogin $(MAKE) qemu 1132813126eSlogin 1142813126eSlogin# 在docker中编译,并启动QEMU 1152813126eSloginrun-docker: 1162813126eSlogin @echo "使用docker构建并运行" 1172813126eSlogin sudo bash tools/build_in_docker.sh || exit 1 1185ed4cd46Sguanjinquan $(MAKE) write_diskimage || exit 1 1192813126eSlogin $(MAKE) qemu 120