adventskalender-2009/Makefile

63 lines
1.4 KiB
Makefile
Raw Normal View History

####### Compile Flags
2009-12-06 21:11:29 +01:00
# Compiler
CC= gcc
2009-12-06 21:11:29 +01:00
# Compiler flags
CFLAGS= -Wall -std=c99 -ggdb
2009-12-06 21:11:29 +01:00
# Libraries
CLIBS= `sdl-config --cflags` -lSDL -lGL
####### 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
OBJEND= o
SRCEND= c
2009-12-06 21:11:29 +01:00
# name of programm (and executable)
NAME= game
2009-12-06 21:11:29 +01:00
# path to executable
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
SRCS = $(shell ls -1 $(SRCDIR)/*.$(SRCEND))
2009-12-06 21:11:29 +01:00
# substitude /$(SRCDIR)(.*)$(SRCEND)/$(OBJDIR)\1$(OBJEND)/
BINS = $(SRCS:$(SRCDIR)%.$(SRCEND)=$(OBJDIR)%.$(OBJEND))
2009-12-06 21:11:29 +01:00
# default task depends on compile
all: init compile
# create object-folder
init:
$(MKDIR) $(OBJDIR)
2009-12-06 21:11:29 +01:00
# compile depends on object files and executable
compile: $(BINS) $(EXE)
2009-12-06 21:11:29 +01:00
# executable depends on all object files
$(EXE): $(BINS)
$(CC) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS)
2009-12-06 21:11:29 +01:00
# each file in OBJDIR/*.o depends on corresponding source file in SRCDIR
# $@ = name of target (*.o)
# $< = first dependency (*.c)
2009-12-06 21:11:29 +01:00
$(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEND)
$(CC) -c $< -o $@ $(CLIBS) $(CFLAGS)
2009-12-06 21:11:29 +01:00
# delete OUTDIR
# don't raise an error if directory not exists
clean:
$(RM) $(OUTDIR) || true
2009-12-06 21:11:29 +01:00
# start programm
run: $(OUTDIR)/$(NAME)
./$(OUTDIR)/$(NAME)
2009-12-06 21:11:29 +01:00
# execute clean every time
.PHONY: clean
2009-12-06 21:11:29 +01:00
# don't show command in run target
.SILENT: run
2009-12-06 21:11:29 +01:00