Skip to content

Commit

Permalink
Add ability to build various static supporting libraries to
Browse files Browse the repository at this point in the history
contain code that is shared between several modules.

Discussed with @liviuchircu & @bogdan-iancu.
  • Loading branch information
sobomax committed Oct 14, 2020
1 parent 25e55f1 commit 9569160
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.o
*.d
*.so
*.a
*.sw?
tags
cscope*
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ $(modules):

.PHONY: modules
modules: $(deps_gen)
@set -e; \
for r in $(all_misclibs); do \
echo "" ; \
echo "" ; \
$(MAKE) -j -C $$r ; \
done
ifeq (,$(FASTER))
@set -e; \
for r in $(modules) "" ; do \
Expand Down
5 changes: 4 additions & 1 deletion Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ else
makefile_defs=1
export makefile_defs

_makefile_defs_path := $(lastword $(MAKEFILE_LIST))
TOP_SRCDIR?= $(shell realpath `dirname $(_makefile_defs_path)`)

# main binary name
MAIN_NAME=opensips

Expand Down Expand Up @@ -1675,7 +1678,7 @@ endif


## Unit Testing - required extensions
ifeq (1,$(shell grep -c '^\DEFS+= -DUNIT_TESTS' Makefile.conf))
ifeq (1,$(shell grep -c '^\DEFS+= -DUNIT_TESTS' $(TOP_SRCDIR)/Makefile.conf))
DEFS := $(DEFS) -DUNIT_TESTS
LIBS := $(LIBS) -ltap
test_src := $(shell find . -wholename "*/test/*\.c" | grep -v "^./modules/")
Expand Down
22 changes: 22 additions & 0 deletions Makefile.misclibs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Miscelanious library Makefile
#(to be included from each library)
#

_makefile_misclibs_path := $(lastword $(MAKEFILE_LIST))
TOP_SRCDIR?= $(shell realpath `dirname $(_makefile_misclibs_path)`)

include $(TOP_SRCDIR)/Makefile.defs

NAME= lib${LIBNAME}.a
LD= $(TOP_SRCDIR)/scripts/build/linkstatic.sh

include $(TOP_SRCDIR)/Makefile.conf

LIBS=
TWEAK_LIBS=
LDFLAGS=
CFLAGS:=$(MOD_CFLAGS)

include $(TOP_SRCDIR)/Makefile.sources
include $(TOP_SRCDIR)/Makefile.rules
11 changes: 4 additions & 7 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ all_nostatic_modules=$(filter-out $(addprefix modules/, $(static_modules)), \
all_modules:=$(addprefix modules/, $(all_modules))
all_modules:=$(addprefix net/, $(builtin_modules)) $(all_modules)
all_utils:=$(addprefix utils/, $(all_utils))
all_misclibs=reg
all_misclibs:=$(addprefix lib/, $(all_misclibs))

#implicit rules
%.o: %.c $(ALLDEP)
Expand Down Expand Up @@ -147,12 +149,7 @@ dbschema-docbook-clean:
.PHONY: clean
clean: docbook-clean dbschema-docbook-clean
-@rm -f $(objs) $(NAME) $(objs:.o=.il) 2>/dev/null
-@for r in $(all_modules) "" ; do \
if [ -d "$$r" -a -f "$$r/Makefile" ]; then \
$(MAKE) -C $$r clean ; \
fi ; \
done
-@for r in $(all_utils) "" ; do \
-@for r in $(all_modules) $(all_utils) $(all_misclibs); do \
if [ -d "$$r" -a -f "$$r/Makefile" ]; then \
$(MAKE) -C $$r clean ; \
fi ; \
Expand All @@ -164,7 +161,7 @@ clean: docbook-clean dbschema-docbook-clean
proper realclean distclean: clean
-@rm -f $(depends) $(deps_gen) $(auto_gen) 2>/dev/null
-@rm -f cfg.tab.h 2>/dev/null
-@for r in $(all_nostatic_modules) "" ; do \
-@for r in $(all_nostatic_modules) $(all_misclibs) ; do \
if [ -d "$$r" -a -f "$$r/Makefile" ]; then \
$(MAKE) -C $$r proper ; \
fi ; \
Expand Down
28 changes: 28 additions & 0 deletions scripts/build/linkstatic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

set -e

AR=${AR:-"ar"}
RANLIB=${RANLIB:-"ranlib"}

LINKARGS=""
ARNAME=""
nmfollows=0
for var in "$@"
do
if [ ${nmfollows} -ne 0 ]
then
ARNAME="${var}"
nmfollows=0
continue
fi
if [ "${var}" != "-o" ]
then
LINKARGS="${LINKARGS} ${var}"
continue
fi
nmfollows=1
done

${AR} cr "${ARNAME}" ${LINKARGS}
${RANLIB} "${ARNAME}"

0 comments on commit 9569160

Please sign in to comment.