From 9b4b7e06ede3d94802a30df4e1c965b65a96da51 Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Wed, 8 Sep 2021 14:49:42 +0200 Subject: [PATCH] build: Build and install static library This is useful for client applications. More cleanup may be done afterwards. Relate-to: https://github.com/lvgl/lvgl/issues/2534 Relate-to: https://git.ostc-eu.org/OSTC/planning/core-os/-/issues/219 Forwarded: https://github.com/lvgl/lv_sim_vscode_sdl/pull/10 Signed-off-by: Philippe Coval --- Makefile | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a4545b34..c86e044c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,9 @@ +#! /usr/bin/make -f +# -*- makefile -*- +# ex: set tabstop=4 noexpandtab: + +default: all + # # Makefile # WARNING: relies on invocation setting current working directory to Makefile location @@ -7,6 +13,7 @@ PROJECT ?= lvgl-sdl MAKEFLAGS := -j $(shell nproc) SRC_EXT := c OBJ_EXT := o +LIB_EXT := a CC ?= gcc SRC_DIR := ./ @@ -32,6 +39,7 @@ DEFINES := -D SIMULATOR=1 -D LV_BUILD_TEST=0 INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ LDLIBS := -lSDL2 -lm BIN := $(BIN_DIR)/demo +LIB := $(BIN_DIR)/lib${PROJECT}.${LIB_EXT} COMPILE = $(CC) $(CFLAGS) $(INC) $(DEFINES) @@ -39,20 +47,38 @@ COMPILE = $(CC) $(CFLAGS) $(INC) $(DEFINES) SRCS := $(shell find $(SRC_DIR) -type f -name '*.c' -not -path '*/\.*') OBJECTS := $(patsubst $(SRC_DIR)%,$(BUILD_DIR)/%,$(SRCS:.$(SRC_EXT)=.$(OBJ_EXT))) -all: default +all: ${BIN} ${LIB} + ls $^ $(BUILD_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.$(SRC_EXT) @echo 'Building project file: $<' @mkdir -p $(dir $@) @$(COMPILE) -c -o "$@" "$<" -default: $(OBJECTS) +${BIN}: ${LIB} @mkdir -p $(BIN_DIR) - $(CC) -o $(BIN) $(OBJECTS) $(LDFLAGS) ${LDLIBS} + $(CC) -o $@ $(LDFLAGS) ${LIB} ${LDLIBS} + +${LIB}: ${OBJECTS} + @mkdir -p ${@D} + ${AR} rcs $@ $^ clean: rm -rf $(WORKING_DIR) -install: ${BIN} +install: ${BIN} install-headers install -d ${DESTDIR}/usr/lib/${PROJECT}/bin install $< ${DESTDIR}/usr/lib/${PROJECT}/bin/ + install ${LIB} ${DESTDIR}/usr/lib/${PROJECT}/bin/ + +${DESTDIR}/usr/include/${PROJECT}: + install -d $@ + +install-headers: ${DESTDIR}/usr/include/${PROJECT} + find . -type f \ + \( -iname "debian" -o -iname ".?*" -o -iname "CVS" \) -prune -false \ + -o -type f -iname "*.h" -print \ + | while read t; do \ + install -vd "$