diff --git a/Makefile b/Makefile index fd6a7b0..97553bf 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ # Basic configuration -TARGET := langc AFLAGS = -felf64 -F dwarf -g ifdef DEBUG @@ -10,7 +9,9 @@ endif SRCDIR := src OBJDIR := obj LIBDIR := lib +BINDIR := bin +TARGET := $(BINDIR)/langc # Core directories COREDIR := $(SRCDIR)/core MATHDIR := $(COREDIR)/math @@ -132,6 +133,7 @@ ALL_OBJ := $(patsubst $(SRCDIR)/%.s,$(OBJDIR)/%.o,$(ALL_SRC)) # Library settings LIBNAME := $(LIBDIR)/core/core.a +LIBCORE_DIR := $(LIBDIR)/core LIBFTDIR := $(LIBDIR)/libft LIBFT := $(LIBFTDIR)/lib/libft.a LIB_OBJ := $(filter-out $(OBJDIR)/start.o, $(ALL_OBJ)) @@ -158,14 +160,20 @@ all: prepare-build build-core build-parser build-lexer build-global build-main l # Stage 1: Prepare build environment prepare-build: create-directories -create-directories: | $(OBJDIRS) $(LIBDIR) +create-directories: | $(OBJDIRS) $(LIBDIR) $(LIBCORE_DIR) $(BINDIR) $(OBJDIRS): mkdir -p $@ +$(BINDIR): + mkdir -p $@ + $(LIBDIR): mkdir -p $@ +$(LIBCORE_DIR): + mkdir -p $@ + # Stage 2: Build core modules build-core: build-math build-string build-memory build-vector build-print build-file build-syscall build-string-builder @@ -214,7 +222,7 @@ $(TARGET): $(ALL_OBJ) $(LIBFT) $(LIBNAME) # Stage 8: Create library create-library: $(LIBNAME) -$(LIBNAME): $(LIB_OBJ) | $(LIBDIR) +$(LIBNAME): $(LIB_OBJ) $(LIBDIR) ar rcs $@ $(LIB_OBJ) $(LIBFT): diff --git a/compile b/compile index 91ef6f5..f9601d0 100755 --- a/compile +++ b/compile @@ -1,17 +1,20 @@ #!/bin/sh set -e +set -x LD_ARGS="-nostdlib -static" NASM_FLAG="-felf64 -g" LIBS="./lib/core/core.a ./lib/libft/lib/libft.a" -PROGNAME="langproc" + +COMPILER_PATH=./bin/langc filename=$1 comp_out=${filename%.lang}.s -nasm_out=${comp_output%.s}.o +nasm_out=${comp_out%.s}.o +PROGNAME=${filename%.lang} -./langc ${filename} +${COMPILER_PATH} ${filename} nasm ${NASM_FLAG} ${comp_out} -o ${nasm_out} ld ${nasm_out} ${LD_ARGS} ${LIBS} -o ${PROGNAME} diff --git a/test.lang b/examples/test.lang similarity index 100% rename from test.lang rename to examples/test.lang diff --git a/lib/libft/Makefile b/lib/libft/Makefile index bf0c98b..adfef6a 100644 --- a/lib/libft/Makefile +++ b/lib/libft/Makefile @@ -6,7 +6,7 @@ # By: vvobis +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/09/17 14:23:19 by vvobis #+# #+# # -# Updated: 2025/05/14 15:16:25 by vvobis ### ########.fr # +# Updated: 2025/05/29 15:50:55 by victor ### ########.fr # # # # **************************************************************************** # @@ -14,7 +14,7 @@ NAME := libft.a CC := cc -CFLAGS := -Wall -Wextra -Werror -mabi=sysv +CFLAGS := -Wall -Wextra -Werror -fstack-protector ifdef DEBUG CFLAGS += -g3 diff --git a/src/start.s b/src/start.s index a95068b..20e25a0 100644 --- a/src/start.s +++ b/src/start.s @@ -1,4 +1,5 @@ %include "./src/core/string_builder/sb.s" +%include "./src/inc/c_alignment.s" section .data usage: db "Usage: ./debug .lang", 0xa, 0 @@ -67,10 +68,13 @@ _start: mov rdi, rax mov rdi, [rdi] mov rsi, dot_s - call ft_strjoin + c_call ft_strjoin mov rdi, rax mov rsi, 0x241 mov rdx, 0o644 + push rdi + call putstr + pop rdi call open mov [fd_out], rax