Change readme, and add changable build dir

This commit is contained in:
2025-06-02 16:39:17 +03:00
parent 804c8c5254
commit 4e3de1cfb2
2 changed files with 25 additions and 9 deletions

View File

@@ -1,5 +1,7 @@
LIB=libcx
BUILD_DIR?=build
COM_FLAGS = -fPIC -Isrc/include
CC_FLAGS = -std=c23 -ggdb
CXX_FLAGS = -std=c++23 -nostdinc++ -ggdb -fexceptions
@@ -11,28 +13,28 @@ AR=ar
cxx_sources=$(wildcard src/*.cpp)
c_sources=$(wildcard src/*.c)
objects=$(patsubst src/%.cpp,build/obj/%.cpp.o,$(cxx_sources)) $(patsubst src/%.c,build/obj/%.c.o,$(c_sources))
objects=$(patsubst src/%.cpp,$(BUILD_DIR)/obj/%.cpp.o,$(cxx_sources)) $(patsubst src/%.c,$(BUILD_DIR)/obj/%.c.o,$(c_sources))
all: shared static compile_commands.json
shared: build/$(LIB).so
static: build/$(LIB).a
shared: $(BUILD_DIR)/$(LIB).so
static: $(BUILD_DIR)/$(LIB).a
build/$(LIB).a: $(objects)
$(BUILD_DIR)/$(LIB).a: $(objects)
$(AR) rcs $@ $^
build/$(LIB).so: $(objects)
$(BUILD_DIR)/$(LIB).so: $(objects)
$(LD) -shared -o $@ $^
clean:
rm -r build/obj/
rm -r $(BUILD_DIR)/obj/
build/obj/%.cpp.o: */%.cpp
$(BUILD_DIR)/obj/%.cpp.o: */%.cpp
@mkdir -p $(dir $@)
$(CXX) -c -o $@ $< $(CXX_FLAGS) $(COM_FLAGS)
build/obj/%.c.o: */%.c
$(BUILD_DIR)/obj/%.c.o: */%.c
@mkdir -p $(dir $@)
$(CC) -c -o $@ $< $(CC_FLAGS) $(COM_FLAGS)