Added comments to Makefile

This commit is contained in:
Florian Eitel 2009-12-07 04:11:29 +08:00 committed by Aaron Mueller
parent fb499130ed
commit 104a4b1d49

View file

@ -1,7 +1,11 @@
####### Compile Flags ####### Compile Flags
# Compiler
CC= gcc CC= gcc
# Compiler flags
CFLAGS= -Wall -Os -std=c99 CFLAGS= -Wall -Os -std=c99
# Libraries
CLIBS= CLIBS=
# Includes
CINCL= CINCL=
####### Commands ####### Commands
RM= rm -r RM= rm -r
@ -11,30 +15,47 @@ SRCDIR= src
OUTDIR= bin OUTDIR= bin
OBJDIR= $(OUTDIR)/objects OBJDIR= $(OUTDIR)/objects
####### Project ####### Project
# file extension for object and source files
OBJEND= o OBJEND= o
SRCEND= c SRCEND= c
# name of programm (and executable)
NAME= game NAME= game
# path to executable
EXE = $(OUTDIR)/$(NAME) EXE = $(OUTDIR)/$(NAME)
# execute shell command "ls -1 src/*.c" for a listing of all source files
SRCS = $(shell ls -1 $(SRCDIR)/*.$(SRCEND)) SRCS = $(shell ls -1 $(SRCDIR)/*.$(SRCEND))
# substitude /$(SRCDIR)(.*)$(SRCEND)/$(OBJDIR)\1$(OBJEND)/
BINS = $(SRCS:$(SRCDIR)%.$(SRCEND)=$(OBJDIR)%.$(OBJEND)) BINS = $(SRCS:$(SRCDIR)%.$(SRCEND)=$(OBJDIR)%.$(OBJEND))
# default task depends on compile
all: compile all: compile
# compile depends on object files and executable
compile: $(BINS) $(EXE) compile: $(BINS) $(EXE)
# executable depends on all object files
$(EXE): $(BINS) $(EXE): $(BINS)
$(CC) $(CINCL) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS) $(CC) $(CINCL) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS)
$(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEND) # each file in OBJDIR/*.o depends on corresponding source file in SRCDIR
$(MKDIR) $(OBJDIR) $(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEND)
$(MKDIR) $(OBJDIR) # create object-folder
# $@ = name of target (*.o)
# $< = first dependency (*.c)
$(CC) $(CINCL) -c $< -o $@ $(CFLAGS) $(CC) $(CINCL) -c $< -o $@ $(CFLAGS)
# delete OUTDIR
clean: clean:
# don't raise an error if directory not exists
$(RM) $(OUTDIR) || true $(RM) $(OUTDIR) || true
# start programm
run: $(OUTDIR)/$(NAME) run: $(OUTDIR)/$(NAME)
./$(OUTDIR)/$(NAME) ./$(OUTDIR)/$(NAME)
# execute clean every time
.PHONY: clean .PHONY: clean
# don't show command in run target
.SILENT: run .SILENT: run