<commit_before>CROSS_PATH = /Users/sonald/crossgcc/bin
CXX = $(CROSS_PATH)/i686-elf-g++
CPP = $(CROSS_PATH)/i686-elf-cpp
CC = $(CROSS_PATH)/i686-elf-gcc
CXXFLAGS = -std=c++11 -I./include -ffreestanding  \
		 -O2 -Wall -Wextra -fno-exceptions -fno-rtti -DDEBUG

USER_FLAGS = -std=c++11 -I./include -ffreestanding  \
	   -O2 -Wall -Wextra -fno-exceptions -fno-rtti -DDEBUG

OBJS_DIR = objs

crtbegin_o=$(shell $(CXX) $(CXXFLAGS) -print-file-name=crtbegin.o)
crtend_o=$(shell $(CXX) $(CXXFLAGS) -print-file-name=crtend.o)

kernel_srcs = kern/boot.s kern/core/irq_stubs.s kern/core/context.s \
	$(wildcard kern/*.cc) \
	$(wildcard kern/runtime/*.cc) \
	$(wildcard kern/core/*.cc) \
	$(wildcard kern/drv/*.cc) \
	$(wildcard lib/*.cc)

kernel_objs := $(patsubst %.cc, $(OBJS_DIR)/%.o, $(kernel_srcs))
kernel_objs := $(patsubst %.s, $(OBJS_DIR)/%.o, $(kernel_objs))

kern_objs := $(OBJS_DIR)/kern/runtime/crti.o $(crtbegin_o) \
	$(kernel_objs) \
	$(crtend_o) $(OBJS_DIR)/kern/runtime/crtn.o

DEPFILES := $(patsubst %.cc, $(OBJS_DIR)/%.d, $(kernel_srcs))
DEPFILES := $(patsubst %.s, $(OBJS_DIR)/%.d, $(DEPFILES))

all: run ramfs_gen

-include $(DEPFILES)

$(OBJS_DIR)/kern/%.d: kern/%.cc 
	@mkdir -p $(@D)
	$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@

$(OBJS_DIR)/lib/%.d: lib/%.cc 
	@mkdir -p $(@D)
	$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@

# print makefile variable (for debug purpose)
print-%: ; @echo $* = $($*)

debug: kernel
	qemu-system-i386 -kernel kernel -initrd initramfs.img -m 32 -s -monitor stdio \
	-drive file=hd.img,format=raw -vga vmware

run: kernel echo hd.img
	qemu-system-i386 -m 32 -s -monitor stdio -hda hd.img -vga vmware 

hd.img: kernel 
	hdiutil attach hd.img
	cp kernel /Volumes/SOS
	cp initramfs.img /Volumes/SOS
	#hdiutil detach disk2

kernel: $(kern_objs) kern/kernel.ld
	$(CXX) -T kern/kernel.ld -O2 -nostdlib -o $@ $^ -lgcc

$(OBJS_DIR)/kern/%.o: kern/%.cc 
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) -c -o $@ $<
			
$(OBJS_DIR)/kern/%.o: kern/%.s
	@mkdir -p $(@D)
	nasm -f elf32 -o $@ $<

$(OBJS_DIR)/lib/%.o: lib/%.cc 
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) -c -o $@ $<

# tools
ramfs_gen: tools/ramfs_gen.c
	gcc -o $@ $^

# user prog
echo: user/echo.c user/libc.c lib/sprintf.cc user/user.ld 
	@mkdir -p $(@D)
	$(CXX) $(USER_FLAGS) -T user/user.ld -nostdlib -o $@ $^ 
	./ramfs_gen README.md user/echo.c echo

	
.PHONY: clean

clean:
	-rm $(OBJS_DIR)/kern/*.o 
	-rm $(OBJS_DIR)/kern/*.d
	-rm kernel<commit_msg>fix make clean<commit_after>CROSS_PATH = /Users/sonald/crossgcc/bin
CXX = $(CROSS_PATH)/i686-elf-g++
CPP = $(CROSS_PATH)/i686-elf-cpp
CC = $(CROSS_PATH)/i686-elf-gcc
CXXFLAGS = -std=c++11 -I./include -ffreestanding  \
		 -O2 -Wall -Wextra -fno-exceptions -fno-rtti -DDEBUG

USER_FLAGS = -std=c++11 -I./include -ffreestanding  \
	   -O2 -Wall -Wextra -fno-exceptions -fno-rtti -DDEBUG

OBJS_DIR = objs

crtbegin_o=$(shell $(CXX) $(CXXFLAGS) -print-file-name=crtbegin.o)
crtend_o=$(shell $(CXX) $(CXXFLAGS) -print-file-name=crtend.o)

kernel_srcs = kern/boot.s kern/core/irq_stubs.s kern/core/context.s \
	$(wildcard kern/*.cc) \
	$(wildcard kern/runtime/*.cc) \
	$(wildcard kern/core/*.cc) \
	$(wildcard kern/drv/*.cc) \
	$(wildcard lib/*.cc)

kernel_objs := $(patsubst %.cc, $(OBJS_DIR)/%.o, $(kernel_srcs))
kernel_objs := $(patsubst %.s, $(OBJS_DIR)/%.o, $(kernel_objs))

kern_objs := $(OBJS_DIR)/kern/runtime/crti.o $(crtbegin_o) \
	$(kernel_objs) \
	$(crtend_o) $(OBJS_DIR)/kern/runtime/crtn.o

DEPFILES := $(patsubst %.cc, $(OBJS_DIR)/%.d, $(kernel_srcs))
DEPFILES := $(patsubst %.s, $(OBJS_DIR)/%.d, $(DEPFILES))

all: run ramfs_gen

-include $(DEPFILES)

$(OBJS_DIR)/kern/%.d: kern/%.cc 
	@mkdir -p $(@D)
	$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@

$(OBJS_DIR)/lib/%.d: lib/%.cc 
	@mkdir -p $(@D)
	$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@

# print makefile variable (for debug purpose)
print-%: ; @echo $* = $($*)

debug: kernel
	qemu-system-i386 -kernel kernel -initrd initramfs.img -m 32 -s -monitor stdio \
	-drive file=hd.img,format=raw -vga vmware

run: kernel echo hd.img
	qemu-system-i386 -m 32 -s -monitor stdio -hda hd.img -vga vmware 

hd.img: kernel 
	hdiutil attach hd.img
	cp kernel /Volumes/SOS
	cp initramfs.img /Volumes/SOS
	#hdiutil detach disk2

kernel: $(kern_objs) kern/kernel.ld
	$(CXX) -T kern/kernel.ld -O2 -nostdlib -o $@ $^ -lgcc

$(OBJS_DIR)/kern/%.o: kern/%.cc 
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) -c -o $@ $<
			
$(OBJS_DIR)/kern/%.o: kern/%.s
	@mkdir -p $(@D)
	nasm -f elf32 -o $@ $<

$(OBJS_DIR)/lib/%.o: lib/%.cc 
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) -c -o $@ $<

# tools
ramfs_gen: tools/ramfs_gen.c
	gcc -o $@ $^

# user prog
echo: user/echo.c user/libc.c lib/sprintf.cc user/user.ld 
	@mkdir -p $(@D)
	$(CXX) $(USER_FLAGS) -T user/user.ld -nostdlib -o $@ $^ 
	./ramfs_gen README.md user/echo.c echo

	
.PHONY: clean

clean:
	-rm $(OBJS_DIR)/kern/*.o 
	-rm $(OBJS_DIR)/lib/*.o 
	-rm $(OBJS_DIR)/kern/core/*.o 
	-rm $(OBJS_DIR)/kern/runtime/*.o 
	-rm $(OBJS_DIR)/kern/drv/*.o 
	-rm $(OBJS_DIR)/kern/*.d
	-rm $(OBJS_DIR)/kern/core/*.d 
	-rm $(OBJS_DIR)/kern/runtime/*.d 
	-rm $(OBJS_DIR)/kern/drv/*.d
	-rm $(OBJS_DIR)/lib/*.d 
	-rm kernel
{'fraction_non_alphanumeric': 0.22547870261821024, 'fraction_numerical': 0.011332551778038297, 'mean_word_length': 3.2872696817420435, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4449160', 'n_tokens_mistral': 2540, 'n_tokens_neox': 2336, 'n_words': 469}