diff options
author | Bad Diode <bd@badd10de.dev> | 2021-01-25 22:01:00 +0100 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-01-25 22:01:00 +0100 |
commit | e24186fc1917c5e8b91924af0c3c7c55816ff5d6 (patch) | |
tree | 6b20f24824736e822ba614811f312a7c7c2fd43b /Makefile | |
download | mic-e24186fc1917c5e8b91924af0c3c7c55816ff5d6.tar.gz mic-e24186fc1917c5e8b91924af0c3c7c55816ff5d6.zip |
Introducing MIC
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 61 |
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. | ||
5 | SRC_DIR := src | ||
6 | SRC_MAIN := $(SRC_DIR)/main.c | ||
7 | SRC_APP := $(SRC_DIR)/app.c | ||
8 | WATCH_SRC := $(wildcard $(SRC_DIR)/*.c) | ||
9 | WATCH_SRC += $(wildcard $(SRC_DIR)/*.h) | ||
10 | |||
11 | # Output library names and executables. | ||
12 | BIN_NAME := app | ||
13 | LIB_NAME := libmic.so | ||
14 | BUILD_DIR := build | ||
15 | BIN := $(BUILD_DIR)/$(BIN_NAME) | ||
16 | LIB := $(BUILD_DIR)/$(LIB_NAME) | ||
17 | LIB_DIR := $(BUILD_DIR) | ||
18 | |||
19 | # Compiler and linker configuration. | ||
20 | CC := gcc | ||
21 | CFLAGS := -Wall -Wextra -pedantic -std=c99 | ||
22 | LDFLAGS := | ||
23 | LDLIBS := | ||
24 | RELEASE_CFLAGS := -DNDEBUG -O2 | ||
25 | DEBUG_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 | ||
32 | DEBUG ?= 0 | ||
33 | ifeq ($(DEBUG), 1) | ||
34 | CFLAGS += $(DEBUG_CFLAGS) | ||
35 | else | ||
36 | CFLAGS += $(RELEASE_CFLAGS) | ||
37 | endif | ||
38 | |||
39 | dynamic: CFLAGS += -fPIC | ||
40 | dynamic: CFLAGS += -DLIB_NAME=\"$(LIB_NAME)\" | ||
41 | dynamic: CFLAGS += -DLIB_DIR=\"$(LIB_DIR)\" | ||
42 | dynamic: LDFLAGS += -ldl | ||
43 | dynamic: $(BUILD_DIR) $(LIB) $(BIN) | ||
44 | |||
45 | static: SRC_MAIN += $(SRC_APP) | ||
46 | static: $(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 | |||
57 | run: $(BIN) | ||
58 | exec $(BIN) | ||
59 | |||
60 | clean: | ||
61 | rm -r $(BUILD_DIR) | ||