'simplify' make file to work across gmake and bmake
This commit is contained in:
@@ -1,64 +1,81 @@
|
|||||||
# Directories
|
SRC_DIR = src
|
||||||
SRC_DIR := src
|
INC_DIR = include
|
||||||
INC_DIR := include
|
OBJ_DIR = obj
|
||||||
OBJ_DIR := obj
|
BIN_DIR = bin
|
||||||
BIN_DIR := bin
|
|
||||||
|
|
||||||
# Source files
|
CC = cc
|
||||||
SRCS := $(wildcard $(SRC_DIR)/*.c)
|
CFLAGS_DEBUG = -g -O0 -Wall -Wpedantic -I$(INC_DIR) -std=c89 -fPIC
|
||||||
OBJS_DEBUG := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/debug/%.o,$(SRCS))
|
CFLAGS_RELEASE = -O2 -Wall -Wpedantic -I$(INC_DIR) -std=c89 -fPIC
|
||||||
OBJS_RELEASE := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/release/%.o,$(SRCS))
|
LDFLAGS = -ldl
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
# Compiler and flags
|
# Compiler and flags
|
||||||
CC := cc
|
CC := cc
|
||||||
CFLAGS_DEBUG := -g -O0 -Wall -Wpedantic -I$(INC_DIR) -std=c89
|
CFLAGS_DEBUG := -g -O0 -Wall -Wpedantic -I$(INC_DIR) -std=c89
|
||||||
CFLAGS_RELEASE := -O2 -Wall -Wpedantic -I$(INC_DIR) -std=c89
|
CFLAGS_RELEASE := -O2 -Wall -Wpedantic -I$(INC_DIR) -std=c89
|
||||||
|
=======
|
||||||
|
LIB_NAME = libstk.so
|
||||||
|
>>>>>>> 9712d47 ('simplify' make file to work across gmake and bmake)
|
||||||
|
|
||||||
# Platform detection
|
OBJS_DEBUG = \
|
||||||
ifeq ($(OS),Windows_NT)
|
$(OBJ_DIR)/debug/module.o \
|
||||||
LIB_NAME := stk.dll
|
$(OBJ_DIR)/debug/platform.o \
|
||||||
LDFLAGS :=
|
$(OBJ_DIR)/debug/stk.o \
|
||||||
CFLAGS_DEBUG += -D_WIN32
|
$(OBJ_DIR)/debug/stk_log.o
|
||||||
CFLAGS_RELEASE += -D_WIN32
|
|
||||||
else
|
|
||||||
LIB_NAME := libstk.so
|
|
||||||
LDFLAGS := -ldl
|
|
||||||
CFLAGS_DEBUG += -fPIC
|
|
||||||
CFLAGS_RELEASE += -fPIC
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Default build
|
OBJS_RELEASE = \
|
||||||
all: debug
|
$(OBJ_DIR)/release/module.o \
|
||||||
|
$(OBJ_DIR)/release/platform.o \
|
||||||
# Debug / Release builds
|
$(OBJ_DIR)/release/stk.o \
|
||||||
debug: $(BIN_DIR)/debug/$(LIB_NAME)
|
$(OBJ_DIR)/release/stk_log.o
|
||||||
release: $(BIN_DIR)/release/$(LIB_NAME)
|
|
||||||
|
|
||||||
# Build shared library
|
|
||||||
$(BIN_DIR)/debug/$(LIB_NAME): $(OBJS_DEBUG)
|
|
||||||
@mkdir -p $(BIN_DIR)/debug
|
|
||||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
$(BIN_DIR)/release/$(LIB_NAME): $(OBJS_RELEASE)
|
|
||||||
@mkdir -p $(BIN_DIR)/release
|
|
||||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
# Compile object files with header dependency tracking
|
|
||||||
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.c
|
|
||||||
@mkdir -p $(OBJ_DIR)/debug
|
|
||||||
$(CC) $(CFLAGS_DEBUG) -MMD -MP -c $< -o $@
|
|
||||||
|
|
||||||
$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.c
|
|
||||||
@mkdir -p $(OBJ_DIR)/release
|
|
||||||
$(CC) $(CFLAGS_RELEASE) -MMD -MP -c $< -o $@
|
|
||||||
|
|
||||||
# Include generated dependency files
|
|
||||||
-include $(OBJS_DEBUG:.o=.d)
|
|
||||||
-include $(OBJS_RELEASE:.o=.d)
|
|
||||||
|
|
||||||
# Clean
|
|
||||||
clean:
|
|
||||||
rm -rf $(OBJ_DIR) $(BIN_DIR)
|
|
||||||
|
|
||||||
.PHONY: all debug release clean
|
.PHONY: all debug release clean
|
||||||
|
|
||||||
|
all: debug
|
||||||
|
|
||||||
|
debug: $(BIN_DIR)/debug/$(LIB_NAME)
|
||||||
|
|
||||||
|
release: $(BIN_DIR)/release/$(LIB_NAME)
|
||||||
|
|
||||||
|
$(BIN_DIR)/debug/$(LIB_NAME): $(OBJS_DEBUG)
|
||||||
|
@mkdir -p $(BIN_DIR)/debug
|
||||||
|
$(CC) -shared -o $@ $(OBJS_DEBUG) $(LDFLAGS)
|
||||||
|
|
||||||
|
$(BIN_DIR)/release/$(LIB_NAME): $(OBJS_RELEASE)
|
||||||
|
@mkdir -p $(BIN_DIR)/release
|
||||||
|
$(CC) -shared -o $@ $(OBJS_RELEASE) $(LDFLAGS)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/debug/module.o: $(SRC_DIR)/module.c
|
||||||
|
@mkdir -p $(OBJ_DIR)/debug
|
||||||
|
$(CC) $(CFLAGS_DEBUG) -c $(SRC_DIR)/module.c -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/debug/platform.o: $(SRC_DIR)/platform.c
|
||||||
|
@mkdir -p $(OBJ_DIR)/debug
|
||||||
|
$(CC) $(CFLAGS_DEBUG) -c $(SRC_DIR)/platform.c -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/debug/stk.o: $(SRC_DIR)/stk.c
|
||||||
|
@mkdir -p $(OBJ_DIR)/debug
|
||||||
|
$(CC) $(CFLAGS_DEBUG) -c $(SRC_DIR)/stk.c -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/debug/stk_log.o: $(SRC_DIR)/stk_log.c
|
||||||
|
@mkdir -p $(OBJ_DIR)/debug
|
||||||
|
$(CC) $(CFLAGS_DEBUG) -c $(SRC_DIR)/stk_log.c -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/release/module.o: $(SRC_DIR)/module.c
|
||||||
|
@mkdir -p $(OBJ_DIR)/release
|
||||||
|
$(CC) $(CFLAGS_RELEASE) -c $(SRC_DIR)/module.c -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/release/platform.o: $(SRC_DIR)/platform.c
|
||||||
|
@mkdir -p $(OBJ_DIR)/release
|
||||||
|
$(CC) $(CFLAGS_RELEASE) -c $(SRC_DIR)/platform.c -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/release/stk.o: $(SRC_DIR)/stk.c
|
||||||
|
@mkdir -p $(OBJ_DIR)/release
|
||||||
|
$(CC) $(CFLAGS_RELEASE) -c $(SRC_DIR)/stk.c -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/release/stk_log.o: $(SRC_DIR)/stk_log.c
|
||||||
|
@mkdir -p $(OBJ_DIR)/release
|
||||||
|
$(CC) $(CFLAGS_RELEASE) -c $(SRC_DIR)/stk_log.c -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rf $(OBJ_DIR) $(BIN_DIR)
|
||||||
|
|||||||
Reference in New Issue
Block a user