107 lines
2.8 KiB
Makefile
107 lines
2.8 KiB
Makefile
#!/usr/bin/make -f
|
|
|
|
# Target architecture for compilation
|
|
ARCH = native
|
|
|
|
# Optimization level
|
|
O = 3
|
|
|
|
# Flags for the compiler
|
|
FLAGS = -std=c23
|
|
FLAGS += -O$(O)
|
|
FLAGS += -march=$(ARCH)
|
|
# Only override gcc default tuning if specified in make command line
|
|
ifneq (, $(TUNE))
|
|
FLAGS += -mtune=$(TUNE)
|
|
endif
|
|
FLAGS += -pedantic
|
|
FLAGS += -Wall
|
|
FLAGS += -Wextra
|
|
FLAGS += -Werror
|
|
# This flag is because of the compiler otherwise giving too much warning
|
|
#FLAGS += -Wformat-truncation=0
|
|
|
|
# Compile flag for defining GITHASH to put at the end of the version string
|
|
GITFLAG = -D'GITHASH=$(shell git rev-parse --short=1 HEAD)'
|
|
|
|
# Directories where .o files and excecutables will be placed
|
|
OBJDIR = obj
|
|
OUTDIR = out
|
|
|
|
# The UI to compile for by default using make run
|
|
#UI_TARGET = vt100
|
|
UI_TARGET = ncurses
|
|
|
|
# The URL of the plaintext version of the lisence, for the --license option
|
|
LICENSEURL = https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
|
|
|
# C compiler
|
|
CC = cc
|
|
|
|
.NOTINTERMEDIATE:
|
|
|
|
# Messages to print during different steps in making
|
|
MSG_FETCHING = FETCHING:
|
|
MSG_LINKING = Linking:
|
|
MSG_COMPILING = Compiling C:
|
|
MSG_CLEANING = Cleaning:
|
|
MSG_CLEANING_OBJ = Cleaning $(OBJDIR):
|
|
MSG_CLEANING_OUT = Cleaning $(OUTDIR):
|
|
|
|
# Compile for all UI targets
|
|
all: $(addprefix $(OUTDIR)/connect4_,ncurses.elf vt100.elf)
|
|
|
|
# Compile and run the default UI target
|
|
run: $(OUTDIR)/connect4_$(UI_TARGET).elf
|
|
./$<
|
|
|
|
# Compile and run with a specific UI target
|
|
run_%: $(OUTDIR)/connect4_%.elf
|
|
./$<
|
|
|
|
# Compile specifically the ncurses version
|
|
# This one's special because it needs -lncursesw
|
|
$(OUTDIR)/connect4_ncurses.elf: $(addprefix $(OBJDIR)/,ui_ncurses.o logic.o connect4.o LICENSE.o)
|
|
@echo $(MSG_LINKING) $@
|
|
@mkdir -p $(@D)
|
|
$(CC) $(FLAGS) -lncursesw -o $@ $^
|
|
|
|
# Compile the final excecutable for a given UI target
|
|
$(OUTDIR)/connect4_%.elf: $(addprefix $(OBJDIR)/,ui_%.o logic.o connect4.o LICENSE.o)
|
|
@echo $(MSG_LINKING) $@
|
|
@mkdir -p $(@D)
|
|
$(CC) $(FLAGS) -o $@ $^
|
|
|
|
# Make an object file for the license so it does not all need to be in the code
|
|
$(OBJDIR)/LICENSE.o: $(OBJDIR)/LICENSE
|
|
@echo $(MSG_LINKING) $@
|
|
@mkdir -p $(@D)
|
|
cd $(@D); ld -r -b binary -o $(@F) $(^F)
|
|
|
|
# Compile the object file of the main code.
|
|
# This one's special because it includes the git hash
|
|
$(OBJDIR)/connect4.o: connect4.c
|
|
@echo $(MSG_COMPILING) $^
|
|
@mkdir -p $(@D)
|
|
$(CC) -c $(FLAGS) $(GITFLAG) -o $@ $^
|
|
|
|
# Generic object file compile
|
|
$(OBJDIR)/%.o: %.c
|
|
@echo $(MSG_COMPILING) $^
|
|
@mkdir -p $(@D)
|
|
$(CC) -c $(FLAGS) -o $@ $^
|
|
|
|
# Download the license file in non-markdown form.
|
|
# This is not cleaned as that would be too silly
|
|
$(OBJDIR)/LICENSE:
|
|
@echo $(MSG_FETCHING) $@
|
|
curl $(LICENSEURL) \
|
|
| sed -n '/END OF TERMS AND CONDITIONS/q;p' > $(OBJDIR)/LICENSE
|
|
|
|
# Remove all compilation output and intermediate files
|
|
clean:
|
|
@echo $(MSG_CLEANING)
|
|
@echo $(MSG_CLEANING_OBJ)
|
|
rm -f $(OBJDIR)/*.o
|
|
@echo $(MSG_CLEANING_OUT)
|
|
rm -f $(OUTDIR)/*.elf
|