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: #10
Signed-off-by: Philippe Coval <[email protected]>
  • Loading branch information
rzr committed Sep 9, 2021
1 parent 1010181 commit 5d5b30e
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 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,52 @@ 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)

prefix ?= usr/local
libdir ?= ${prefix}/lib
includedir ?= ${prefix}/include
sudo ?=
# 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 -d ${DESTDIR}/usr/lib/${PROJECT}/bin
install $< ${DESTDIR}/usr/lib/${PROJECT}/bin/
install: ${BIN} install-headers
@echo "info: installing to ${DESTDIR} (sudo=${sudo})"
${sudo} install -d ${DESTDIR}/${libdir}/${PROJECT}/bin/
${sudo} install $< ${DESTDIR}/${libdir}/${PROJECT}/bin/demo
${sudo} install -d ${DESTDIR}/${libdir}
${sudo} install ${LIB} ${DESTDIR}/${libdir}

${DESTDIR}/${includedir}/${PROJECT}:
${sudo} install -d $@

install-headers: ${DESTDIR}/${includedir}/${PROJECT}
find . -type f \
\( -iname "debian" -o -iname ".?*" -o -iname "CVS" \) -prune -false \
-o -type f -iname "*.h" -print \
| while read t; do \
${sudo} install -vd "$</`dirname $${t}`"; \
${sudo} install -v "$${t}" "$</$${t}"; \
done

5 comments on commit 5d5b30e

@microwavesafe
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started this project to simulate my embedded development. This would be with the library compiled directly into the executable. By changing what is built and how I'm worried we are diverging too far away from that original goal?

@rzr
Copy link
Contributor Author

@rzr rzr commented on 5d5b30e Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I know it's not perfect but I reused your WIP branch, to build an other app using SDL2 it worked for me

https://git.ostc-eu.org/rzr/dialog-lvgl

https://forum.lvgl.io/c/my-projects/10

yes but this be can cleaned up but I won't cause any harm

@microwavesafe
Copy link
Collaborator

@microwavesafe microwavesafe commented on 5d5b30e Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right in saying that the default build is now a linked library rather than a single executable? My slight issue with this is that this may work for you, but does it break anything for the other users of this project? I know I enjoy having a single executable that I can easily share with others.

If the default was to build the project as a single executable, but the Makefile could be switched over to create a library and executable that would be better.

Apologies if I've misunderstood the changes to the Makefile.

@rzr
Copy link
Contributor Author

@rzr rzr commented on 5d5b30e Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default will build the executable linked to static lib (which contain the demo app too) this is the same lib I reused for an other app.
It worked enough to support by yocto system ( lvgl/lvgl#2534 )

dialog-lgvl-input

I am currently trying to rebuild latest lvgl

@microwavesafe
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default will build the executable linked to static lib (which contain the demo app too)

This is the part I have a problem with. I realise doing this suits your needs, but selfishly, they don't suit mine. If the pull request left the original build process in place, but could be configured to the new build process I would be willing to consider it.

Please sign in to comment.