-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
50 lines (37 loc) · 1.07 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
# makefile for making C library genelife_lib.so
#
# written by John S. McCaskill Nov 2019#
#
# use make -f Makefile_xterm to make standalone C xterm application with primitive graphics without python
#
TARGET_LIB ?= libgenelife
BUILD_DIR ?= ./buildlib
SRC_DIRS ?= ./genelifec ./genelifeclib
OS_LDFLAG :=
OS_NAME := $(shell uname -s)
ifeq ($(OS_NAME),Linux)
LDLIBS := $(TARGET_LIB).so
endif
ifeq ($(OS_NAME),Darwin)
LDLIBS := $(TARGET_LIB).dylib
OS_LDFLAG = -dynamiclib
endif
SRCS := $(shell find $(SRC_DIRS) -name *.c)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CFLAGS ?= $(INC_FLAGS) -fPIC -g -Wall -std=gnu99 -MMD -MP # C flags, add -Wextra to see mixed integer type warnings etc
LDFLAGS := $(OS_LDFLAG) -lm -shared # linking flags
$(LDLIBS): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
$(RM) $(LDLIBS)
-include $(DEPS)
MKDIR_P ?= mkdir -p