Add Makefile and initial implementation of MyModule with main function

This commit is contained in:
whaffman 2025-09-10 17:41:04 +02:00
parent fa58455218
commit ac39854276
5 changed files with 110 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
*.o
*.a
webserv
build
.cache

87
Makefile Normal file
View File

@ -0,0 +1,87 @@
# Compiler and flags
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++20 -MMD -MP
# Build type (default to debug)
BUILD_TYPE ?= debug
# Build-specific flags
ifeq ($(BUILD_TYPE), release)
CXXFLAGS += -O3 -DNDEBUG
BUILD_SUFFIX = release
else ifeq ($(BUILD_TYPE), asan)
CXXFLAGS += -g -O1 -fsanitize=address -fno-omit-frame-pointer
BUILD_SUFFIX = asan
else
CXXFLAGS += -g -O0 -DDEBUG
BUILD_SUFFIX = debug
endif
# Directories
SRCDIR = webserv
BUILDDIR = build/$(BUILD_SUFFIX)
OBJDIR = $(BUILDDIR)/obj
# Target executable
NAME = $(BUILDDIR)/webserv
# Source files
SOURCES = $(wildcard $(SRCDIR)/*.cpp) \
$(wildcard $(SRCDIR)/*/*.cpp)
# Object files
OBJECTS = $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
# Dependency files
DEPENDS = $(OBJECTS:.o=.d)
# Include directories
INCLUDES = -I.
# Default target
all: $(NAME)
# Create executable
$(NAME): $(OBJECTS)
@mkdir -p $(BUILDDIR)
$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME)
# Compile source files to object files
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp Makefile
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# Clean object files
clean:
rm -rf $(OBJDIR)
# Clean everything (object files, executable, and build directory)
fclean: clean
rm -rf $(BUILDDIR)
# Clean all build types
fclean-all:
rm -rf build
# Rebuild everything
re: fclean all
# Run the executable (rebuild first)
run: re
./$(NAME)
# Build type targets
debug:
$(MAKE) BUILD_TYPE=debug
release:
$(MAKE) BUILD_TYPE=release
asan:
$(MAKE) BUILD_TYPE=asan
# Phony targets
.PHONY: all clean fclean fclean-all re run debug release asan
# Include dependency files
-include $(DEPENDS)

8
webserv/main.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <webserv/mymodule/MyModule.hpp>
int main()
{
MyModule module;
module.doSomething();
return 0;
}

View File

@ -0,0 +1,8 @@
#include <webserv/mymodule/MyModule.hpp>
#include <iostream>
void MyModule::doSomething()
{
std::cout << "Doing something!" << std::endl;
}

View File

@ -0,0 +1,6 @@
#pragma once
class MyModule {
public:
void doSomething();
};