aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-01-25 22:01:00 +0100
committerBad Diode <bd@badd10de.dev>2021-01-25 22:01:00 +0100
commite24186fc1917c5e8b91924af0c3c7c55816ff5d6 (patch)
tree6b20f24824736e822ba614811f312a7c7c2fd43b /Makefile
downloadmic-e24186fc1917c5e8b91924af0c3c7c55816ff5d6.tar.gz
mic-e24186fc1917c5e8b91924af0c3c7c55816ff5d6.zip
Introducing MIC
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile61
1 files changed, 61 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b31e5c8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,61 @@
1.POSIX:
2.SUFFIXES:
3
4# Source code location and files to watch for changes.
5SRC_DIR := src
6SRC_MAIN := $(SRC_DIR)/main.c
7SRC_APP := $(SRC_DIR)/app.c
8WATCH_SRC := $(wildcard $(SRC_DIR)/*.c)
9WATCH_SRC += $(wildcard $(SRC_DIR)/*.h)
10
11# Output library names and executables.
12BIN_NAME := app
13LIB_NAME := libmic.so
14BUILD_DIR := build
15BIN := $(BUILD_DIR)/$(BIN_NAME)
16LIB := $(BUILD_DIR)/$(LIB_NAME)
17LIB_DIR := $(BUILD_DIR)
18
19# Compiler and linker configuration.
20CC := gcc
21CFLAGS := -Wall -Wextra -pedantic -std=c99
22LDFLAGS :=
23LDLIBS :=
24RELEASE_CFLAGS := -DNDEBUG -O2
25DEBUG_CFLAGS := -DDEBUG -g
26
27.PHONY: dynamic static clean run
28
29# Setup debug/release builds.
30# make clean && make <target> DEBUG=0
31# make clean && make <target> DEBUG=1
32DEBUG ?= 0
33ifeq ($(DEBUG), 1)
34 CFLAGS += $(DEBUG_CFLAGS)
35else
36 CFLAGS += $(RELEASE_CFLAGS)
37endif
38
39dynamic: CFLAGS += -fPIC
40dynamic: CFLAGS += -DLIB_NAME=\"$(LIB_NAME)\"
41dynamic: CFLAGS += -DLIB_DIR=\"$(LIB_DIR)\"
42dynamic: LDFLAGS += -ldl
43dynamic: $(BUILD_DIR) $(LIB) $(BIN)
44
45static: SRC_MAIN += $(SRC_APP)
46static: $(BUILD_DIR) $(BIN)
47
48$(BIN): $(SRC_MAIN) $(WATCH_SRC)
49 $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(SRC_MAIN) $(LDLIBS)
50
51$(LIB): $(SRC_APP) $(WATCH_SRC)
52 $(CC) $(CFLAGS) -shared $(LDFLAGS) -o $@ $(SRC_APP) $(LDLIBS)
53
54$(BUILD_DIR):
55 mkdir -p $(BUILD_DIR)
56
57run: $(BIN)
58 exec $(BIN)
59
60clean:
61 rm -r $(BUILD_DIR)