Second commit. Boilerplate initialized.

This commit is contained in:
2025-10-17 09:08:26 -04:00
parent 45a95eb525
commit ce96b5a6e2
4 changed files with 68 additions and 0 deletions

33
Makefile Normal file
View File

@@ -0,0 +1,33 @@
include config.mk
all: $(TARGET)
release: clean
release: CFLAGS = -Wall -O2
release: $(TARGET)
# Run the target.
run: $(TARGET)
./$(TARGET)
# Compile project source objects.
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INC_DIR)/%.h
@ mkdir -p $(OBJ_DIR)
@ $(PRINT) "$(WHITE_BOLD)Compiling source object $(WHITE)$@$(WHITE_BOLD)... $(RESETCOLOR)"
$(CC) $(CFLAGS) -c $< -o $@
# Link to final binary.
$(TARGET): $(OBJ_FILES)
@ $(PRINT) "$(WHITE_BOLD)Linking $(WHITE)$@$(WHITE_BOLD)...$(RESETCOLOR)"
$(LINK) -o $(TARGET) $(OBJ_FILES) $(LDFLAGS)
# Clean out objects, binaries, and built artifacts.
clean:
@ $(PRINT) "$(WHITE_BOLD)Cleaning up...$(RESETCOLOR)"
rm -rf $(OBJ_DIR)/*.o $(TARGET)
# Get LOC.
lines:
@ wc -l $(SRC_FILES) $(INC_FILES) $(GRAM_SRC)
.PHONY: all clean release run lines

24
config.mk Normal file
View File

@@ -0,0 +1,24 @@
NAME = stug
TARGET = $(NAME).out
SRC_DIR = src
INC_DIR = $(SRC_DIR)/include
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
CC = clang -std=c23
LINK = clang
CFLAGS = -Wall -DDBG -ggdb -fsanitize=leak
LDFLAGS = -lm
PRINT = echo -e
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
INC_FILES = $(wildcard $(INC_DIR)/*.h)
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES))
OBJ_FILES_NOMAIN = $(filter-out $(OBJ_DIR)/main.o, $(OBJ_FILES)) # Object files without main.c.
RESETCOLOR = \033[0m
WHITE = $(RESETCOLOR)\033[37m
WHITE_BOLD = $(RESETCOLOR)\033[37;1m
RED_BOLD = $(RESETCOLOR)\033[31;1m

3
src/include/main.h Normal file
View File

@@ -0,0 +1,3 @@
#ifndef MAIN_H
#define MAIN_H
#endif

8
src/main.c Normal file
View File

@@ -0,0 +1,8 @@
#include "include/main.h"
#include <stdio.h>
int main(int argc, char** argv) {
printf("Hello, world.\n");
return 0;
}