Skip to content

Commit

Permalink
build: Build and install static library
Browse files Browse the repository at this point in the history
This is useful for client applications.
More cleanup may be done afterwards.

Relate-to: lvgl/lvgl#2534
Relate-to: https://git.ostc-eu.org/OSTC/planning/core-os/-/issues/219
Forwarded: lvgl#10
Signed-off-by: Philippe Coval <[email protected]>
  • Loading branch information
rzr committed Sep 8, 2021
1 parent 1010181 commit 9b4b7e0
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,6 +13,7 @@ PROJECT ?= lvgl-sdl
MAKEFLAGS := -j $(shell nproc)
SRC_EXT := c
OBJ_EXT := o
LIB_EXT := a
CC ?= gcc

SRC_DIR := ./
Expand All @@ -32,27 +39,46 @@ 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)

# Automatically include all source files
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 "$</`dirname $${t}`"; \
install -v "$${t}" "$</$${t}"; \
done

0 comments on commit 9b4b7e0

Please sign in to comment.