mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
update template to use makefile
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,4 +1,7 @@
|
|||||||
|
.cache
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
build
|
bin
|
||||||
|
obj
|
||||||
|
compile_commands.json
|
||||||
|
|||||||
32
.vscode/launch.json
vendored
32
.vscode/launch.json
vendored
@@ -2,30 +2,20 @@
|
|||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "(gdb) C Launch",
|
"name": "(lldb) C Launch",
|
||||||
"type": "cppdbg",
|
"type": "lldb",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/build/linux-86_64/${workspaceFolderBasename}",
|
"program": "",
|
||||||
|
"linux": {
|
||||||
|
"program": "${workspaceFolder}/bin/linux-x86_64/sdl_template",
|
||||||
|
"preLaunchTask": "build linux-x86_64"
|
||||||
|
},
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/bin/win-x86_64/sdl_template",
|
||||||
|
"preLaunchTask": "build win-x86_64"
|
||||||
|
},
|
||||||
"args": [],
|
"args": [],
|
||||||
"stopAtEntry": false,
|
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"environment": [],
|
|
||||||
"externalConsole": false,
|
|
||||||
"miDebuggerPath": "/usr/bin/gdb",
|
|
||||||
"MIMode": "gdb",
|
|
||||||
"setupCommands": [
|
|
||||||
{
|
|
||||||
"description": "Enable pretty-printing for gdb",
|
|
||||||
"text": "-enable-pretty-printing",
|
|
||||||
"ignoreFailures": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Set Disassembly Flavor to Intel",
|
|
||||||
"text": "-gdb-set disassembly-flavor intel",
|
|
||||||
"ignoreFailures": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"preLaunchTask": "build linux86_64"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
35
.vscode/tasks.json
vendored
35
.vscode/tasks.json
vendored
@@ -1,18 +1,16 @@
|
|||||||
{
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"label": "build linux86_64",
|
"label": "build linux-x86_64",
|
||||||
"command": "./build.sh",
|
"command": "make",
|
||||||
"args": [
|
"args": [
|
||||||
"linux86_64"
|
"linux-x86_64"
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}"
|
"cwd": "${workspaceFolder}"
|
||||||
},
|
},
|
||||||
"problemMatcher": [
|
|
||||||
"$gcc"
|
|
||||||
],
|
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": true
|
"isDefault": true
|
||||||
@@ -21,17 +19,14 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"label": "build win86_64",
|
"label": "build win-x86_64",
|
||||||
"command": "./build.sh",
|
"command": "make",
|
||||||
"args": [
|
"args": [
|
||||||
"win86_64"
|
"win-x86_64"
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}"
|
"cwd": "${workspaceFolder}"
|
||||||
},
|
},
|
||||||
"problemMatcher": [
|
|
||||||
"$gcc"
|
|
||||||
],
|
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": false
|
"isDefault": false
|
||||||
@@ -41,22 +36,26 @@
|
|||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"label": "build web",
|
"label": "build web",
|
||||||
"command": "./build.sh",
|
"command": "make",
|
||||||
"args": [
|
"args": [
|
||||||
"web"
|
"web"
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}"
|
"cwd": "${workspaceFolder}"
|
||||||
},
|
},
|
||||||
"problemMatcher": [
|
|
||||||
"$gcc"
|
|
||||||
],
|
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": false
|
"isDefault": false
|
||||||
},
|
},
|
||||||
"detail": "builds the program for web using emscripten"
|
"detail": "builds the program for web using emscripten"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "create compile_commands.json",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "bear -- make",
|
||||||
|
"runOptions": {
|
||||||
|
"runOn": "folderOpen"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"version": "2.0.0"
|
|
||||||
}
|
}
|
||||||
|
|||||||
71
build.sh
71
build.sh
@@ -1,71 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# define variables
|
|
||||||
PROJECT_NAME=${PWD##*/}
|
|
||||||
BUILD_DIR="./build"
|
|
||||||
INCLUDE_IN_BUILD="./assets"
|
|
||||||
|
|
||||||
# compilation targets
|
|
||||||
args_linux86_64()
|
|
||||||
{
|
|
||||||
ARCHITECTURE="linux-86_64"
|
|
||||||
COMPILER="/bin/gcc"
|
|
||||||
ARGS="-lSDL2"
|
|
||||||
FILE_EXSTENSION=""
|
|
||||||
}
|
|
||||||
|
|
||||||
args_win86-64()
|
|
||||||
{
|
|
||||||
ARCHITECTURE="win-86_64"
|
|
||||||
COMPILER="/usr/bin/x86_64-w64-mingw32-gcc"
|
|
||||||
ARGS="-lmingw32 -lSDL2main -lSDL2 -mwindows"
|
|
||||||
INCLUDE_IN_BUILD="$INCLUDE_IN_BUILD /usr/x86_64-w64-mingw32/bin/SDL2.dll"
|
|
||||||
FILE_EXSTENSION=".exe"
|
|
||||||
}
|
|
||||||
|
|
||||||
args_emscripten()
|
|
||||||
{
|
|
||||||
ARCHITECTURE="web"
|
|
||||||
COMPILER="emcc" # just make sure it's in $PATH (it's a pain to install)
|
|
||||||
ARGS="-s USE_SDL=2"
|
|
||||||
FILE_EXSTENSION=".html"
|
|
||||||
}
|
|
||||||
|
|
||||||
# handle arguments
|
|
||||||
if [ "$1" = "linux86_64" ]; then args_linux86_64
|
|
||||||
elif [ "$1" = "win86_64" ]; then args_win86-64
|
|
||||||
elif [ "$1" = "web" ]; then args_emscripten
|
|
||||||
else echo -e "\033[91mdidn't include any arguments! D:\033[0m" && exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check whether $BUILD_DIR or $ARCHITECTURE isn't set
|
|
||||||
if [[ -z $BUILD_DIR ]] || [[ -z "$ARCHITECTURE" ]]; then
|
|
||||||
echo -e "\033[91mBUILD_DIR or ARCHITECTURE not set D:\033[0m"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# make (and clear) the build directory
|
|
||||||
mkdir -p "$BUILD_DIR/$ARCHITECTURE"
|
|
||||||
rm -rf "${BUILD_DIR:?}/$ARCHITECTURE/*"
|
|
||||||
|
|
||||||
# copy included files or directories to the build directory
|
|
||||||
if [[ -n $INCLUDE_IN_BUILD ]]; then
|
|
||||||
cp -r "$INCLUDE_IN_BUILD" "$BUILD_DIR/$ARCHITECTURE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# get the executable path
|
|
||||||
EXE_PATH=$BUILD_DIR/$ARCHITECTURE/$PROJECT_NAME$FILE_EXSTENSION
|
|
||||||
echo "building at: $EXE_PATH"
|
|
||||||
|
|
||||||
# check whether the compiler can actually be executed
|
|
||||||
if [ ! -x "$COMPILER" ] && ! command -v "$COMPILER" > /dev/null; then
|
|
||||||
echo -e "\033[91mCouldn't find an executable at path: \033[0m $COMPILER"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# compile the code
|
|
||||||
COMMAND="$COMPILER $(find ./src -name "*.c") -o $EXE_PATH -Wall -g -lm $ARGS"
|
|
||||||
echo "using command: $COMMAND"
|
|
||||||
$COMMAND
|
|
||||||
exit $?
|
|
||||||
1
build/linux-86_64/assets/uwu
Normal file
1
build/linux-86_64/assets/uwu
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uwu
|
||||||
BIN
build/linux-86_64/tetris_clone
Executable file
BIN
build/linux-86_64/tetris_clone
Executable file
Binary file not shown.
41
makefile
Normal file
41
makefile
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
NAME = sdl_template
|
||||||
|
|
||||||
|
# compiler settings
|
||||||
|
CC := clang
|
||||||
|
CFLAGS = $(shell pkg-config --cflags sdl2) -Wall -g
|
||||||
|
LDFLAGS = $(shell pkg-config --libs sdl2) -lm
|
||||||
|
|
||||||
|
# file locations
|
||||||
|
DIR_BIN := bin
|
||||||
|
DIR_OBJ := obj
|
||||||
|
SRC = $(wildcard src/*.c) $(wildcard src/**/*.c) $(wildcard src/**/**/*.c) $(wildcard src/**/**/**/*.c) $(wildcard src/**/**/**/**/*.c)
|
||||||
|
OBJ = $(patsubst src/%,$(DIR_OBJ)/$(ARCH)/%,$(SRC:.c=.o))
|
||||||
|
TARGET = $(DIR_BIN)/$(ARCH)/$(NAME)$(EXT)
|
||||||
|
|
||||||
|
# sets the variables for the different targets
|
||||||
|
linux-x86_64:
|
||||||
|
$(MAKE) build ARCH=linux-x86_64 CFLAGS="$(CFLAGS) -target x86_64-pc-linux-gnu"
|
||||||
|
win-x86_64:
|
||||||
|
$(MAKE) build ARCH=win-x86-64 CFLAGS="$(CFLAGS) -target x86_64-pc-windows-gnu" EXT=".exe"
|
||||||
|
web:
|
||||||
|
$(MAKE) build ARCH=web CC=emcc EXT=".html"
|
||||||
|
|
||||||
|
all: linux-x86_64 win-x86_64 web
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(DIR_BIN) $(DIR_OBJ)
|
||||||
|
|
||||||
|
build: dirs binary
|
||||||
|
|
||||||
|
# creates the binary
|
||||||
|
binary: $(OBJ)
|
||||||
|
$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
# creates the object files, include a flag for no unused command line arguments, because in this context it's unneeded
|
||||||
|
$(DIR_OBJ)/$(ARCH)/%.o: src/%.c
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS) $(LDFLAGS) -Wno-unused-command-line-argument
|
||||||
|
|
||||||
|
dirs:
|
||||||
|
mkdir -p $(DIR_BIN)/$(ARCH)
|
||||||
|
mkdir -p $(DIR_OBJ)/$(ARCH)
|
||||||
Reference in New Issue
Block a user