Skip to content

Commit

Permalink
Makefile : - add keyword "static" to build a static version of binary
Browse files Browse the repository at this point in the history
	- the keyword "dyn" is to build a shared version (it is the default)
  • Loading branch information
Raizo62 committed Aug 27, 2022
1 parent 3797027 commit 41039f4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ MAN := man

CXX ?= g++

#STATIC := -static

#MODE+= -O3 -s -Wall -Wextra -pedantic -DNDEBUG # ////////// RELEASE WITHOUT ASSERT
MODE+= -O3 -s -Wall -Wextra -pedantic # ////////// RELEASE
#MODE+= -g -Wall -Wextra -pedantic -D_DEBUG # ////////// DEBUG
Expand All @@ -40,7 +42,7 @@ EUID := $(shell id -u -r)
vpath %.cc $(SRC)
vpath %.h $(SRC)

.PHONY: all clean build install man dep tools directories update edit cppcheck gitversion
.PHONY: all clean build install man dep tools directories update edit cppcheck gitversion static dyn

build : directories $(EXEC) # man

Expand All @@ -53,7 +55,7 @@ $(OBJ)/%.o:
# To build bin :
# On OpenWRT, $(LDFLAGS) must be after $^
$(EXEC):
$(CXX) -o $@ $(MODE) $^ $(LDFLAGS)
$(CXX) -o $@ $(MODE) $(STATIC) $^ $(LDFLAGS)

$(MAN)/$(NAME).1.gz : $(MAN)/$(NAME).1
gzip -c $(MAN)/$(NAME).1 > $(MAN)/$(NAME).1.gz
Expand Down Expand Up @@ -86,6 +88,12 @@ edit:
cppcheck:
cppcheck --verbose --enable=all --enable=style --xml $(CFLAGS) $(DEFS) -D_DEBUG $(SRC)/*.cc 2> $(NAME)-cppcheck.xml

dyn:
@sed -i 's/^\s*STATIC\s*:=\(.*\)/#STATIC := \1/g' Makefile

static:
@sed -i 's/^\s*#\s*STATIC\s*:=\(.*\)/STATIC := \1/g' Makefile

gitversion: .git
@sed -n "s/^\(VERSION.[^\-]*\)\(-.*\)\?/\1-$(shell git log --pretty=format:"%h" -n 1)/gp" Makefile
@sed -i "s/^\(VERSION.[^\-]*\)\(-.*\)\?/\1-$(shell git log --pretty=format:"%h" -n 1)/g" Makefile
Expand Down

0 comments on commit 41039f4

Please sign in to comment.