aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bin2carr/Makefile
blob: a9ff81621b3731397939ceb5a2ab769dc0794a04 (plain)
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
.POSIX:
.SUFFIXES:

# Source code location and files to watch for changes.
SRC_DIR        := src
SRC_MAIN       := $(SRC_DIR)/main.c
WATCH_SRC      := $(wildcard $(SRC_DIR)/*.c)
WATCH_SRC      += $(wildcard $(SRC_DIR)/*.h)

# Output library names and executables.
BIN_NAME       := bin2carr
BUILD_DIR      := build
BIN            := $(BUILD_DIR)/$(BIN_NAME)

# Compiler and linker configuration.
CC             := gcc
CFLAGS         := -Wall -Wextra -pedantic -std=c99 -DBIN_NAME=\"$(BIN_NAME)\"
LDFLAGS        := -lm
LDLIBS         :=
RELEASE_CFLAGS := -DNDEBUG -O2
DEBUG_CFLAGS   := -DDEBUG -g

.PHONY: static clean run

# Setup debug/release builds.
#     make clean && make <target> DEBUG=0
#     make clean && make <target> DEBUG=1
DEBUG ?= 0
ifeq ($(DEBUG), 1)
    CFLAGS += $(DEBUG_CFLAGS)
else
    CFLAGS += $(RELEASE_CFLAGS)
endif

static: $(BUILD_DIR) $(BIN)

$(BIN): $(SRC_MAIN) $(WATCH_SRC)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(SRC_MAIN) $(LDLIBS)

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

run: $(BIN)
	exec $(BIN)

clean:
	rm -r $(BUILD_DIR)