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
This commit is contained in:
parent
60d12068f3
commit
b5c6cd5168
2 changed files with 40 additions and 14 deletions
40
Makefile
Normal file
40
Makefile
Normal file
|
@ -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
|
14
src/Makefile
14
src/Makefile
|
@ -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
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue