Liftoff
This commit is contained in:
parent
e5a11eabb1
commit
21b5d52c5d
6 changed files with 144 additions and 11 deletions
2
.clang-format
Normal file
2
.clang-format
Normal file
|
@ -0,0 +1,2 @@
|
|||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build
|
86
makefile
Normal file
86
makefile
Normal file
|
@ -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
|
12
src/main.cpp
Normal file
12
src/main.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <iostream>
|
||||
|
||||
#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;
|
||||
}
|
|
@ -1,14 +1,29 @@
|
|||
class Point {
|
||||
int x, y;
|
||||
#include "point.hpp"
|
||||
|
||||
Point(int x, int y) {
|
||||
Point::Point(int x, int y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
void move(int dx, int 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;
|
||||
}
|
||||
|
|
17
src/point.hpp
Normal file
17
src/point.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <iostream>
|
||||
|
||||
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);
|
||||
};
|
Loading…
Reference in a new issue