Converted to new build system
This commit is contained in:
parent
b0be7f0c0b
commit
8ff968d209
|
|
@ -1,77 +0,0 @@
|
||||||
# Makefile for SLS project with automatic header dependencies
|
|
||||||
|
|
||||||
CC ?= gcc
|
|
||||||
CFLAGS ?= -std=c99 -Wall -Wextra -Werror -g -Iinclude -MMD -MP
|
|
||||||
LDFLAGS ?=
|
|
||||||
CTESTFLAGS ?= -std=c99 -Wall -Wextra -Wno-unused-function -Werror -g -O0 -Iinclude -MMD -MP
|
|
||||||
|
|
||||||
SRCDIR := src
|
|
||||||
OBJDIR := obj
|
|
||||||
BINDIR := bin
|
|
||||||
TESTDIR := tests
|
|
||||||
|
|
||||||
TARGET := $(BINDIR)/sls
|
|
||||||
TEST_TARGET := $(BINDIR)/sls_tests
|
|
||||||
|
|
||||||
SOURCES := $(wildcard $(SRCDIR)/*.c)
|
|
||||||
OBJECTS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
|
|
||||||
NON_MAIN_OBJECTS := $(filter-out $(OBJDIR)/main.o,$(OBJECTS))
|
|
||||||
|
|
||||||
TEST_SOURCES := $(wildcard $(TESTDIR)/*.c)
|
|
||||||
TEST_OBJECTS := $(patsubst $(TESTDIR)/%.c,$(OBJDIR)/%.o,$(TEST_SOURCES))
|
|
||||||
|
|
||||||
# Include dependency files if they exist
|
|
||||||
-include $(OBJECTS:.o=.d) $(TEST_OBJECTS:.o=.d)
|
|
||||||
|
|
||||||
.PHONY: all build run test clean
|
|
||||||
|
|
||||||
# Default: build main program
|
|
||||||
all: $(TARGET)
|
|
||||||
|
|
||||||
# Compile object files
|
|
||||||
build: $(OBJECTS)
|
|
||||||
|
|
||||||
# Rule to compile .c -> .o (handles both src and tests)
|
|
||||||
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
|
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
$(OBJDIR)/%.o: $(TESTDIR)/%.c | $(OBJDIR)
|
|
||||||
$(CC) $(CTESTFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
# Link main program
|
|
||||||
$(TARGET): $(OBJECTS) | $(BINDIR)
|
|
||||||
$(CC) $(LDFLAGS) $^ -o $@ -lm
|
|
||||||
|
|
||||||
# Run main program
|
|
||||||
run: $(TARGET)
|
|
||||||
@echo "Running $(TARGET)..."
|
|
||||||
./$(TARGET)
|
|
||||||
|
|
||||||
test_cases: ../SLS_Tests/yaml_to_c_tests.py ../SLS_Tests/cases.yaml
|
|
||||||
python3 ../SLS_Tests/yaml_to_c_tests.py ../SLS_Tests/cases.yaml ./tests/lexer_tests.c
|
|
||||||
|
|
||||||
# Build test runner executable
|
|
||||||
$(TEST_TARGET): $(TEST_OBJECTS) $(NON_MAIN_OBJECTS) | $(BINDIR)
|
|
||||||
$(CC) $(LDFLAGS) $^ -o $@ -lm
|
|
||||||
|
|
||||||
build_tests: test_cases $(TEST_TARGET)
|
|
||||||
|
|
||||||
# Run tests
|
|
||||||
debug: build_tests
|
|
||||||
gdb ./$(TEST_TARGET)
|
|
||||||
|
|
||||||
# Run tests
|
|
||||||
test: test_cases $(TEST_TARGET)
|
|
||||||
@echo "Running tests..."
|
|
||||||
./$(TEST_TARGET)
|
|
||||||
|
|
||||||
# Create directories if missing
|
|
||||||
$(BINDIR):
|
|
||||||
mkdir -p $(BINDIR)
|
|
||||||
|
|
||||||
$(OBJDIR):
|
|
||||||
mkdir -p $(OBJDIR)
|
|
||||||
|
|
||||||
# Remove build artifacts
|
|
||||||
clean:
|
|
||||||
rm -rf $(OBJDIR) $(BINDIR)
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
# MSVC nmake build file for SLS
|
|
||||||
|
|
||||||
CC = cl
|
|
||||||
CFLAGS = /std:c11 /Zi /I include
|
|
||||||
LDFLAGS =
|
|
||||||
|
|
||||||
SRCDIR = src
|
|
||||||
OBJDIR = obj
|
|
||||||
BINDIR = bin
|
|
||||||
TESTDIR = tests
|
|
||||||
|
|
||||||
TARGET = $(BINDIR)\sls.exe
|
|
||||||
TEST_TARGET = $(BINDIR)\sls_tests.exe
|
|
||||||
|
|
||||||
# === LIST FILES MANUALLY (edit as needed) ===
|
|
||||||
SOURCES = \
|
|
||||||
$(SRCDIR)\main.c \
|
|
||||||
$(SRCDIR)\lexer.c \
|
|
||||||
$(SRCDIR)\string.c
|
|
||||||
|
|
||||||
OBJECTS = \
|
|
||||||
$(OBJDIR)\main.obj \
|
|
||||||
$(OBJDIR)\lexer.obj \
|
|
||||||
$(OBJDIR)\string.obj
|
|
||||||
|
|
||||||
TEST_SOURCES = \
|
|
||||||
$(TESTDIR)\extra_tests.c \
|
|
||||||
$(TESTDIR)\lexer_test_helpers.c \
|
|
||||||
$(TESTDIR)\lexer_tests.c \
|
|
||||||
$(TESTDIR)\string_tests.c \
|
|
||||||
$(TESTDIR)\tests.c
|
|
||||||
|
|
||||||
TEST_OBJECTS = \
|
|
||||||
$(OBJDIR)\extra_tests.obj \
|
|
||||||
$(OBJDIR)\lexer_test_helpers.obj \
|
|
||||||
$(OBJDIR)\lexer_tests.obj \
|
|
||||||
$(OBJDIR)\string_tests.obj \
|
|
||||||
$(OBJDIR)\tests.obj
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
# Default target
|
|
||||||
all: build
|
|
||||||
|
|
||||||
# === BUILD MAIN PROGRAM ===
|
|
||||||
build: $(TARGET)
|
|
||||||
|
|
||||||
$(TARGET): dirs $(OBJECTS)
|
|
||||||
link $(OBJECTS) /OUT:$@ $(LDFLAGS)
|
|
||||||
|
|
||||||
# === COMPILE RULES ===
|
|
||||||
$(OBJDIR)\main.obj: $(SRCDIR)\main.c
|
|
||||||
$(CC) $(CFLAGS) /c $(SRCDIR)\main.c /Fo$(OBJDIR)\main.obj
|
|
||||||
|
|
||||||
$(OBJDIR)\lexer.obj: $(SRCDIR)\lexer.c
|
|
||||||
$(CC) $(CFLAGS) /c $(SRCDIR)\lexer.c /Fo$(OBJDIR)\lexer.obj
|
|
||||||
|
|
||||||
$(OBJDIR)\string.obj: $(SRCDIR)\string.c
|
|
||||||
$(CC) $(CFLAGS) /c $(SRCDIR)\string.c /Fo$(OBJDIR)\string.obj
|
|
||||||
|
|
||||||
$(OBJDIR)\extra_tests.obj: $(TESTDIR)\extra_tests.c
|
|
||||||
$(CC) $(CFLAGS) /c $(TESTDIR)\extra_tests.c /Fo$(OBJDIR)\extra_tests.obj
|
|
||||||
|
|
||||||
$(OBJDIR)\lexer_test_helpers.obj: $(TESTDIR)\lexer_test_helpers.c
|
|
||||||
$(CC) $(CFLAGS) /c $(TESTDIR)\lexer_test_helpers.c /Fo$(OBJDIR)\lexer_test_helpers.obj
|
|
||||||
|
|
||||||
$(OBJDIR)\lexer_tests.obj: $(TESTDIR)\lexer_tests.c
|
|
||||||
$(CC) $(CFLAGS) /c $(TESTDIR)\lexer_tests.c /Fo$(OBJDIR)\lexer_tests.obj
|
|
||||||
|
|
||||||
$(OBJDIR)\string_tests.obj: $(TESTDIR)\string_tests.c
|
|
||||||
$(CC) $(CFLAGS) /c $(TESTDIR)\string_tests.c /Fo$(OBJDIR)\string_tests.obj
|
|
||||||
|
|
||||||
$(OBJDIR)\tests.obj: $(TESTDIR)\tests.c
|
|
||||||
$(CC) $(CFLAGS) /c $(TESTDIR)\tests.c /Fo$(OBJDIR)\tests.obj
|
|
||||||
|
|
||||||
# === RUN EXECUTABLE ===
|
|
||||||
run: $(TARGET)
|
|
||||||
$(TARGET)
|
|
||||||
|
|
||||||
# === TEST BUILD & RUN ===
|
|
||||||
test: $(TEST_TARGET)
|
|
||||||
$(TEST_TARGET)
|
|
||||||
|
|
||||||
$(TEST_TARGET): dirs $(TEST_OBJECTS) $(OBJDIR)\lexer.obj $(OBJDIR)\string.obj
|
|
||||||
link $(TEST_OBJECTS) $(OBJDIR)\lexer.obj $(OBJDIR)\string.obj /OUT:$@ $(LDFLAGS)
|
|
||||||
|
|
||||||
# === CREATE DIRECTORIES ===
|
|
||||||
dirs:
|
|
||||||
if not exist $(OBJDIR) mkdir $(OBJDIR)
|
|
||||||
if not exist $(BINDIR) mkdir $(BINDIR)
|
|
||||||
|
|
||||||
# === CLEAN ===
|
|
||||||
clean:
|
|
||||||
rmdir /s /q $(OBJDIR)
|
|
||||||
rmdir /s /q $(BINDIR)
|
|
||||||
|
|
@ -4,20 +4,20 @@ This is the C implementation for the YREA SLS interpreter.
|
||||||
|
|
||||||
## Compiling, Running, and Testing
|
## Compiling, Running, and Testing
|
||||||
|
|
||||||
|
Interpreter binary location:
|
||||||
|
- Linux: `./bin/sls`
|
||||||
|
- Windows: `.\bin\sls.exe`
|
||||||
|
|
||||||
### Linux (GCC)
|
### Linux (GCC)
|
||||||
|
|
||||||
Build Project: `make build`
|
Build Project: `python3 build.py all`
|
||||||
Build and Run Project: `make run`
|
Build and Run Project: `python3 build.py run`
|
||||||
Build and Run Tests: `make test`
|
Build and Run Tests: `python3 build.py test`
|
||||||
|
|
||||||
Interpreter binary location: `./bin/sls`
|
|
||||||
|
|
||||||
### Windows (MSVC)
|
### Windows (MSVC)
|
||||||
|
|
||||||
Use a developer shell for all nmake commands.
|
*__For Windows users:__ Use a VS developer shell for all build commands.*
|
||||||
|
|
||||||
Build Project: `nmake /f Makefile.nmake build`
|
Build Project: `python build.py all`
|
||||||
Build and Run Project: `nmake /f Makefile.nmake run`
|
Build and Run Project: `python build.py run`
|
||||||
Build and Run Tests: `nmake /f Makefile.nmake test`
|
Build and Run Tests: `python build.py test`
|
||||||
|
|
||||||
Interpreter binary location: `.\bin\sls.exe`
|
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,35 @@ def detect_compiler():
|
||||||
|
|
||||||
CC, CC_KIND = detect_compiler()
|
CC, CC_KIND = detect_compiler()
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
# PYTHON DETECTION
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
def detect_python():
|
||||||
|
if os.name == "nt":
|
||||||
|
return "python"
|
||||||
|
return "python3"
|
||||||
|
|
||||||
|
PYTHON = detect_python()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
# GIT COMMIT HASH
|
# GIT COMMIT HASH
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
def git_commit_hash():
|
def git_commit_hash():
|
||||||
try:
|
try:
|
||||||
result = subprocess.check_output(
|
result_hash = subprocess.check_output(
|
||||||
["git", "describe", "--always", "--dirty", "--abbrev=7"],
|
["git", "describe", "--always", "--dirty", "--abbrev=7"],
|
||||||
cwd=".",
|
cwd=".",
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
text=True
|
text=True
|
||||||
)
|
).strip()
|
||||||
return result.strip()
|
result_date = subprocess.check_output(
|
||||||
|
["git", "show", "-s", "--format=%ci"],
|
||||||
|
cwd=".",
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
text=True
|
||||||
|
).strip()
|
||||||
|
return f"{result_hash} {result_date}"
|
||||||
except Exception:
|
except Exception:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
|
@ -126,7 +142,7 @@ def generate_tests():
|
||||||
if out.exists() and out.stat().st_mtime > yaml.stat().st_mtime:
|
if out.exists() and out.stat().st_mtime > yaml.stat().st_mtime:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
run(["python3", str(script), str(yaml), str(out)])
|
run([PYTHON, str(script), str(yaml), str(out)])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue