Skip to content

Commit 5a60e8a

Browse files
committed
support static library creation
1 parent 9c6778c commit 5a60e8a

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

Makefile

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ NIMVER:=choosenim $(NIMVER);
5858
endif
5959

6060
DOCOMPRESS:=$(shell echo $(COMPRESS) | tr A-Z a-z | cut -c1-1)
61+
DOSTATIC:=$(shell echo $(STATIC) | tr A-Z a-z | cut -c1-1)
6162

6263
BUILDDEP:=$(wildcard *.nim *.c *.m Makefile config.mk)
6364

@@ -98,6 +99,19 @@ clean: ## Clean up project files
9899
help: ## Show this message
99100
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
100101

102+
helpconfig: ## Show config.mk options
103+
@echo 'Required:'
104+
@echo ' NAME The application name'
105+
@echo ' VERSION The application version'
106+
@echo 'Optional:'
107+
@echo ' COMPILER The nim compiler to use, "c" by default'
108+
@echo ' COMPRESS If the final application should be compressed by upx or not, boolean value, false by default'
109+
@echo ' EXECNAME The executable name, $$NAME by default'
110+
@echo ' NIMOPTS Extra nim compiler options'
111+
@echo ' RUNARGS The run arguments when "run" make target is used'
112+
@echo ' STATIC If the final application should be statically linked, boolean value, false by default'
113+
@echo ' WINAPP Type of windows application, valid values [gui,console], "console" by default'
114+
101115
podman: ## If required, create specific podman containers to aid compiling this project
102116
@if [ "${NIMBLE}" != "" ] ; then \
103117
rm -rf podman.tmp && \
@@ -149,44 +163,68 @@ target/${EXECNAME}:${BUILDDEP}
149163

150164
target/${EXECNAME}.osx:${BUILDDEP}
151165
mkdir -p target
166+
@echo "** WARNING ** static binaries not supported for macOS platform"
152167
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAMEOSX} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} ${OSXNIMOPTS} --os:macosx --passC:'-mmacosx-version-min=10.7 -gfull' --passL:'-mmacosx-version-min=10.7 -dead_strip' ${NAME} && x86_64-apple-darwin19-strip ${NAME}"
153168
mv ${NAME} target/${EXECNAME}.osx
154169
# if [ "$(DOCOMPRESS)" = "t" ] ; then upx --best target/${EXECNAME}.osx ; fi # UPX is broken under OSX right now
155170

156171
target/${EXECNAME}.linux:${BUILDDEP}
157172
mkdir -p target
158-
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} ${LINUXNIMOPTS} ${NAME} && strip ${NAME}"
173+
CC=/cross/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc ;\
174+
CS=/cross/x86_64-linux-musl-cross/bin/x86_64-linux-musl-strip ;\
175+
EXTRA="${LINUXNIMOPTS}" ;\
176+
if [ "$(DOSTATIC)" != "f" ] ; then ASSTATIC="--gcc.exe:$$CC --gcc.linkerexe:$$CC --passL:-static" ; fi ;\
177+
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} $$EXTRA $$ASSTATIC ${NAME} && $$CS ${NAME}"
159178
mv ${NAME} target/${EXECNAME}.linux
160179
if [ "$(DOCOMPRESS)" = "t" ] ; then upx --best target/${EXECNAME}.linux ; fi
161180

162181
target/${EXECNAME}.linux32:${BUILDDEP}
163182
mkdir -p target
164-
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME32} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} ${LINUXNIMOPTS} --cpu:i386 --passC:-m32 --passL:-m32 ${NAME} && strip ${NAME} ; if [ \"$(DOCOMPRESS)\" = \"t\" ] ; then upx --best ${NAME} ; fi"
183+
CC=/cross/i686-linux-musl-cross/bin/i686-linux-musl-gcc ;\
184+
CS=/cross/i686-linux-musl-cross/bin/i686-linux-musl-strip ;\
185+
EXTRA="${LINUXNIMOPTS} --cpu:i386 --passC:-m32 --passL:-m32" ;\
186+
if [ "$(DOSTATIC)" != "f" ] ; then ASSTATIC="--gcc.exe:$$CC --gcc.linkerexe:$$CC --passL:-static" ; fi ;\
187+
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME32} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} $$EXTRA $$ASSTATIC ${NAME} && $$CS ${NAME}"
165188
mv ${NAME} target/${EXECNAME}.linux32
166189
if [ "$(DOCOMPRESS)" = "t" ] ; then upx --best target/${EXECNAME}.linux32 ; fi
167190

168191
target/${EXECNAME}.arm.linux:${BUILDDEP}
169192
mkdir -p target
170-
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} ${PINIMOPTS} --cpu:arm --os:linux ${NAME} && arm-linux-gnueabi-strip ${NAME}"
193+
CC=/cross/armel-linux-musleabihf-cross/bin/armel-linux-musleabihf-gcc ;\
194+
CS=/cross/armel-linux-musleabihf-cross/bin/armel-linux-musleabihf-strip ;\
195+
EXTRA="${PINIMOPTS} --cpu:arm --os:linux" ;\
196+
if [ "$(DOSTATIC)" != "f" ] ; then ASSTATIC="--gcc.exe:$$CC --gcc.linkerexe:$$CC --passL:-static " ; fi ;\
197+
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} $$EXTRA $$ASSTATIC ${NAME} && $$CS ${NAME}"
171198
mv ${NAME} target/${EXECNAME}.arm.linux
172-
patchelf --set-interpreter /lib/ld-linux-armhf.so.3 target/${EXECNAME}.arm.linux
173199
if [ "$(DOCOMPRESS)" = "t" ] ; then upx --best target/${EXECNAME}.arm.linux ; fi
174200

175201
target/${EXECNAME}.aarch64.linux:${BUILDDEP}
176202
mkdir -p target
177-
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} ${PINIMOPTS} --cpu:arm64 --os:linux ${NAME} && aarch64-linux-gnu-strip ${NAME}"
203+
CC=/cross/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc ;\
204+
CS=/cross/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip ;\
205+
EXTRA="${PINIMOPTS} --cpu:arm64 --os:linux";\
206+
if [ "$(DOSTATIC)" != "f" ] ; then ASSTATIC="--gcc.exe:$$CC --gcc.linkerexe:$$CC --passL:-static" ; fi ;\
207+
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} $$EXTRA $$ASSTATIC ${NAME} && $$CS ${NAME}"
178208
mv ${NAME} target/${EXECNAME}.aarch64.linux
179209
if [ "$(DOCOMPRESS)" = "t" ] ; then upx --best target/${EXECNAME}.aarch64.linux ; fi
180210

181211
target/${EXECNAME}.32.exe:${BUILDDEP}
182212
mkdir -p target
183-
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} ${WINDOWSNIMOPTS} -d:mingw --cpu:i386 --app:${WINAPP} ${NAME} && i686-w64-mingw32-strip ${NAME}.exe"
213+
CC=/cross/i686-w64-mingw32-cross/bin/i686-w64-mingw32-gcc ;\
214+
CS=/cross/i686-w64-mingw32-cross/bin/i686-w64-mingw32-strip ;\
215+
EXTRA="${WINDOWSNIMOPTS} -d:mingw --cpu:i386 --app:${WINAPP}" ;\
216+
if [ "$(DOSTATIC)" != "f" ] ; then ASSTATIC="--gcc.exe:$$CC --gcc.linkerexe:$$CC --passL:-static" ; fi ;\
217+
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} $$EXTRA $$ASSTATIC ${NAME} && $$CS ${NAME}".exe
184218
mv ${NAME}.exe target/${EXECNAME}.32.exe
185219
if [ "$(DOCOMPRESS)" = "t" ] ; then upx --best target/${EXECNAME}.32.exe ; fi
186220

187221
target/${EXECNAME}.64.exe:${BUILDDEP}
188222
mkdir -p target
189-
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} ${WINDOWSNIMOPTS} -d:mingw --cpu:amd64 --app:${WINAPP} ${NAME} && x86_64-w64-mingw32-strip ${NAME}.exe"
223+
CC=/cross/x86_64-w64-mingw32-cross/bin/x86_64-w64-mingw32-gcc ;\
224+
CS=/cross/x86_64-w64-mingw32-cross/bin/x86_64-w64-mingw32-strip ;\
225+
EXTRA="${WINDOWSNIMOPTS} -d:mingw --cpu:amd64 --app:${WINAPP}" ;\
226+
if [ "$(DOSTATIC)" != "f" ] ; then ASSTATIC="--gcc.exe:$$CC --gcc.linkerexe:$$CC --passL:-static" ; fi ;\
227+
podman run --rm -v `pwd`:/usr/src/app -w /usr/src/app ${DOCKERNAME} bash -c "${NIMVER} nim ${COMPILER} ${BASENIMOPTS} $$EXTRA $$ASSTATIC ${NAME} && $$CS ${NAME}".exe
190228
mv ${NAME}.exe target/${EXECNAME}.64.exe
191229
if [ "$(DOCOMPRESS)" = "t" ] ; then upx --best target/${EXECNAME}.64.exe ; fi
192230

config.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ EXECNAME=dpr
1212
RUNARGS=--dpr-help
1313

1414
#COMPRESS=true
15+
16+
#STATIC=false

0 commit comments

Comments
 (0)