<commit_before># Makefile for asmos (SB1?). Copyright by <NAME>, 2002-2013

.PHONY: all clean install commit

CP=cp

CCACHE ?= ccache
ifneq ($(USE_CROSS),NO)
CROSS := x86_64-elf-
export PATH := $(PATH):$(CURDIR)/toolchain/cross/bin
else
CROSS :=
endif
CC := $(CROSS)gcc
CXX := $(CROSS)g++

export LD := $(CROSS)ld
export OBJCOPY := $(CROSS)objcopy
export AS := $(CROSS)as
export CC := $(CCACHE) $(CC)
export CXX := $(CCACHE) $(CXX)

SYSTEM := $(shell uname -s)

YASM ?= yasm/yasm
ifeq (yasm, $(YASM))
YASMDEP := $(shell which $(YASM))
else
YASMDEP := $(YASM)
endif
YASMFLAGS = -Werror -i $(ASMDIR) -i include

ifeq ($(VERBOSE),YES)
CP=cp -v
else
HUSH_ASM=@echo ' [ASM]\t'$@;
#HUSH_ASM_DEP=@echo ' [DEP]\t'$@;
HUSH_ASM_DEP=@
HUSH_CC= @echo ' [CC]\t'$@;
HUSH_CXX=@echo ' [CXX]\t'$@;
HUSH_LD= @echo ' [LD]\t'$@;
HUSH_OBJCOPY= @echo ' [OBJCOPY]\t'$@;
SIZE_ASM=@echo ' [ASM]\t'$@: `stat -c %s $@` bytes
SIZE_LD= @echo ' [LD]\t'$@: `stat -c %s $@` bytes
SIZE_OBJCOPY= @echo ' [OBJCOPY]\t'$@: `stat -c %s $@` bytes
endif

OUTDIR       := out
# Interesting experiment though it currently doesn't work :)
# (The modules are in total about 10kB smaller in X32 mode.)
ifeq ($(X32), YES)
OUTDIR       := out/x32
endif
ACPICA_OUT   := $(OUTDIR)/cuser/acpica
ACPICA       := acpica
LWIP_OUT     := $(OUTDIR)/cuser/lwip
LWIP         := lwip
GRUBDIR      := $(OUTDIR)/grub
ASMDIR       := kasm
MOD_ASMFILES := user/newproc.asm user/gettime.asm user/loop.asm user/shell.asm
MOD_ASMFILES += user/test_puts.asm user/test_xmm.asm
MOD_ASMFILES += kern/console.asm kern/pic.asm kern/irq.asm
ASMFILES     := $(ASMDIR)/kstart.asm $(MOD_ASMFILES)
MOD_CFILES   := cuser/helloworld.c cuser/zeropage.c
MOD_CFILES   += cuser/test_maps.c cuser/e1000.c cuser/apic.c cuser/timer_test.c
MOD_CFILES   += cuser/bochsvga.c cuser/fbtest.c cuser/acpi_debugger.c
MOD_CFILES   += cuser/ioapic.c
MOD_OFILES   := $(MOD_CFILES:%.c=$(OUTDIR)/%.o)
MOD_ELFS     := $(MOD_CFILES:%.c=$(OUTDIR)/%.elf)
MOD_ELFS     += $(OUTDIR)/cuser/acpica.elf $(OUTDIR)/cuser/lwip.elf
MODFILES     := $(MOD_ASMFILES:%.asm=$(GRUBDIR)/%.mod) $(MOD_CFILES:%.c=$(GRUBDIR)/%.mod) $(GRUBDIR)/cuser/acpica.mod $(GRUBDIR)/cuser/lwip.mod
DEPFILES     := $(ASMFILES:%.asm=$(OUTDIR)/%.d) $(MOD_OFILES:.o=.d)
ASMOUTS      := \
	$(GRUBDIR)/kstart.b \
	$(MODFILES) \
	$(ASMFILES:%.asm=$(OUTDIR)/%.b) \
	$(ASMFILES:.asm=.map) $(ASMFILES:.asm=.lst) \
	$(DEPFILES)
UTIL_BINS    := utils/cpuid utils/rflags

all: $(OUTDIR)/grub.iso
all: $(MOD_ELFS)
all: $(UTIL_BINS)

.SECONDARY: $(ASMFILES:%.asm=$(OUTDIR)/%.b) $(MOD_OFILES)

clean::
	rm -fr $(OUTDIR)
	rm -f cpuid rflags

%: %.cpp
	$(HUSH_CXX) $(CXX) $(CXXFLAGS) -o $@ $<

%: %.c
	$(HUSH_CC) $(CC) $(CFLAGS) -o $@ $<

-include $(DEPFILES)

$(OUTDIR)/%.d: %.asm $(YASMDEP)
	@mkdir -p $(@D)
	$(HUSH_ASM_DEP) $(YASM) $(YASMFLAGS) -e -M $< -o $(@:.d=.b) > $(@)

$(OUTDIR)/%.b: %.asm $(OUTDIR)/%.d $(YASMDEP)
	@mkdir -p $(@D)
	$(HUSH_ASM) $(YASM) $(YASMFLAGS) -f bin $< -o $@ -L nasm -l $(OUTDIR)/$*.lst --mapfile=$(OUTDIR)/$*.map
	$(SIZE_ASM)

-include $(OUTDIR)/start32.d

$(OUTDIR)/start32.o: kasm/start32.asm $(YASMDEP)
	@mkdir -p $(@D)
	$(HUSH_ASM_DEP) $(YASM) $(YASMFLAGS) -e -M $< -o $@ > $(@:.o=.d)
	$(HUSH_ASM) $(YASM) $(YASMFLAGS) -f elf64 -g dwarf2 $< -o $@ -L nasm -l $(OUTDIR)/start32.lst
	$(SIZE_ASM)

$(OUTDIR)/kstart.b: $(INLINE_MODULES)

%.asm.pp: %.asm $(YASMDEP)
	$(YASM) -i . -f bin -o $@ -e -L nasm $<

$(GRUBDIR)/%.b: $(OUTDIR)/kasm/%.b
	@mkdir -p $(@D)
	@$(CP) $< $@<commit_msg>Use host gcc to build utilities<commit_after># Makefile for asmos (SB1?). Copyright by <NAME>, 2002-2013

.PHONY: all clean install commit

CP=cp

CCACHE ?= ccache
ifneq ($(USE_CROSS),NO)
CROSS := x86_64-elf-
export PATH := $(PATH):$(CURDIR)/toolchain/cross/bin
else
CROSS :=
endif
CC := $(CROSS)gcc
CXX := $(CROSS)g++
HOST_CC := gcc
HOST_CXX := g++

export LD := $(CROSS)ld
export OBJCOPY := $(CROSS)objcopy
export AS := $(CROSS)as
export CC := $(CCACHE) $(CC)
export CXX := $(CCACHE) $(CXX)

SYSTEM := $(shell uname -s)

YASM ?= yasm/yasm
ifeq (yasm, $(YASM))
YASMDEP := $(shell which $(YASM))
else
YASMDEP := $(YASM)
endif
YASMFLAGS = -Werror -i $(ASMDIR) -i include

ifeq ($(VERBOSE),YES)
CP=cp -v
else
HUSH_ASM=@echo ' [ASM]\t'$@;
#HUSH_ASM_DEP=@echo ' [DEP]\t'$@;
HUSH_ASM_DEP=@
HUSH_CC= @echo ' [CC]\t'$@;
HUSH_CXX=@echo ' [CXX]\t'$@;
HUSH_LD= @echo ' [LD]\t'$@;
HUSH_OBJCOPY= @echo ' [OBJCOPY]\t'$@;
SIZE_ASM=@echo ' [ASM]\t'$@: `stat -c %s $@` bytes
SIZE_LD= @echo ' [LD]\t'$@: `stat -c %s $@` bytes
SIZE_OBJCOPY= @echo ' [OBJCOPY]\t'$@: `stat -c %s $@` bytes
endif

OUTDIR       := out
# Interesting experiment though it currently doesn't work :)
# (The modules are in total about 10kB smaller in X32 mode.)
ifeq ($(X32), YES)
OUTDIR       := out/x32
endif
ACPICA_OUT   := $(OUTDIR)/cuser/acpica
ACPICA       := acpica
LWIP_OUT     := $(OUTDIR)/cuser/lwip
LWIP         := lwip
GRUBDIR      := $(OUTDIR)/grub
ASMDIR       := kasm
MOD_ASMFILES := user/newproc.asm user/gettime.asm user/loop.asm user/shell.asm
MOD_ASMFILES += user/test_puts.asm user/test_xmm.asm
MOD_ASMFILES += kern/console.asm kern/pic.asm kern/irq.asm
ASMFILES     := $(ASMDIR)/kstart.asm $(MOD_ASMFILES)
MOD_CFILES   := cuser/helloworld.c cuser/zeropage.c
MOD_CFILES   += cuser/test_maps.c cuser/e1000.c cuser/apic.c cuser/timer_test.c
MOD_CFILES   += cuser/bochsvga.c cuser/fbtest.c cuser/acpi_debugger.c
MOD_CFILES   += cuser/ioapic.c
MOD_OFILES   := $(MOD_CFILES:%.c=$(OUTDIR)/%.o)
MOD_ELFS     := $(MOD_CFILES:%.c=$(OUTDIR)/%.elf)
MOD_ELFS     += $(OUTDIR)/cuser/acpica.elf $(OUTDIR)/cuser/lwip.elf
MODFILES     := $(MOD_ASMFILES:%.asm=$(GRUBDIR)/%.mod) $(MOD_CFILES:%.c=$(GRUBDIR)/%.mod) $(GRUBDIR)/cuser/acpica.mod $(GRUBDIR)/cuser/lwip.mod
DEPFILES     := $(ASMFILES:%.asm=$(OUTDIR)/%.d) $(MOD_OFILES:.o=.d)
ASMOUTS      := \
	$(GRUBDIR)/kstart.b \
	$(MODFILES) \
	$(ASMFILES:%.asm=$(OUTDIR)/%.b) \
	$(ASMFILES:.asm=.map) $(ASMFILES:.asm=.lst) \
	$(DEPFILES)
UTIL_BINS    := utils/cpuid utils/rflags

all: $(OUTDIR)/grub.iso
all: $(MOD_ELFS)
all: $(UTIL_BINS)

.SECONDARY: $(ASMFILES:%.asm=$(OUTDIR)/%.b) $(MOD_OFILES)

clean::
	rm -fr $(OUTDIR)
	rm -f cpuid rflags $(UTIL_BINS)

%: %.cpp
	$(HUSH_CXX) $(HOST_CXX) $(CXXFLAGS) -o $@ $<

%: %.c
	$(HUSH_CC) $(HOST_CC) $(CFLAGS) -o $@ $<

-include $(DEPFILES)

$(OUTDIR)/%.d: %.asm $(YASMDEP)
	@mkdir -p $(@D)
	$(HUSH_ASM_DEP) $(YASM) $(YASMFLAGS) -e -M $< -o $(@:.d=.b) > $(@)

$(OUTDIR)/%.b: %.asm $(OUTDIR)/%.d $(YASMDEP)
	@mkdir -p $(@D)
	$(HUSH_ASM) $(YASM) $(YASMFLAGS) -f bin $< -o $@ -L nasm -l $(OUTDIR)/$*.lst --mapfile=$(OUTDIR)/$*.map
	$(SIZE_ASM)

-include $(OUTDIR)/start32.d

$(OUTDIR)/start32.o: kasm/start32.asm $(YASMDEP)
	@mkdir -p $(@D)
	$(HUSH_ASM_DEP) $(YASM) $(YASMFLAGS) -e -M $< -o $@ > $(@:.o=.d)
	$(HUSH_ASM) $(YASM) $(YASMFLAGS) -f elf64 -g dwarf2 $< -o $@ -L nasm -l $(OUTDIR)/start32.lst
	$(SIZE_ASM)

$(OUTDIR)/kstart.b: $(INLINE_MODULES)

%.asm.pp: %.asm $(YASMDEP)
	$(YASM) -i . -f bin -o $@ -e -L nasm $<

$(GRUBDIR)/%.b: $(OUTDIR)/kasm/%.b
	@mkdir -p $(@D)
	@$(CP) $< $@
{'fraction_non_alphanumeric': 0.2348657909765848, 'fraction_numerical': 0.010279840091376356, 'mean_word_length': 3.902029391182645, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 9, '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': '27274', 'n_tokens_mistral': 3460, 'n_tokens_neox': 3145, 'n_words': 636}