-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
35 lines (28 loc) · 854 Bytes
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
EXECUTABLE_NAME := Tetris
BIN_DIR := bin
SRC_DIR := src
COMPILER_FLAGS := -c
ASSEMBLER_FLAGS := -f elf64
LINKER_FLAGS := -no-pie -lX11
# find c and asm files
SOURCE_FILES := $(shell find -name "*.asm" -or -name "*.c")
# replace .c and .asm extensions with .o
RAW_OBJECTS := $(patsubst %.c, %.o, $(patsubst %.asm, %.o, $(SOURCE_FILES)))
# move object files to bin directory
OBJECTS := $(patsubst ./$(SRC_DIR)/%, ./$(BIN_DIR)/%, $(RAW_OBJECTS))
# link obj files to executable (gcc)
Tetris: $(OBJECTS)
@gcc $^ -o $(EXECUTABLE_NAME) $(LINKER_FLAGS)
# c to obj (gcc)
bin/%.o: src/%.c $(BIN_DIR)
@gcc $< -o $@ $(COMPILER_FLAGS)
# asm to obj (nasm)
bin/%.o: src/%.asm $(BIN_DIR)
@nasm $< -o $@ $(ASSEMBLER_FLAGS)
# create bin directory if it's missing
$(BIN_DIR):
@mkdir $@
# compile and run
.PHONY: run
run: $(EXECUTABLE_NAME)
@./$(EXECUTABLE_NAME)