1SUBDIRS = kernel user 2 3# ifndef $(EMULATOR) 4ifeq ($(EMULATOR), ) 5export EMULATOR=__NO_EMULATION__ 6endif 7 8# 计算cpu核心数 9NPROCS:=1 10OS:=$(shell uname -s) 11 12ifeq ($(OS),Linux) 13 NPROCS:=$(shell grep -c ^processor /proc/cpuinfo) 14endif 15ifeq ($(OS),Darwin) # Assume Mac OS X 16 NPROCS:=$(shell system_profiler | awk '/Number Of CPUs/{print $4}{next;}') 17endif 18 19export ARCH=__x86_64__ 20export ROOT_PATH=$(shell pwd) 21 22export RUSTC=$(shell which rustc) 23 24export DEBUG=DEBUG 25export GLOBAL_CFLAGS := -mcmodel=large -fno-builtin -m64 -fno-stack-protector -D $(ARCH) -D $(EMULATOR) -O1 26 27ifeq ($(DEBUG), DEBUG) 28GLOBAL_CFLAGS += -g 29endif 30 31export CC=gcc 32 33.PHONY: all 34all: kernel user 35 36 37.PHONY: kernel 38kernel: 39 mkdir -p bin/kernel/ 40 @list='./kernel'; for subdir in $$list; do \ 41 echo "make all in $$subdir";\ 42 cd $$subdir;\ 43 $(MAKE) all;\ 44 if [ "$$?" != "0" ]; then\ 45 echo "内核编译失败";\ 46 exit 1;\ 47 fi;\ 48 cd ..;\ 49 done 50 51.PHONY: user 52user: 53 mkdir -p bin/user/ 54 mkdir -p bin/tmp/user 55 @list='./user'; for subdir in $$list; do \ 56 echo "make all in $$subdir";\ 57 cd $$subdir;\ 58 $(MAKE) all;\ 59 if [ "$$?" != "0" ]; then\ 60 echo "用户态程序编译失败";\ 61 exit 1;\ 62 fi;\ 63 cd ..;\ 64 done 65 66.PHONY: clean 67clean: 68 @list='$(SUBDIRS)'; for subdir in $$list; do \ 69 echo "Clean in dir: $$subdir";\ 70 cd $$subdir && $(MAKE) clean;\ 71 cd .. ;\ 72 done 73 74cppcheck-xml: 75 cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) --xml 2> cppcheck.xml 76 77cppcheck: 78 cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) 79 80gdb: 81 gdb -n -x tools/.gdbinit 82