Skip to content

Commit

Permalink
updated Makefile to organize build dir
Browse files Browse the repository at this point in the history
  • Loading branch information
KDesp73 committed Jun 19, 2024
1 parent bfa82fb commit 57de3e4
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,50 @@ LDFLAGS =
SRC_DIR = src
INCLUDE_DIR = include
BUILD_DIR = build
OBJECTS_DIR = $(BUILD_DIR)/objects

SRC_FILES := $(shell find $(SRC_DIR) -name '*.c')
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRC_FILES))
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJECTS_DIR)/%.o, $(SRC_FILES))

# chmod 755 libwebc.so
LIB_NAME = libwebc.so
LIB_NAME = $(BUILD_DIR)/output/libwebc.so

# chmod 644 libwebc.a
STATIC_LIB_NAME = libwebc.a
STATIC_LIB_NAME = $(BUILD_DIR)/output/libwebc.a

# read access for all users
DLL_NAME = webc.dll
DLL_NAME = $(BUILD_DIR)/output/webc.dll

all: library
all: $(BUILD_DIR) shared static dll

$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
mkdir -p $(BUILD_DIR)/core
mkdir -p $(BUILD_DIR)/ui
mkdir -p $(BUILD_DIR)/actions
mkdir -p $(BUILD_DIR)/server

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
mkdir -p $(BUILD_DIR)/output
mkdir -p $(OBJECTS_DIR)/core
mkdir -p $(OBJECTS_DIR)/ui
mkdir -p $(OBJECTS_DIR)/actions
mkdir -p $(OBJECTS_DIR)/server

$(OBJECTS_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<

library: $(BUILD_DIR) $(OBJ_FILES)
shared: $(BUILD_DIR) $(OBJ_FILES)
$(CC) -shared -o $(LIB_NAME) $(OBJ_FILES)
chmod 755 $(LIB_NAME)

static_library: $(BUILD_DIR) $(OBJ_FILES)
static: $(BUILD_DIR) $(OBJ_FILES)
ar rcs $(STATIC_LIB_NAME) $(OBJ_FILES)
chmod 644 $(STATIC_LIB_NAME)

dll: $(BUILD_DIR) $(OBJ_FILES)
$(CC) -shared -o $(DLL_NAME) $(OBJ_FILES) -Wl,--out-implib,libwebc.dll.a
$(CC) -shared -o $(DLL_NAME) $(OBJ_FILES) -Wl,--out-implib,$(BUILD_DIR)/output/libwebc.dll.a
chmod 644 $(DLL_NAME)
chmod 644 $(BUILD_DIR)/output/libwebc.dll.a

clean:
rm -rf $(BUILD_DIR) $(LIB_NAME) $(STATIC_LIB_NAME) $(DLL_NAME) libwebc.dll.a
rm -rf $(BUILD_DIR)

compile_commands.json: $(SRC_FILES)
bear -- make

.PHONY: all clean library static_library dll
.PHONY: all clean shared static dll

0 comments on commit 57de3e4

Please sign in to comment.