mirror of
https://github.com/ascii-boxes/boxes.git
synced 2024-12-04 22:11:07 +01:00
Enable build process to create a static binary for Unix #100
One can now run "make static" to get a binary that is statically linked to libunistring and pcre2. Both libraries are downloaded first, so they don't need to be available on the machine.
This commit is contained in:
parent
d572344fce
commit
6b6c1ad528
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
@ -6,7 +6,7 @@
|
||||
"${workspaceFolder}/src",
|
||||
"${workspaceFolder}/src/misc",
|
||||
"${workspaceFolder}/out",
|
||||
"${workspaceFolder}/vendor/pcre2-10.36/src",
|
||||
"${workspaceFolder}/vendor/pcre2-10.40/src",
|
||||
"${workspaceFolder}/vendor/cmocka-1.1.0/include"
|
||||
],
|
||||
"defines": [
|
||||
|
52
Makefile
52
Makefile
@ -23,15 +23,17 @@ DOC_FILES = doc/boxes.1 doc/boxes.el
|
||||
PKG_NAME = boxes-$(BVERSION)
|
||||
OUT_DIR = out
|
||||
|
||||
WIN_PCRE2_VERSION = 10.40
|
||||
WIN_PCRE2_DIR = vendor/pcre2-$(WIN_PCRE2_VERSION)
|
||||
PCRE2_VERSION = 10.40
|
||||
PCRE2_DIR = vendor/pcre2-$(PCRE2_VERSION)
|
||||
LIBUNISTRING_VERSION = 1.0
|
||||
LIBUNISTRING_DIR = vendor/libunistring-$(LIBUNISTRING_VERSION)
|
||||
WIN_FLEX_BISON_VERSION = 2.5.24
|
||||
WIN_FLEX_BISON_DIR = vendor/flex_bison_$(WIN_FLEX_BISON_VERSION)
|
||||
WIN_CMOCKA_VERSION = 1.1.0
|
||||
WIN_CMOCKA_DIR = vendor/cmocka-$(WIN_CMOCKA_VERSION)
|
||||
|
||||
.PHONY: clean build cov win32 debug win32.debug win32.pcre infomsg replaceinfos test covtest \
|
||||
package win32.package package_common utest win32.utest
|
||||
package win32.package package_common utest win32.utest static
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@ -42,30 +44,30 @@ build cov debug: infomsg replaceinfos
|
||||
$(MAKE) -C src BOXES_PLATFORM=unix LEX=flex YACC=bison $@
|
||||
|
||||
win32: infomsg replaceinfos
|
||||
$(MAKE) -C src BOXES_PLATFORM=win32 C_INCLUDE_PATH=../$(WIN_PCRE2_DIR)/src LDFLAGS=-L../$(WIN_PCRE2_DIR)/.libs \
|
||||
$(MAKE) -C src BOXES_PLATFORM=win32 C_INCLUDE_PATH=../$(PCRE2_DIR)/src LDFLAGS=-L../$(PCRE2_DIR)/.libs \
|
||||
LEX=../$(WIN_FLEX_BISON_DIR)/win_flex.exe YACC=../$(WIN_FLEX_BISON_DIR)/win_bison.exe build
|
||||
|
||||
win32.debug: infomsg replaceinfos
|
||||
$(MAKE) -C src BOXES_PLATFORM=win32 C_INCLUDE_PATH=../$(WIN_PCRE2_DIR)/src LDFLAGS=-L../$(WIN_PCRE2_DIR)/.libs \
|
||||
$(MAKE) -C src BOXES_PLATFORM=win32 C_INCLUDE_PATH=../$(PCRE2_DIR)/src LDFLAGS=-L../$(PCRE2_DIR)/.libs \
|
||||
LEX=../$(WIN_FLEX_BISON_DIR)/win_flex.exe YACC=../$(WIN_FLEX_BISON_DIR)/win_bison.exe debug
|
||||
|
||||
win32.prereq:
|
||||
# download components
|
||||
curl -LO https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$(WIN_PCRE2_VERSION)/pcre2-$(WIN_PCRE2_VERSION).tar.gz
|
||||
curl -LO https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$(PCRE2_VERSION)/pcre2-$(PCRE2_VERSION).tar.gz
|
||||
curl -LO https://downloads.sourceforge.net/project/winflexbison/win_flex_bison-$(WIN_FLEX_BISON_VERSION).zip
|
||||
curl -LO https://cmocka.org/files/$(WIN_CMOCKA_VERSION:%.0=%)/cmocka-$(WIN_CMOCKA_VERSION)-mingw.zip
|
||||
# unpack components
|
||||
mkdir -p vendor
|
||||
unzip win_flex_bison-$(WIN_FLEX_BISON_VERSION).zip -d $(WIN_FLEX_BISON_DIR)
|
||||
tar -C vendor -xzf pcre2-$(WIN_PCRE2_VERSION).tar.gz
|
||||
tar -C vendor -xzf pcre2-$(PCRE2_VERSION).tar.gz
|
||||
unzip cmocka-$(WIN_CMOCKA_VERSION)-mingw.zip -d vendor
|
||||
# build the pcre2 dependency (only needed on Windows MinGW)
|
||||
cd $(WIN_PCRE2_DIR) ; \
|
||||
cd $(PCRE2_DIR) ; \
|
||||
./configure --disable-pcre2-8 --disable-pcre2-16 --enable-pcre2-32 --disable-shared \
|
||||
--enable-never-backslash-C --enable-newline-is-anycrlf ; \
|
||||
$(MAKE)
|
||||
# remove downloaded archives
|
||||
rm pcre2-$(WIN_PCRE2_VERSION).tar.gz
|
||||
rm pcre2-$(PCRE2_VERSION).tar.gz
|
||||
rm win_flex_bison-$(WIN_FLEX_BISON_VERSION).zip
|
||||
rm cmocka-$(WIN_CMOCKA_VERSION)-mingw.zip
|
||||
|
||||
@ -94,6 +96,34 @@ doc/boxes.1.html: doc/boxes.1
|
||||
@echo "Conversion complete. Excessive manual work remains."
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Static Build (Unix)
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
vendor:
|
||||
mkdir -p vendor
|
||||
|
||||
vendor/libunistring-$(LIBUNISTRING_VERSION).tar.gz: | vendor
|
||||
curl -L https://ftp.gnu.org/gnu/libunistring/libunistring-$(LIBUNISTRING_VERSION).tar.gz --output $@
|
||||
|
||||
$(LIBUNISTRING_DIR)/lib/.libs/libunistring.a: vendor/libunistring-$(LIBUNISTRING_VERSION).tar.gz
|
||||
tar -C vendor -xzf vendor/libunistring-$(LIBUNISTRING_VERSION).tar.gz
|
||||
cd $(LIBUNISTRING_DIR) ; ./configure --enable-static ; $(MAKE)
|
||||
|
||||
vendor/pcre2-$(PCRE2_VERSION).tar.gz: | vendor
|
||||
curl -L https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$(PCRE2_VERSION)/pcre2-$(PCRE2_VERSION).tar.gz --output $@
|
||||
|
||||
$(PCRE2_DIR)/.libs/libpcre2-32.a: vendor/pcre2-$(PCRE2_VERSION).tar.gz
|
||||
tar -C vendor -xzf vendor/pcre2-$(PCRE2_VERSION).tar.gz
|
||||
cd $(PCRE2_DIR) ; \
|
||||
./configure --disable-pcre2-8 --disable-pcre2-16 --enable-pcre2-32 --enable-static --disable-shared \
|
||||
--enable-never-backslash-C --enable-newline-is-anycrlf ; \
|
||||
$(MAKE)
|
||||
|
||||
static: infomsg replaceinfos $(LIBUNISTRING_DIR)/lib/.libs/libunistring.a $(PCRE2_DIR)/.libs/libpcre2-32.a
|
||||
$(MAKE) -C src BOXES_PLATFORM=static LEX=flex YACC=bison LIBUNISTRING_DIR=$(LIBUNISTRING_DIR) PCRE2_DIR=$(PCRE2_DIR) $@
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Standalone Packaging (Unix / Windows)
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@ -159,8 +189,8 @@ utest:
|
||||
|
||||
win32.utest: $(OUT_DIR)
|
||||
cp $(WIN_CMOCKA_DIR)/bin/cmocka.dll $(OUT_DIR)/
|
||||
$(MAKE) -C utest BOXES_PLATFORM=win32 C_INCLUDE_PATH=../$(WIN_PCRE2_DIR)/src:../$(WIN_CMOCKA_DIR)/include \
|
||||
LDFLAGS_ADDTL="-L../$(WIN_PCRE2_DIR)/.libs -L../$(WIN_CMOCKA_DIR)/lib" utest
|
||||
$(MAKE) -C utest BOXES_PLATFORM=win32 C_INCLUDE_PATH=../$(PCRE2_DIR)/src:../$(WIN_CMOCKA_DIR)/include \
|
||||
LDFLAGS_ADDTL="-L../$(PCRE2_DIR)/.libs -L../$(WIN_CMOCKA_DIR)/lib" utest
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Cleanup
|
||||
|
17
src/Makefile
17
src/Makefile
@ -32,7 +32,7 @@ ORIG_SRC = $(ORIG_GEN) $(ORIG_NORM)
|
||||
ORIG_FILES = $(ORIG_SRC) $(ORIG_HDR)
|
||||
|
||||
|
||||
.PHONY: check_dir clean build cov debug package flags_unix flags_win32 flags_
|
||||
.PHONY: boxes.static check_dir clean build cov debug package static flags_unix flags_static flags_win32 flags_
|
||||
|
||||
.NOTPARALLEL:
|
||||
|
||||
@ -49,6 +49,10 @@ build: flags_$(BOXES_PLATFORM) | $(OUT_DIR)
|
||||
$(MAKE) -C $(OUT_DIR) -f $(SRC_DIR)/Makefile BOXES_PLATFORM=$(BOXES_PLATFORM) ALL_OBJ="$(ALL_OBJ)" STRIP=true \
|
||||
CFLAGS_ADDTL="-O $(CFLAGS_ADDTL)" flags_$(BOXES_PLATFORM) $(BOXES_EXECUTABLE_NAME)
|
||||
|
||||
static: flags_$(BOXES_PLATFORM) | $(OUT_DIR)
|
||||
$(MAKE) -C $(OUT_DIR) -f $(SRC_DIR)/Makefile BOXES_PLATFORM=$(BOXES_PLATFORM) ALL_OBJ="$(ALL_OBJ)" STRIP=true \
|
||||
CFLAGS_ADDTL="-O $(CFLAGS_ADDTL)" flags_$(BOXES_PLATFORM) boxes.static
|
||||
|
||||
cov: flags_$(BOXES_PLATFORM) | $(OUT_DIR)
|
||||
$(MAKE) -C $(OUT_DIR) -f $(SRC_DIR)/Makefile BOXES_PLATFORM=$(BOXES_PLATFORM) ALL_OBJ="$(ALL_OBJ)" STRIP=false \
|
||||
CFLAGS_ADDTL="-g --coverage $(CFLAGS_ADDTL)" \
|
||||
@ -63,6 +67,10 @@ boxes: $(ALL_OBJ) | check_dir
|
||||
$(CC) $(LDFLAGS) $^ -o $@ -lunistring -lpcre2-32
|
||||
if [ "$(STRIP)" = "true" ] ; then strip $@ ; fi
|
||||
|
||||
boxes.static: $(ALL_OBJ) | check_dir
|
||||
$(CC) $(LDFLAGS) $^ -o $(BOXES_EXECUTABLE_NAME) -l:libunistring.a -l:libpcre2-32.a
|
||||
if [ "$(STRIP)" = "true" ] ; then strip $(BOXES_EXECUTABLE_NAME) ; fi
|
||||
|
||||
boxes.exe: $(ALL_OBJ) | check_dir
|
||||
$(CC) $(LDFLAGS) $^ -o $@ -lkernel32 -l:libunistring.a -l:libpcre2-32.a -l:libiconv.a
|
||||
if [ "$(STRIP)" = "true" ] ; then strip $@ ; fi
|
||||
@ -75,6 +83,13 @@ flags_unix:
|
||||
$(eval ALL_OBJ := $(GEN_SRC:.c=.o) $(ORIG_NORM:.c=.o))
|
||||
echo $(filter-out boxes.o,$(ALL_OBJ)) > $(OUT_DIR)/modules.txt
|
||||
|
||||
flags_static:
|
||||
$(eval CFLAGS := -I. -I$(SRC_DIR) -Wall -W $(CFLAGS_ADDTL))
|
||||
$(eval LDFLAGS := $(LDFLAGS) -L../$(LIBUNISTRING_DIR)/lib/.libs -L../$(PCRE2_DIR)/.libs $(LDFLAGS_ADDTL))
|
||||
$(eval BOXES_EXECUTABLE_NAME := boxes)
|
||||
$(eval ALL_OBJ := $(GEN_SRC:.c=.o) $(ORIG_NORM:.c=.o))
|
||||
echo $(filter-out boxes.o,$(ALL_OBJ)) > $(OUT_DIR)/modules.txt
|
||||
|
||||
flags_win32:
|
||||
$(eval CFLAGS := -Os -s -m32 -I. -I$(SRC_DIR) -Wall -W $(CFLAGS_ADDTL))
|
||||
$(eval LDFLAGS := $(LDFLAGS) -s -m32)
|
||||
|
Loading…
Reference in New Issue
Block a user