shellmatta/makefile

109 lines
3.0 KiB
Makefile

#
# Copyright (c) 2019 Stefan Strobel <stefan.strobel@shimatta.net>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
OBJ_DIR := output/
CC := gcc
CPP := g++
LN := ln
SOURCES := src/shellmatta.c \
src/shellmatta_autocomplete.c \
src/shellmatta_history.c \
src/shellmatta_utils.c \
src/shellmatta_escape.c
INCLUDES := api .
TEST_SOURCES := test/test_main.cpp \
test/shellmatta_utils/itoa.cpp \
test/shellmatta_utils/clearInput.cpp \
test/shellmatta_utils/insertChars.cpp
TEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(TEST_SOURCES))
CFLAGS := $(INCLUDES:%=-I%) -g
TESTFLAGS := $(INCLUDES:%=-I%) -g -fprofile-arcs -ftest-coverage
TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
EXAMPLE_SOURCES := example/main.c
EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(EXAMPLE_SOURCES))
EXAMPLE_TARGET := $(OBJ_DIR)example/example
TEST_TARGET := $(OBJ_DIR)test/test
OBJ := $(COBJ) $(EXAMPLE_COBJ) $(TEST_CPPOBJ)
DEPS := $(OBJ:%.o=%.d)
export
help:
@echo Shellmatta help
@echo -------------------------
@echo test - run all tests
@echo example - build example
@echo -------------------------
test: $(TEST_TARGET)
- @mkdir -p output/test/report
@echo running test:
-output/test/test
#gcov -o output/test $(TEST_CPPOBJ) -r
gcovr --html-details --output output/test/report/report.html output/test -f src -f api
#-rm *.gcov
example: $(EXAMPLE_TARGET)
@echo building example
doc:
- @mkdir -p output/doc/html
- @mkdir -p output/doc/latex
doxygen settings/doxygen/doxyfile
clean:
- rm -rf $(OBJ_DIR)
$(EXAMPLE_TARGET): $(COBJ) $(EXAMPLE_COBJ)
- @mkdir -p $(@D)
$(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
$(TEST_TARGET): $(TEST_CPPOBJ)
- @mkdir -p $(@D)
$(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
$(TARGET): $(OBJ)
- @mkdir -p $(@D)
$(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
$(COBJ):
- @mkdir -p $(@D)
@$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
$(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
$(EXAMPLE_COBJ):
- @mkdir -p $(@D)
@$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
$(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
$(TEST_CPPOBJ):
- @mkdir -p $(@D)
@$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
$(CPP) -c $(TESTFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
%.o: %.cpp
- @mkdir -p $(@D)
@$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
$(CPP) -c $(CFLAGS) -o $@ $<
-include $(DEPS)