mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 04:37:47 +08:00
![Alexander Patel](/assets/img/avatar_default.png)
This commit updates the Makefile to complile each .c source file into an object before linking. The benefit of this is that only the necessary files will be recompiled when modifying the code. We also move the Makefile and build.bat up to the root directory of the repo. This is so that calling make directly builds the binaries. Both files are updated to adapt to the new directory structure. With this change, initial build times are increased from ~3s to ~10s on my machine. However, subsequent build times are improved. As a result of this change, SConstruct is somewhat deprecated. We can update this as well if necessary in a future change. I verified that the build completes successfully and tests pass for both ubuntu and windows 10. A future change could compile src/ files into a static library to be linked with cli/, if necessary. Issue: #64
60 lines
1.3 KiB
Makefile
60 lines
1.3 KiB
Makefile
|
|
# ## Copyright (c) 2020-2021 Thakee Nathees
|
|
# ## Distributed Under The MIT License
|
|
|
|
CC = gcc
|
|
CFLAGS = -fPIC -Wno-int-to-pointer-cast
|
|
DEBUG_CFLAGS = -D DEBUG -g3 -Og
|
|
RELEASE_CFLAGS = -g -O3
|
|
LDFLAGS = -lm
|
|
|
|
TARGET_EXEC = pocket
|
|
BUILD_DIR = ./build
|
|
|
|
SRC_DIRS = ./src ./cli
|
|
INC_DIRS = ./src/include
|
|
|
|
SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name *.c)
|
|
OBJS := $(SRCS:.c=.o)
|
|
DEPS := $(OBJS:.o=.d)
|
|
|
|
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
|
DEP_FLAGS = -MMD -MP
|
|
CC_FLAGS = $(INC_FLAGS) $(DEP_FLAGS) $(CFLAGS)
|
|
|
|
DEBUG_DIR = $(BUILD_DIR)/debug
|
|
DEBUG_TARGET = $(DEBUG_DIR)/$(TARGET_EXEC)
|
|
DEBUG_OBJS := $(addprefix $(DEBUG_DIR)/, $(OBJS))
|
|
|
|
RELEASE_DIR = $(BUILD_DIR)/release
|
|
RELEASE_TARGET = $(RELEASE_DIR)/$(TARGET_EXEC)
|
|
RELEASE_OBJS := $(addprefix $(RELEASE_DIR)/, $(OBJS))
|
|
|
|
.PHONY: debug release all clean
|
|
|
|
# default; target if run as `make`
|
|
debug: $(DEBUG_TARGET)
|
|
|
|
$(DEBUG_TARGET): $(DEBUG_OBJS)
|
|
$(CC) $^ -o $@ $(LDFLAGS)
|
|
|
|
$(DEBUG_DIR)/%.o: %.c
|
|
@mkdir -p $(dir $@)
|
|
$(CC) $(CC_FLAGS) $(DEBUG_CFLAGS) -c $< -o $@
|
|
|
|
release: $(RELEASE_TARGET)
|
|
|
|
$(RELEASE_TARGET): $(RELEASE_OBJS)
|
|
$(CC) $^ -o $@ $(LDFLAGS)
|
|
|
|
$(RELEASE_DIR)/%.o: %.c
|
|
@mkdir -p $(dir $@)
|
|
$(CC) $(CC_FLAGS) $(RELEASE_CFLAGS) -c $< -o $@
|
|
|
|
all: debug release
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|
|
|
|
-include $(DEPS)
|