2009-12-06 14:49:38 +01:00
|
|
|
####### Compile Flags
|
2009-12-06 21:11:29 +01:00
|
|
|
# Compiler
|
2009-12-06 14:49:38 +01:00
|
|
|
CC= gcc
|
2009-12-06 21:11:29 +01:00
|
|
|
# Compiler flags
|
2009-12-10 23:23:02 +01:00
|
|
|
CFLAGS= -Wall -std=c99 -ggdb
|
2009-12-06 21:11:29 +01:00
|
|
|
# Libraries
|
2009-12-07 16:57:30 +01:00
|
|
|
CLIBS= `sdl-config --cflags` -lSDL -lGL
|
2009-12-06 14:49:38 +01:00
|
|
|
####### Commands
|
|
|
|
RM= rm -r
|
|
|
|
MKDIR= mkdir -p
|
|
|
|
####### Directories
|
|
|
|
SRCDIR= src
|
|
|
|
OUTDIR= bin
|
|
|
|
OBJDIR= $(OUTDIR)/objects
|
|
|
|
####### Project
|
2009-12-06 21:11:29 +01:00
|
|
|
# file extension for object and source files
|
2009-12-06 14:49:38 +01:00
|
|
|
OBJEND= o
|
|
|
|
SRCEND= c
|
2009-12-06 21:11:29 +01:00
|
|
|
# name of programm (and executable)
|
2009-12-06 14:49:38 +01:00
|
|
|
NAME= game
|
|
|
|
|
2009-12-06 21:11:29 +01:00
|
|
|
# path to executable
|
2009-12-06 14:49:38 +01:00
|
|
|
EXE = $(OUTDIR)/$(NAME)
|
2009-12-06 21:11:29 +01:00
|
|
|
# execute shell command "ls -1 src/*.c" for a listing of all source files
|
2009-12-06 14:49:38 +01:00
|
|
|
SRCS = $(shell ls -1 $(SRCDIR)/*.$(SRCEND))
|
2009-12-06 21:11:29 +01:00
|
|
|
# substitude /$(SRCDIR)(.*)$(SRCEND)/$(OBJDIR)\1$(OBJEND)/
|
2009-12-06 14:49:38 +01:00
|
|
|
BINS = $(SRCS:$(SRCDIR)%.$(SRCEND)=$(OBJDIR)%.$(OBJEND))
|
|
|
|
|
2009-12-06 21:11:29 +01:00
|
|
|
# default task depends on compile
|
2009-12-07 16:57:30 +01:00
|
|
|
all: init compile
|
|
|
|
|
|
|
|
# create object-folder
|
|
|
|
init:
|
|
|
|
$(MKDIR) $(OBJDIR)
|
2009-12-06 14:49:38 +01:00
|
|
|
|
2009-12-06 21:11:29 +01:00
|
|
|
# compile depends on object files and executable
|
2009-12-06 14:49:38 +01:00
|
|
|
compile: $(BINS) $(EXE)
|
|
|
|
|
2009-12-06 21:11:29 +01:00
|
|
|
# executable depends on all object files
|
2009-12-06 14:49:38 +01:00
|
|
|
$(EXE): $(BINS)
|
2009-12-07 16:57:30 +01:00
|
|
|
$(CC) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS)
|
2009-12-06 14:49:38 +01:00
|
|
|
|
2009-12-06 21:11:29 +01:00
|
|
|
# each file in OBJDIR/*.o depends on corresponding source file in SRCDIR
|
2009-12-07 16:57:30 +01:00
|
|
|
# $@ = name of target (*.o)
|
|
|
|
# $< = first dependency (*.c)
|
2009-12-06 21:11:29 +01:00
|
|
|
$(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEND)
|
2009-12-07 16:57:30 +01:00
|
|
|
$(CC) -c $< -o $@ $(CLIBS) $(CFLAGS)
|
2009-12-06 14:49:38 +01:00
|
|
|
|
2009-12-06 21:11:29 +01:00
|
|
|
# delete OUTDIR
|
2009-12-07 16:57:30 +01:00
|
|
|
# don't raise an error if directory not exists
|
2009-12-06 14:49:38 +01:00
|
|
|
clean:
|
|
|
|
$(RM) $(OUTDIR) || true
|
|
|
|
|
2009-12-06 21:11:29 +01:00
|
|
|
# start programm
|
2009-12-06 14:49:38 +01:00
|
|
|
run: $(OUTDIR)/$(NAME)
|
|
|
|
./$(OUTDIR)/$(NAME)
|
|
|
|
|
2009-12-06 21:11:29 +01:00
|
|
|
# execute clean every time
|
2009-12-06 14:49:38 +01:00
|
|
|
.PHONY: clean
|
2009-12-06 21:11:29 +01:00
|
|
|
# don't show command in run target
|
2009-12-06 14:49:38 +01:00
|
|
|
.SILENT: run
|
2009-12-06 21:11:29 +01:00
|
|
|
|