-
Notifications
You must be signed in to change notification settings - Fork 59
/
Makefile
90 lines (77 loc) · 2 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#-------------------------------------------------------------------------------
#
# File: Makefile
#
# Author: Stephen Brennan
#
# Date Created: Tuesday, 10 June 2015
#
# Description: Makefile for CKY parser program.
#
# Copyright (c) 2015, Stephen Brennan. Released under the Revised BSD License.
# See the LICENSE.txt file for details.
#
#-------------------------------------------------------------------------------
# Compiler Variable Declarations
CC=gcc
FLAGS=-Wall -pedantic
INC=-Isrc/
CFLAGS=$(FLAGS) -c -g --std=c99 $(INC)
LFLAGS=$(FLAGS) -lncurses
DIR_GUARD=@mkdir -p $(@D)
# Build configurations.
CFG=release
ifeq ($(CFG),debug)
FLAGS += -g -DDEBUG -DSMB_DEBUG
endif
ifneq ($(CFG),debug)
ifneq ($(CFG),release)
@echo "Invalid configuration "$(CFG)" specified."
@echo "You must specify a configuration when running make, e.g."
@echo " make CFG=debug"
@echo "Choices are 'release', 'debug'."
@exit 1
endif
endif
SDL=yes
ifeq ($(SDL),yes)
CFLAGS += `sdl-config --cflags` -DWITH_SDL=1
LFLAGS += `sdl-config --libs` -lSDL_mixer
endif
ifneq ($(SDL),yes)
ifneq ($(SDL),no)
@echo "Invalid SDL configuration "$(SDL)" specified."
@echo "You must specify the SDL configuration when running make, e.g."
@echo " make SDL=yes"
@echo "Choices are 'yes', 'no'."
@exit 1
endif
endif
# Sources and Objects
SOURCES=$(shell find src/ -type f -name "*.c")
OBJECTS=$(patsubst src/%.c,obj/$(CFG)/%.o,$(SOURCES))
DEPS=$(patsubst src/%.c,deps/%.d,$(SOURCES))
# Main targets
.PHONY: all clean clean_all
all: bin/$(CFG)/main
GTAGS: $(SOURCES)
gtags
clean:
rm -rf obj/$(CFG)/* bin/$(CFG)/* src/*.gch GTAGS GPATH GRTAGS
clean_all:
rm -rf bin/* obj/* deps/*
# --- Compile Rule
obj/$(CFG)/%.o: src/%.c
$(DIR_GUARD)
$(CC) $(CFLAGS) $< -o $@
# --- Link Rule
bin/$(CFG)/main: $(OBJECTS)
$(DIR_GUARD)
$(CC) $(OBJECTS) $(LFLAGS) -o bin/$(CFG)/main
# --- Dependency Rule
deps/%.d: src/%.c
$(DIR_GUARD)
$(CC) $(CFLAGS) -MM $< | sed -e 's/~\(.*\)\.o:/\1.d \1.o:/' > $@
ifneq "$(MAKECMDGOALS)" "clean_all"
-include $(DEPS)
endif