diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..80d3293 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: LLVM +IndentWidth: 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build diff --git a/makefile b/makefile new file mode 100644 index 0000000..3116133 --- /dev/null +++ b/makefile @@ -0,0 +1,86 @@ +#dd Compiler and assembler +CC = gcc +CXX = g++ +AS = as +LD = ld +OBJDUMP = objdump +SIZE = size + +CFLAGS += -std=c++23 +CFLAGS += -Wall +CFLAGS += -Wextra +CFLAGS += -Werror +CFLAGS += -Wno-unused-parameter +CFLAGS += -Wno-unused-variable +CFLAGS += -Wno-unused-function +CFLAGS += -Wno-unused-but-set-variable +CFLAGS += -Wno-unused-value +CFLAGS += -Wno-unused-label +CFLAGS += -Wno-unused-result +CFLAGS += -Wno-unused-local-typedefs +CFLAGS += -Wno-unused-const-variable +CFLAGS += -Wno-unused-macros +CFLAGS += -O3 +CFLAGS += -g + +GITHASH = $(shell git rev-parse --short HEAD) + +# Specify the target binary (call it whatever) +TARGET = build/program +TARGET_TAR = $(TARGET)-$(GITHASH).tar.zst +TARGET_SIG = $(TARGET_TAR).minisig + +SRCS := $(wildcard src/*.cpp) +HDRS := $(wildcard src/*.hpp) + +# Specify the object files in the build directory +OBJS := $(patsubst src/%.cpp,build/%.o,$(SRCS)) + +all: $(TARGET) + +# For convenience +run: $(TARGET) + @./$(TARGET) + +# Create the build directory +mkbuilddir: + @mkdir -p build + +# Link the object files into the target binary +$(TARGET): $(OBJS) + @$(CXX) $(CFLAGS) -o $@ $^ + @echo -e "LD \t$^" + +# Compile the source files into object files +build/%.o: src/%.cpp | mkbuilddir + @$(CXX) $(CFLAGS) -c -o $@ $< || (rm -f $@ && exit 1) + @echo -e "CC \t$<" + +# Print the size of the target binary +size: $(TARGET) + $(SIZE) $(TARGET) + +# Format with clang-format +format: $(SRCS) $(HDRS) + clang-format -i $^ + +# Clean up the build directory +clean: + rm -r build + rm -f build/*.o + rm -f $(TARGET)* + +# Create a signed release +tar: $(TARGET_TAR) + +# Sign the tar +sign: $(TARGET_SIG) + +$(TARGET_SIG): $(TARGET_TAR) + minisign -Sm $< + +$(TARGET_TAR): $(TARGET) + strip $< + tar --zstd -cvf $@ $< + +.PHONY: all clean size mkbuilddir run tar sign diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..5b0b1d3 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,12 @@ +#include + +#include "point.hpp" + +int main(int argc, char *argv[]) { + Point p = Point(10, 5); + std::cout << p << std::endl; + p.move(5, 5); + std::cout << p << std::endl; + std::cout << "Hello, World!" << std::endl; + return 0; +} diff --git a/src/point.cpp b/src/point.cpp index f1da4f9..a31c805 100644 --- a/src/point.cpp +++ b/src/point.cpp @@ -1,14 +1,29 @@ -class Point { - int x, y; +#include "point.hpp" - Point(int x, int y) { - this->x = x; - this->y = y; - } +Point::Point(int x, int y) { + this->x = x; + this->y = y; +} - void move(int dx, int dy) { - this->x += dx; - this->y += dy; - } -}; +void Point::move(int dx, int dy) { + this->x += dx; + this->y += dy; +} +int Point::getX() { return this->x; } + +int Point::getY() { return this->y; } + +void Point::setX(int x) { this->x = x; } + +void Point::setY(int y) { this->y = y; } + +void Point::set(int x, int y) { + this->x = x; + this->y = y; +} + +std::ostream &operator<<(std::ostream &os, const Point &obj) { + os << "Point: (" << obj.x << ", " << obj.y << ")"; + return os; +} diff --git a/src/point.hpp b/src/point.hpp new file mode 100644 index 0000000..f43c85b --- /dev/null +++ b/src/point.hpp @@ -0,0 +1,17 @@ +#include + +class Point { + private: + int x, y; + + public: + Point(int x, int y); + int getX(); + int getY(); + void set(int x, int y); + void setX(int x); + void setY(int y); + void move(int dx, int dy); + + friend std::ostream &operator<<(std::ostream &os, const Point &obj); +};