Skip to content

Commit 1d65325

Browse files
committed
Add basic infrastructure for doing 32 and 64-bit GCC builds on macOS
Using make to do the platform selection is admittedly abusing the hammer beyond any sort of sanity, but was a fun exercise ;)
1 parent 63da17b commit 1d65325

File tree

4 files changed

+177
-5
lines changed

4 files changed

+177
-5
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**

Dockerfile.linux-gcc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ubuntu:16.04
2+
3+
ARG arch
4+
5+
RUN dpkg --add-architecture $arch && \
6+
apt-get update && \
7+
apt-get install -y \
8+
build-essential \
9+
g++-multilib \
10+
pkg-config:$arch \
11+
libfuse-dev:$arch \
12+
fuse:$arch

Makefile

+121-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,123 @@
1+
#
2+
# Usage: make [target] [platform|alias|all], e.g.:
3+
#
4+
# $ make clean all - cleans all available platforms
5+
# $ make gcc - builds on all available GCC platforms
6+
#
7+
# Copyright (c) 2018 Tor Arne Vestbø
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in all
17+
# copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
25+
# OR OTHER DEALINGS IN THE SOFTWARE.
26+
#
27+
# ------------ Platform selection ------------
28+
29+
AVAILABLE_PLATFORMS := macos-clang-64 linux-gcc-32 linux-gcc-64
30+
31+
OS := $(shell uname -s)
32+
ARCH ?= $(shell uname -m)
33+
34+
ifeq ($(OS),Darwin)
35+
NATIVE_PLATFORM=macos-clang-64
36+
else ifeq ($(OS),Linux)
37+
ifeq ($(ARCH),x86_64)
38+
NATIVE_PLATFORM=linux-gcc-64
39+
else
40+
NATIVE_PLATFORM=linux-gcc-32
41+
endif
42+
endif
43+
44+
ACTUAL_GOALS := $(MAKECMDGOALS)
45+
ifneq ($(filter all,$(MAKECMDGOALS)),)
46+
PLATFORMS := $(AVAILABLE_PLATFORMS)
47+
ACTUAL_GOALS := $(filter-out all,$(ACTUAL_GOALS))
48+
all: ; @:
49+
endif
50+
51+
define expand_platform_alias
52+
ifneq ($(filter $(alias),$(MAKECMDGOALS)),)
53+
PLATFORMS += $(platform)
54+
ACTUAL_GOALS := $(filter-out $(alias),$(ACTUAL_GOALS))
55+
$(alias):: $$(PLATFORMS) ; @:
56+
endif
57+
endef
58+
59+
define detect_platform
60+
ifneq ($(filter $(platform),$(MAKECMDGOALS)),)
61+
PLATFORMS += $(platform)
62+
ACTUAL_GOALS := $(filter-out $(platform),$(ACTUAL_GOALS))
63+
endif
64+
$(foreach alias,$(subst -, ,$(platform)), $(eval $(expand_platform_alias)))
65+
endef
66+
67+
$(foreach platform,$(AVAILABLE_PLATFORMS), $(eval $(detect_platform)))
68+
PLATFORMS := $(strip $(sort $(subst $(COMMA), ,$(PLATFORMS))))
69+
ifeq ($(PLATFORMS),)
70+
PLATFORMS := $(NATIVE_PLATFORM)
71+
endif
72+
73+
COMMA := ,
74+
MFLAGS := $(filter-out --jobserver-fds%,$(MFLAGS))
75+
make_noop = $(eval $$($1): % : ; @:)
76+
ensure_binary = $(if $(shell which $1),,\
77+
$(error Could not find '$(strip $1)' binary))
78+
79+
# ------------ Multiple platforms ------------
80+
81+
ifeq ($(shell expr $(words $(PLATFORMS)) \> 1), 1)
82+
83+
%:: $(PLATFORMS) ;
84+
$(PLATFORMS):
85+
@$(MAKE) -f $(MAKEFILE_LIST) $(MFLAGS) \
86+
$(filter-out $(NATIVE_PLATFORM),$@) $(ACTUAL_GOALS)
87+
88+
$(call make_noop,ACTUAL_GOALS)
89+
90+
# ------------ Single non-native platform ------------
91+
92+
else ifneq ($(NATIVE_PLATFORM),$(PLATFORMS))
93+
94+
linux-gcc-%: docker ;
95+
docker:
96+
$(call ensure_binary,docker-compose)
97+
@docker-compose run --rm $(PLATFORMS) $(MFLAGS) $(ACTUAL_GOALS)
98+
@stty sane # Work around docker-compose messing up the terminal
99+
100+
$(call make_noop,ACTUAL_GOALS)
101+
102+
%::
103+
$(error "No way to build for $(PLATFORMS) on $(NATIVE_PLATFORM))
104+
105+
# ------------ Native platform ------------
106+
107+
else
108+
1109
TARGET = sparsebundlefs
110+
.DEFAULT_GOAL := $(TARGET)
111+
112+
$(call make_noop,NATIVE_PLATFORM)
113+
114+
ifeq ($(strip $(ACTUAL_GOALS)),)
115+
ACTUAL_GOALS := $(.DEFAULT_GOAL)
116+
$(NATIVE_PLATFORM): $(ACTUAL_GOALS)
117+
endif
2118

3119
# Note: Doesn't work for paths with spaces in them
4-
SRC_DIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
120+
SRC_DIR=$(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
5121
vpath %.cpp $(SRC_DIR)
6122

7123
PKG_CONFIG = pkg-config
@@ -14,10 +130,10 @@ endif
14130

15131
DEFINES = -DFUSE_USE_VERSION=26
16132

17-
ifeq ($(shell uname), Darwin)
133+
ifeq ($(OS),Darwin)
18134
# Pick up OSXFUSE, even with pkg-config from MacPorts
19135
PKG_CONFIG := PKG_CONFIG_PATH=/usr/local/lib/pkgconfig $(PKG_CONFIG)
20-
else ifeq ($(shell uname), Linux)
136+
else ifeq ($(OS),Linux)
21137
LFLAGS += -Wl,-rpath=$(shell $(PKG_CONFIG) fuse --variable=libdir)
22138
endif
23139

@@ -26,8 +142,8 @@ FUSE_FLAGS := $(shell $(PKG_CONFIG) fuse --cflags --libs)
26142
$(TARGET): sparsebundlefs.cpp
27143
$(CXX) $< -o $@ $(CFLAGS) $(FUSE_FLAGS) $(LFLAGS) $(DEFINES)
28144

29-
all: $(TARGET)
30-
31145
clean:
32146
rm -f $(TARGET)
33147
rm -Rf $(TARGET).dSYM
148+
149+
endif

docker-compose.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3.7'
2+
3+
x-base-service: &base-service
4+
build: &base-build
5+
context: .
6+
dockerfile: Dockerfile.linux-gcc
7+
volumes:
8+
- &src-volume .:/src
9+
working_dir: /build
10+
entrypoint:
11+
- make
12+
- -f
13+
- /src/Makefile
14+
network_mode: none
15+
16+
services:
17+
linux-gcc-32:
18+
<<: *base-service
19+
build:
20+
<<: *base-build
21+
args:
22+
- arch=i386
23+
volumes:
24+
- *src-volume
25+
- linux-gcc-32:/build
26+
environment:
27+
- CFLAGS=-m32
28+
- ARCH=i386
29+
30+
linux-gcc-64:
31+
<<: *base-service
32+
build:
33+
<<: *base-build
34+
args:
35+
- arch=amd64
36+
volumes:
37+
- *src-volume
38+
- linux-gcc-64:/build
39+
40+
volumes:
41+
linux-gcc-32:
42+
linux-gcc-64:
43+

0 commit comments

Comments
 (0)