From b5c6cd5168b4e697153a183b9babe6536b742738 Mon Sep 17 00:00:00 2001 From: Florian Eitel Date: Sun, 6 Dec 2009 21:49:38 +0800 Subject: [PATCH] Replaced Makefile with better one * added special output directory for executable and object files * improved configuration section * supported multi source files * fixed ugly warning in clean (... with ugly hack ^^) * added SILENT and PHONY to tasks * added dependency for run target * split default task in compile (and optional other tasks) * split compile in build of each object file and executable --- Makefile | 40 ++++++++++++++++++++++++++++++++++++++++ src/Makefile | 14 -------------- 2 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 Makefile delete mode 100644 src/Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..46dc5c2 --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +####### Compile Flags +CC= gcc +CFLAGS= -Wall -Os -std=c99 +CLIBS= +CINCL= +####### Commands +RM= rm -r +MKDIR= mkdir -p +####### Directories +SRCDIR= src +OUTDIR= bin +OBJDIR= $(OUTDIR)/objects +####### Project +OBJEND= o +SRCEND= c +NAME= game + +EXE = $(OUTDIR)/$(NAME) +SRCS = $(shell ls -1 $(SRCDIR)/*.$(SRCEND)) +BINS = $(SRCS:$(SRCDIR)%.$(SRCEND)=$(OBJDIR)%.$(OBJEND)) + +all: compile + +compile: $(BINS) $(EXE) + +$(EXE): $(BINS) + $(CC) $(CINCL) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS) + +$(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEND) + $(MKDIR) $(OBJDIR) + $(CC) $(CINCL) -c $< -o $@ $(CFLAGS) + +clean: + $(RM) $(OUTDIR) || true + +run: $(OUTDIR)/$(NAME) + ./$(OUTDIR)/$(NAME) + +.PHONY: clean +.SILENT: run diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index e8a5023..0000000 --- a/src/Makefile +++ /dev/null @@ -1,14 +0,0 @@ - -CC=gcc -CFLAGS=-Wall -Os -std=c99 - -all: main.c - $(CC) $(CFLAGS) -o game main.c - -run: - ./game - -clean: game.o - rm game.o - -