<commit_before>  #################################################
 #              IncludeOS makefile               #
#################################################

# Compiler/Linker
###################################################
OS = /usr/local/IncludeOS
OSLIB = $(OS)/i686-elf

DEBUG_OPTS = -ggdb3

CC  = $(OS)/bin/i686-elf-gcc
GPP = $(OS)/bin/i686-elf-g++
CPP = clang++ -target i686-elf

LD  = $(OS)/bin/i686-elf-ld

GCC_VER = $(shell $(CC) -dumpversion)
LIBGCC = $(OS)/lib/gcc/i686-elf/$(GCC_VER)/libgcc.a

INCLUDES = -I$(OSLIB)/include -Iinclude -I../abi -I../stdlib
LIBS     = $(OSLIB)/lib $(LIBGCC)

CAPABS  =  -msse3 #-O2 -Ofast -mstackrealign   # Needed for 16-byte stack alignment (SSE) -Ofast
WARNS   = -Wall -Wextra #-pedantic
CCOPTS	= $(CAPABS) $(WARNS) -c -m32 -fno-stack-protector -fno-builtin -march=i686 $(INCLUDES) -lgcc
CPPOPTS = $(CAPABS) $(WARNS) -c -m32 -std=c++11 -fno-stack-protector  $(INCLUDES) #-ffreestanding -nostdlib -fno-builtin


LDOPTS =  -nostdlib -melf_i386 -N --eh-frame-hdr --script=linker.ld #-ffreestanding


# Objects
###################################################
CXXABI     = $(shell find ./crt/cxxabi -type f -name "*.cpp")
CXXABI_OBJ = $(CXXABI:.cpp=.o)

OS_OBJECTS = kernel_start.o syscalls.o interrupts.o class_os.o \
						 crt/c_abi.o crt/cxx_abi.o util/memstream.o \
						 class_irq_handler.o class_pci_manager.o \
						 hw/pic.o hw/class_pci_device.o hw/class_dev.o \
						 virtio/class_virtio.o virtio/class_virtionet.o virtio/class_virtio_queue.o \
						 net/class_ethernet.o net/class_arp.o net/class_ip4.o net/class_ip6.o\
						 net/class_udp.o net/class_icmp.o net/class_inet.o net/inet.o\
						 net/class_packet.o net/dns/dns.o

# Libraries
###################################################
LIBC_OBJ = $(OSLIB)/lib/libc.a
LIBG_OBJ = $(OSLIB)/lib/libg.a 
LIBM_OBJ = $(OSLIB)/lib/libm.a 

# Header dependencies (rebuild if header changed)
###################################################
OS_DEPS = $(OS_OBJECTS:.o=.d)


# Complete build
###################################################
# A complete build includes:
# - a bootloader
# - an OS library for the service to link against
all: bootloader libc++abi.a os.a 
	echo "TEST: OSLIB: '"$(OS)"'"

stripped: LDOPTS += -s #strip all
stripped: bootloader os.a


# The same, but with debugging symbols (OBS: Dramatically increases binary size)
debug: CCOPTS  += $(DEBUG_OPTS)
debug: CPPOPTS += $(DEBUG_OPTS)
debug: LDOPTS  += -M --verbose

debug: OBJ_LIST += $(LIBG_OBJ)

debug: all  #Don't wanna call 'all', since it strips debug info

# Runtime for the (test) service

CRTBEGIN:=$(shell $(GPP) -print-file-name=crtbegin.o)
CRTEND:=$(shell $(GPP) -print-file-name=crtend.o)
crt%.o: crt/crt%.s
	@echo "\n>> Assembling C runtime:" $@
	$(CPP) $(CPPOPTS) -x assembler-with-cpp $<

LIBGCC = $(OS)/lib/gcc/i686-elf/$(GCC_VER)/libgcc.a
LIBCPP = $(OS)/lib/libc++.a libc++abi.a 
LIBS_OBJ = os.a $(LIBCPP) $(LIBC_OBJ) $(LIBM_OBJ) $(LIBGCC)

test_service.o: test_service.cpp
	$(CPP) -MMD $(CPPOPTS) $(DEBUG_OPTS) -o $@ $< 

# AS-assembled object files
%.o: %.s
	@echo "\n>> Assembling GNU 'as' files"
	$(CPP) $(CPPOPTS) -x assembler-with-cpp $<

test:  debug crti.o crtn.o test_service.o
	$(LD) $(LDOPTS) $(CRTBEGIN) crti.o test_service.o $(LIBS_OBJ) $(CRTEND) crtn.o -o test_service

# OS
libc++abi.a: $(CXXABI_OBJ)
	ar rcs $@ $(CXXABI_OBJ)

os.a: $(OS_OBJECTS)
	@echo "\n>> Building the OS library"
	ar rcs $@ $(OS_OBJECTS)

install: #os.a bootloader
	@echo "\n>> Installing..."
	cp bootloader $(OS)/
	cp os.a $(OS)/lib
	cp libc++abi.a $(OS)/lib
	cp libc++.a $(OS)/lib
	mkdir -p $(OS)/crt
	cp crt/crt*.s $(OS)/crt
	cp -r ../abi $(OS)/
	cp -r ../stdlib $(OS)/
	mkdir -p $(OS)/mod
	#cp -r ../mod/rapidjson $(OS)/mod
	#cp -r ../mod/protobuf $(OS)/mod
	cp linker.ld $(OS)/
	@echo "\nDone!"

# Object files
###################################################
%.o: %.c
	$(CC) -MMD $(CCOPTS) -o $@ $< 

%.o: %.cpp
	@echo "\n>> Compiling " $@
	$(CPP) -MMD $(CPPOPTS) -o $@ $< 

# AS-assembled object files
%.o: %.s
	@echo "\n>> Assembling GNU 'as' files"
	$(CPP) $(CPPOPTS) -x assembler-with-cpp $<

# Bootloader
###################################################
# Nasm-based bootloader
bootloader: bootloader.asm
	@echo "\n>> Assembling bootloader"
	nasm -f bin -o bootloader bootloader.asm

# Optional, for gcc-assembled bootloader
bootloader_s: bootloader.s
	$(CC) $(CCOPTS) -o $@ $<


# Etags
###################################################
etags:
	@echo "\n>> Updating emacs tags "
	- find ../ -name "*.[hc]pp" | grep -v ".*\#.*" | etags -


# Cleanup
###################################################
clean: 
	$(RM) $(OS_OBJECTS) $(CXXABI_OBJ) $(OS_DEPS)
	$(RM) os.a
	$(RM) bootloader	
	$(RM) test_service.o test_service.img

-include $(OS_DEPS)<commit_msg>Made separate debug-target with -O0 etc.<commit_after>  #################################################
 #              IncludeOS makefile               #
#################################################

# Compiler/Linker
###################################################
OS = /usr/local/IncludeOS
OSLIB = $(OS)/i686-elf

DEBUG_OPTS = -ggdb3

CC  = $(OS)/bin/i686-elf-gcc
GPP = $(OS)/bin/i686-elf-g++
CPP = clang++ -target i686-elf

LD  = $(OS)/bin/i686-elf-ld

GCC_VER = $(shell $(CC) -dumpversion)
LIBGCC = $(OS)/lib/gcc/i686-elf/$(GCC_VER)/libgcc.a

INCLUDES = -I$(OSLIB)/include -Iinclude -I../abi -I../stdlib
LIBS     = $(OSLIB)/lib $(LIBGCC)

all: CAPABS  =  -msse3 -Ofast -mstackrealign   # Needed for 16-byte stack alignment (SSE) -Ofast
debug: CAPABS = -msse3 -O0
stripped: CAPABS = -msse3 -Os

WARNS   = -Wall -Wextra #-pedantic

CCOPTS	= $(CAPABS) $(WARNS) -c -m32 -fno-stack-protector -fno-builtin -march=i686 $(INCLUDES) -lgcc
CPPOPTS = $(CAPABS) $(WARNS) -c -m32 -std=c++11 -fno-stack-protector  $(INCLUDES) #-ffreestanding -nostdlib -fno-builtin


LDOPTS =  -nostdlib -melf_i386 -N --eh-frame-hdr --script=linker.ld #-ffreestanding


# Objects
###################################################
CXXABI     = $(shell find ./crt/cxxabi -type f -name "*.cpp")
CXXABI_OBJ = $(CXXABI:.cpp=.o)

OS_OBJECTS = kernel_start.o syscalls.o interrupts.o class_os.o \
						 crt/c_abi.o crt/cxx_abi.o util/memstream.o \
						 class_irq_handler.o class_pci_manager.o \
						 hw/pic.o hw/class_pci_device.o hw/class_dev.o \
						 virtio/class_virtio.o virtio/class_virtionet.o virtio/class_virtio_queue.o \
						 net/class_ethernet.o net/class_arp.o net/class_ip4.o net/class_ip6.o\
						 net/class_udp.o net/class_icmp.o net/class_inet.o net/inet.o\
						 net/class_packet.o net/dns/dns.o

# Libraries
###################################################
LIBC_OBJ = $(OSLIB)/lib/libc.a
LIBG_OBJ = $(OSLIB)/lib/libg.a 
LIBM_OBJ = $(OSLIB)/lib/libm.a 

# Header dependencies (rebuild if header changed)
###################################################
OS_DEPS = $(OS_OBJECTS:.o=.d)


# Complete build
###################################################
# A complete build includes:
# - a bootloader
# - an OS library for the service to link against
all: bootloader libc++abi.a os.a 
	echo "TEST: OSLIB: '"$(OS)"'"

stripped: LDOPTS += -s #strip all
stripped: bootloader libc++abi.a os.a
stripped: test


# The same, but with debugging symbols (OBS: Dramatically increases binary size)
debug: CCOPTS  += $(DEBUG_OPTS)
debug: CPPOPTS += $(DEBUG_OPTS)
#debug: LDOPTS  += #-M #--verbose
debug: OBJ_LIST += $(LIBG_OBJ)
debug: bootloader libc++abi.a os.a # Can't call all, since it changes capabs
debug: test

# Runtime for the (test) service

CRTBEGIN:=$(shell $(GPP) -print-file-name=crtbegin.o)
CRTEND:=$(shell $(GPP) -print-file-name=crtend.o)
crt%.o: crt/crt%.s
	@echo "\n>> Assembling C runtime:" $@
	$(CPP) $(CPPOPTS) -x assembler-with-cpp $<

LIBGCC = $(OS)/lib/gcc/i686-elf/$(GCC_VER)/libgcc.a
LIBCPP = $(OS)/lib/libc++.a libc++abi.a 
LIBS_OBJ = os.a $(LIBCPP) $(LIBC_OBJ) $(LIBM_OBJ) $(LIBGCC)

test_service.o: test_service.cpp
	@echo "\n>> Building test service"
	$(CPP) -MMD $(CPPOPTS) -o $@ $< 

# AS-assembled object files
%.o: %.s
	@echo "\n>> Assembling GNU 'as' files"
	$(CPP) $(CPPOPTS) -x assembler-with-cpp $<

test:  crti.o crtn.o test_service.o
	@echo "\n>> Linking test service"
	$(LD) $(LDOPTS) $(CRTBEGIN) crti.o test_service.o $(LIBS_OBJ) $(CRTEND) crtn.o -o test_service

# OS
libc++abi.a: $(CXXABI_OBJ)
	ar rcs $@ $(CXXABI_OBJ)

os.a: $(OS_OBJECTS)
	@echo "\n>> Building the OS library"
	ar rcs $@ $(OS_OBJECTS)

install: #os.a bootloader
	@echo "\n>> Installing..."
	cp bootloader $(OS)/
	cp os.a $(OS)/lib
	cp libc++abi.a $(OS)/lib
	cp libc++.a $(OS)/lib
	mkdir -p $(OS)/crt
	cp crt/crt*.s $(OS)/crt
	cp -r ../abi $(OS)/
	cp -r ../stdlib $(OS)/
	mkdir -p $(OS)/mod
	#cp -r ../mod/rapidjson $(OS)/mod
	#cp -r ../mod/protobuf $(OS)/mod
	cp linker.ld $(OS)/
	@echo "\nDone!"

# Object files
###################################################
%.o: %.c
	$(CC) -MMD $(CCOPTS) -o $@ $< 

%.o: %.cpp
	@echo "\n>> Compiling " $@
	$(CPP) -MMD $(CPPOPTS) -o $@ $< 

# AS-assembled object files
%.o: %.s
	@echo "\n>> Assembling GNU 'as' files"
	$(CPP) $(CPPOPTS) -x assembler-with-cpp $<

# Bootloader
###################################################
# Nasm-based bootloader
bootloader: bootloader.asm
	@echo "\n>> Assembling bootloader"
	nasm -f bin -o bootloader bootloader.asm

# Optional, for gcc-assembled bootloader
bootloader_s: bootloader.s
	$(CC) $(CCOPTS) -o $@ $<


# Etags
###################################################
etags:
	@echo "\n>> Updating emacs tags "
	- find ../ -name "*.[hc]pp" | grep -v ".*\#.*" | etags -


# Cleanup
###################################################
clean: 
	$(RM) $(OS_OBJECTS) $(CXXABI_OBJ) $(OS_DEPS)
	$(RM) os.a
	$(RM) bootloader	
	$(RM) test_service.o test_service test_service.img

-include $(OS_DEPS)
{'fraction_non_alphanumeric': 0.2788865008699212, 'fraction_numerical': 0.008494524613652646, 'mean_word_length': 3.830449826989619, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 39, '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': '6364017', 'n_tokens_mistral': 4071, 'n_tokens_neox': 3706, 'n_words': 861}