c-cxx-template/Makefile

41 lines
736 B
Makefile
Raw Normal View History

2024-04-02 14:54:40 +00:00
BIN=YOUR_PROJECT_NAME
CC_FLAGS = -Isrc/include -std=c23
CXX_FLAGS = -Isrc/include -Ilib/ -std=c++23 -fmodules-ts
LD_FLAGS = -lm
CC=gcc
CXX=g++
LD=gcc
AR=ar
LIBS=
include lib/make.mk
cxx_sources=$(wildcard src/*.cpp)
c_sources=$(wildcard src/*.c)
2024-05-20 09:21:55 +00:00
objects=$(patsubst src/%.cpp,build/obj/%.cpp.o,$(cxx_sources)) $(patsubst src/%.c,build/obj/%.c.o,$(c_sources)) $(LIBS)
2024-04-02 14:54:40 +00:00
2024-05-20 09:21:55 +00:00
all: build/$(BIN) compile_commands.json
@rm -r build/obj
2024-04-02 14:54:40 +00:00
2024-05-20 09:21:55 +00:00
keep: build/$(BIN)
2024-04-02 14:54:40 +00:00
clean:
2024-05-20 09:21:55 +00:00
rm -r build/obj/
2024-04-02 14:54:40 +00:00
2024-05-20 09:21:55 +00:00
build/$(BIN): $(objects)
2024-04-02 14:54:40 +00:00
$(LD) -o $@ $^ $(LD_FLAGS)
2024-05-20 09:21:55 +00:00
build/obj/%.cpp.o: */%.cpp
2024-04-02 14:54:40 +00:00
@mkdir -p $(dir $@)
$(CXX) -c -o $@ $< $(CXX_FLAGS)
2024-05-20 09:21:55 +00:00
build/obj/%.c.o: */%.c
2024-04-02 14:54:40 +00:00
@mkdir -p $(dir $@)
$(CC) -c -o $@ $< $(CC_FLAGS)
2024-05-20 09:15:47 +00:00
compile_commands.json:
compiledb -n make