From 47361fa75035d78117ec2c97a3b84be3a5259820 Mon Sep 17 00:00:00 2001
From: Tony Theodore
Date: Mon, 3 Feb 2014 18:22:54 +1100
Subject: [PATCH] Makefile docs and pkgconf: add support for shared|static
variants
---
Makefile | 32 ++++++++++++++++++++++++++++----
index.html | 26 +++++++++++++-------------
src/pkgconf.mk | 4 ++--
3 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/Makefile b/Makefile
index 9093c532..7d391000 100644
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,12 @@ TOP_DIR := $(patsubst %/,%,$(dir $(MAKEFILE)))
# See doc/gmsl.html for further information
include $(TOP_DIR)/tools/gmsl
-MXE_TARGET_LIST := i686-pc-mingw32 x86_64-w64-mingw32 i686-w64-mingw32
-MXE_TARGETS := i686-pc-mingw32
+MXE_TRIPLETS := i686-pc-mingw32 x86_64-w64-mingw32 i686-w64-mingw32
+MXE_LIB_TYPES := static shared
+MXE_TARGET_LIST := $(foreach LIB_TYPE,$(MXE_LIB_TYPES),\
+ $(addsuffix .$(LIB_TYPE),$(MXE_TRIPLETS)))
+MXE_TARGETS := i686-pc-mingw32.static
+
DEFAULT_MAX_JOBS := 6
SOURCEFORGE_MIRROR := freefr.dl.sourceforge.net
PKG_MIRROR := s3.amazonaws.com/mxe-pkg
@@ -46,6 +50,14 @@ BUILD := $(shell '$(TOP_DIR)/tools/config.guess')
BUILD_PKGS := $(shell grep -l 'BUILD_$$(BUILD)' '$(TOP_DIR)/src/'*.mk | $(SED) -n 's,.*src/\(.*\)\.mk,\1,p')
PATH := $(PREFIX)/$(BUILD)/bin:$(PREFIX)/bin:$(PATH)
+MXE_CONFIGURE_OPTS = \
+ --host='$(TARGET)' \
+ --build='$(BUILD)' \
+ --prefix='$(PREFIX)/$(TARGET)' \
+ $(if $(BUILD_STATIC), \
+ --enable-static --disable-shared , \
+ --disable-static --enable-shared )
+
# use a minimal whitelist of safe environment variables
ENV_WHITELIST := PATH LANG MAKE% MXE% %PROXY %proxy
unexport $(filter-out $(ENV_WHITELIST),$(shell env | cut -d '=' -f1))
@@ -190,6 +202,15 @@ $(1): | $(if $(value $(1)_DEPS), \
$(addprefix $(PREFIX)/$($(1)_DEPS)/installed/,$(PKGS))))) \
$($(1)_DEPS)
@echo '[target] $(1) $(call TARGET_HEADER)'
+ $(if $(findstring 1,$(words $(subst ., ,$(1)))),
+ @echo
+ @echo '------------------------------------------------------------'
+ @echo 'Warning: Deprecated target name $(1) specified'
+ @echo
+ @echo 'Please use $(1).[$(subst $(space),|,$(MXE_LIB_TYPES))] instead'
+ @echo 'See index.html for further information'
+ @echo '------------------------------------------------------------'
+ @echo)
endef
$(foreach TARGET,$(MXE_TARGETS),$(eval $(call TARGET_RULE,$(TARGET))))
@@ -199,8 +220,10 @@ $(foreach TARGET,$(MXE_TARGETS),$(eval $(call TARGET_RULE,$(TARGET))))
LOOKUP_PKG_RULE = $(strip \
$(if $(findstring undefined, $(flavor $(1)_$(2)_$(3))),\
$(if $(3),\
- $(call LOOKUP_PKG_RULE,$(1),$(2),$(call merge,.,$(call chop,$(call split,.,$(3))))),\
- $(1)_$(2)),\
+ $(call LOOKUP_PKG_RULE,$(1),$(2),$(call merge,.,$(call chop,$(call split,.,$(3)))),$(or $(4),$(call uc,$(word 2,$(subst ., ,$(3)))))),\
+ $(if $(4),\
+ $(call LOOKUP_PKG_RULE,$(1),$(2),$(4)),\
+ $(1)_$(2))),\
$(1)_$(2)_$(3)))
define PKG_RULE
@@ -262,6 +285,7 @@ $(PREFIX)/$(3)/installed/$(1): $(TOP_DIR)/src/$(1).mk \
.PHONY: build-only-$(1)_$(3)
build-only-$(1)_$(3): PKG = $(1)
build-only-$(1)_$(3): TARGET = $(3)
+build-only-$(1)_$(3): BUILD_$(if $(findstring shared,$(3)),SHARED,STATIC) = TRUE
build-only-$(1)_$(3): CMAKE_TOOLCHAIN_FILE = $(PREFIX)/$(3)/share/cmake/mxe-conf.cmake
build-only-$(1)_$(3):
$(if $(value $(call LOOKUP_PKG_RULE,$(1),BUILD,$(3))),
diff --git a/index.html b/index.html
index 71270742..fb0cc483 100644
--- a/index.html
+++ b/index.html
@@ -321,10 +321,10 @@ exit
make gtk lua libidn
Targets can also be specified on the command line.
- By default, only i686-pc-mingw32 is built, but you can
+ By default, only i686-pc-mingw32.static is built, but you can
build your toolchain(s) of choice with:
- make MXE_TARGETS='x86_64-w64-mingw32 i686-w64-mingw32'
+ make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static'
or by adjusting the MXE_TARGETS
variable
in settings.mk
.
@@ -363,9 +363,9 @@ exit
you can add separate entries for cross builds:
export PKG_CONFIG_PATH="entries for native builds"
- export PKG_CONFIG_PATH_i686_pc_mingw32="entries for MXE builds"
+ export PKG_CONFIG_PATH_i686_pc_mingw32_static="entries for MXE builds"
- Remember to use i686-pc-mingw32-pkg-config
+ Remember to use i686-pc-mingw32.static-pkg-config
instead of pkg-config for cross builds.
The Autotools do that automatically for you.
@@ -397,13 +397,13 @@ exit
Autotools,
all you have to do is:
- ./configure --host=i686-pc-mingw32
+ ./configure --host=i686-pc-mingw32.static
make
If you build a library, you might also want to enforce a static build:
- ./configure --host=i686-pc-mingw32 --enable-static --disable-shared
+ ./configure --host=i686-pc-mingw32.static --enable-static --disable-shared
make
@@ -422,7 +422,7 @@ If a cross compiler is detected then cross compile mode will be used.
CMake project,
you can use the provided toolchain file:
- cmake ... -DCMAKE_TOOLCHAIN_FILE=/where MXE is installed/usr/i686-pc-mingw32/share/cmake/mxe-conf.cmake
+ cmake ... -DCMAKE_TOOLCHAIN_FILE=/where MXE is installed/usr/i686-pc-mingw32.static/share/cmake/mxe-conf.cmake
Step 5c: Cross compile your Project (Qt)
@@ -431,7 +431,7 @@ If a cross compiler is detected then cross compile mode will be used.
Qt application,
all you have to do is:
- /where MXE is installed/usr/i686-pc-mingw32/qt/bin/qmake
+ /where MXE is installed/usr/i686-pc-mingw32.static/qt/bin/qmake
make
Note that Qt 4 is in the "qt" subdirectory. Qt 5 is in the "qt5" subdirectory
@@ -466,7 +466,7 @@ PKG_CONFIG=$(CROSS)pkg-config
Then, all you have to do is:
- make CROSS=i686-pc-mingw32-
+ make CROSS=i686-pc-mingw32.static-
That's it!
@@ -489,12 +489,12 @@ USE_OSGPLUGIN(<plugin2>)
OpenSceneGraph source distribution for an example. This example can be
compiled with the following command:
- i686-pc-mingw32-g++ \
+ i686-pc-mingw32.static-g++ \
-o osgstaticviewer.exe examples/osgstaticviewer/osgstaticviewer.cpp \
- `i686-pc-mingw32-pkg-config --cflags openscenegraph-osgViewer openscenegraph-osgPlugins` \
- `i686-pc-mingw32-pkg-config --libs openscenegraph-osgViewer openscenegraph-osgPlugins`
+ `i686-pc-mingw32.static-pkg-config --cflags openscenegraph-osgViewer openscenegraph-osgPlugins` \
+ `i686-pc-mingw32.static-pkg-config --libs openscenegraph-osgViewer openscenegraph-osgPlugins`
- The i686-pc-mingw32-pkg-config
command from MXE will
+ The i686-pc-mingw32.static-pkg-config
command from MXE will
automatically add -DOSG_LIBRARY_STATIC
to your compiler flags.
diff --git a/src/pkgconf.mk b/src/pkgconf.mk
index cca6855b..a5d4146c 100644
--- a/src/pkgconf.mk
+++ b/src/pkgconf.mk
@@ -41,7 +41,7 @@ define $(PKG)_BUILD_COMMON
# create pkg-config script
(echo '#!/bin/sh'; \
- echo 'PKG_CONFIG_PATH="$(PREFIX)/$(TARGET)/qt5/lib/pkgconfig":"$$PKG_CONFIG_PATH_$(subst -,_,$(TARGET))" PKG_CONFIG_LIBDIR='\''$(PREFIX)/$(TARGET)/lib/pkgconfig'\'' exec '$(PREFIX)/$(TARGET)/bin/pkg-config' --static "$$@"') \
+ echo 'PKG_CONFIG_PATH="$(PREFIX)/$(TARGET)/qt5/lib/pkgconfig":"$$PKG_CONFIG_PATH_$(subst .,_,$(subst -,_,$(TARGET)))" PKG_CONFIG_LIBDIR='\''$(PREFIX)/$(TARGET)/lib/pkgconfig'\'' exec '$(PREFIX)/$(TARGET)/bin/pkg-config' $(if $(BUILD_STATIC),--static) "$$@"') \
> '$(PREFIX)/bin/$(TARGET)-pkg-config'
chmod 0755 '$(PREFIX)/bin/$(TARGET)-pkg-config'
@@ -49,7 +49,7 @@ define $(PKG)_BUILD_COMMON
[ -d '$(dir $(CMAKE_TOOLCHAIN_FILE))' ] || mkdir -p '$(dir $(CMAKE_TOOLCHAIN_FILE))'
(echo 'set(CMAKE_SYSTEM_NAME Windows)'; \
echo 'set(MSYS 1)'; \
- echo 'set(BUILD_SHARED_LIBS OFF)'; \
+ echo 'set(BUILD_SHARED_LIBS $(if $(BUILD_SHARED),ON,OFF))'; \
echo 'set(CMAKE_BUILD_TYPE Release)'; \
echo 'set(CMAKE_FIND_ROOT_PATH $(PREFIX)/$(TARGET))'; \
echo 'set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)'; \