Skip to content

Commit 8a12381

Browse files
dalcinljeffhammond
authored andcommitted
Setup as project with CMake/Meson/Make build support
* Move all sources to top level directory. * Default install prefix is the top level directory
1 parent 3921590 commit 8a12381

File tree

11 files changed

+289
-25
lines changed

11 files changed

+289
-25
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/build/
2+
/install/
3+
/bin/
4+
/include/
5+
/lib/
6+
/lib64/
7+
18
# Prerequisites
29
*.d
310

CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
cmake_minimum_required(VERSION 3.5.0)
2+
project(mpi-stubs VERSION 4.2 LANGUAGES C)
3+
4+
option(BUILD_SHARED_LIBS "Build libraries as SHARED" TRUE)
5+
6+
add_library(mpi_abi mpistubs.c)
7+
set_target_properties(mpi_abi PROPERTIES VERSION 0)
8+
9+
include(GNUInstallDirs)
10+
install(FILES mpi.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
11+
install(TARGETS mpi_abi DESTINATION ${CMAKE_INSTALL_LIBDIR})
12+
13+
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
14+
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
15+
set(permissions
16+
OWNER_READ OWNER_WRITE OWNER_EXECUTE
17+
GROUP_READ GROUP_EXECUTE
18+
WORLD_READ WORLD_EXECUTE
19+
)
20+
set(CC CC)
21+
set(cc cc)
22+
set(op cc)
23+
configure_file(mpicc.in mpicc @ONLY)
24+
install(
25+
FILES ${CMAKE_BINARY_DIR}/mpicc
26+
PERMISSIONS ${permissions}
27+
DESTINATION ${CMAKE_INSTALL_BINDIR}
28+
)
29+
set(CC CXX)
30+
set(cc c++)
31+
set(op cxx)
32+
configure_file(mpicc.in mpicxx @ONLY)
33+
install(
34+
FILES ${CMAKE_BINARY_DIR}/mpicxx
35+
PERMISSIONS ${permissions}
36+
DESTINATION ${CMAKE_INSTALL_BINDIR}
37+
)

Makefile

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,96 @@
1-
all:
2-
$(MAKE) -C lib $@
1+
# -*- mode: makefile-gmake -*-
2+
.PHONY: default
3+
default: install
4+
5+
SCRIPTS = mpicc mpicxx
6+
SOURCE_H = mpi.h
7+
SOURCE_C = mpistubs.c
8+
LIBNAME = mpi_abi
9+
VERSION = 0
10+
11+
PREFIX = .
12+
BINDIR = bin
13+
INCDIR = include
14+
LIBDIR = lib
15+
16+
BUILD = build
17+
18+
LN = ln -f
19+
LN_S = $(LN) -s
20+
MKDIR = mkdir -p
21+
RANLIB = ranlib
22+
23+
UNAME_S := $(shell uname -s)
24+
ifeq ($(UNAME_S),Linux)
25+
SED_I = sed -i
26+
LIBFILE = lib$(LIBNAME).so.$(VERSION)
27+
soname = -Wl,-soname,$1
28+
endif
29+
ifeq ($(UNAME_S),Darwin)
30+
SED_I = sed -i''
31+
LIBFILE = lib$(LIBNAME).$(VERSION).dylib
32+
soname = -Wl,-install_name,@rpath/$1
33+
endif
34+
LIBLINK = $(subst .$(VERSION),,$(LIBFILE))
35+
36+
ifndef CFLAGS
37+
CFLAGS = -Wall -Wextra -pedantic -Wno-unused-parameter
38+
endif
39+
40+
.SECONDEXPANSION: # to expand $$(@D)/.DIR
41+
42+
$(BUILD)/mpicc: CC := CC
43+
$(BUILD)/mpicc: cc := cc
44+
$(BUILD)/mpicc: op := cc
45+
$(BUILD)/mpicxx: CC := CXX
46+
$(BUILD)/mpicxx: cc := c++
47+
$(BUILD)/mpicxx: op := cxx
48+
$(BUILD)/mpic%: mpicc.in | $$(@D)/.DIR
49+
cp $< $@
50+
$(SED_I) -e 's:@includedir@:$(abspath $(PREFIX))/$(INCDIR):' $@
51+
$(SED_I) -e 's:@libdir@:$(abspath $(PREFIX))/$(LIBDIR):' $@
52+
$(SED_I) -e 's/@CC@/$(CC)/g' $@
53+
$(SED_I) -e 's/@cc@/$(cc)/g' $@
54+
$(SED_I) -e 's/@op@/$(op)/g' $@
55+
56+
$(BUILD)/$(LIBFILE): $(SOURCE_C) $(SOURCE_H) | $$(@D)/.DIR
57+
$(LINK.c) -shared $(call soname,$(notdir $@)) -o $@ $<
58+
59+
%/.DIR :
60+
$(MKDIR) $(@D)
61+
touch $@
62+
63+
$(DESTDIR)$(PREFIX)/%/.:
64+
$(MKDIR) $@
65+
66+
.PHONY: build
67+
build: $(foreach f,$(SCRIPTS),$(BUILD)/$(f))
68+
build: $(BUILD)/$(LIBFILE)
69+
70+
DESTBINDIR = $(DESTDIR)$(PREFIX)/$(BINDIR)
71+
DESTINCDIR = $(DESTDIR)$(PREFIX)/$(INCDIR)
72+
DESTLIBDIR = $(DESTDIR)$(PREFIX)/$(LIBDIR)
73+
74+
.PHONY: install install-scripts install-headers install-library
75+
install: install-scripts install-headers install-library
76+
install-scripts: $(foreach f,$(SCRIPTS),$(BUILD)/$(f)) | $(DESTBINDIR)/.
77+
install -c -m 755 $^ $(DESTBINDIR)
78+
install-headers: $(SOURCE_H) | $(DESTINCDIR)/.
79+
install -c -m 644 $^ $(DESTINCDIR)
80+
install-library: $(BUILD)/$(LIBFILE) | $(DESTLIBDIR)/.
81+
install -c $^ $(DESTLIBDIR)
82+
cd $(DESTLIBDIR) && $(LN_S) $(LIBFILE) $(LIBLINK)
83+
84+
.PHONY: uninstall uninstall-scripts uninstall-headers uninstall-library
85+
uninstall: uninstall-scripts uninstall-headers uninstall-library
86+
uninstall-scripts:
87+
-$(RM) -r $(foreach f,$(SCRIPTS),$(DESTBINDIR)/$(f))
88+
uninstall-headers:
89+
-$(RM) -r $(foreach f,$(SOURCE_H),$(DESTINCDIR)/$(f))
90+
uninstall-library:
91+
-$(RM) $(DESTLIBDIR)/$(LIBFILE)
92+
-$(RM) $(DESTLIBDIR)/$(LIBLINK)
93+
94+
.PHONY: clean
395
clean:
4-
$(MAKE) -C lib $@
96+
-$(RM) -r build install bin include lib lib64

build-cmake.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
set -eu
3+
cmake -B build -DCMAKE_INSTALL_PREFIX="${PREFIX:-$PWD}"
4+
cmake --build build
5+
cmake --install build
6+
(test -d lib64 && ln -f -s lib64 lib) || true

build-meson.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
set -eu
3+
meson setup build --prefix="${PREFIX:-$PWD}"
4+
meson compile -C build
5+
meson install -C build
6+
(test -d lib64 && ln -f -s lib64 lib) || true

clean.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
rm -fr build install bin include lib lib64

lib/Makefile

Lines changed: 0 additions & 21 deletions
This file was deleted.

meson.build

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
project(
2+
'mpi-stubs',
3+
'c',
4+
version: '4.2',
5+
license: 'MIT',
6+
meson_version: '>=1.0.0',
7+
)
8+
9+
fs = import('fs')
10+
prefix = get_option('prefix')
11+
bindir = get_option('bindir')
12+
includedir = get_option('includedir')
13+
libdir = get_option('libdir')
14+
prog_dirs = {
15+
'includedir':
16+
fs.is_absolute(includedir) ?
17+
includedir : prefix / includedir,
18+
'libdir':
19+
fs.is_absolute(libdir) ?
20+
libdir : prefix / libdir,
21+
}
22+
prog_vars = {
23+
'mpicc': {
24+
'CC': 'CC',
25+
'cc': 'cc',
26+
'op': 'cc',
27+
},
28+
'mpicxx': {
29+
'CC': 'CXX',
30+
'cc': 'c++',
31+
'op': 'cxx',
32+
},
33+
}
34+
foreach prog: ['mpicc', 'mpicxx']
35+
configure_file(
36+
input: 'mpicc.in',
37+
configuration: prog_dirs + prog_vars[prog],
38+
output: prog,
39+
install: true,
40+
install_dir: bindir,
41+
install_mode: 'rwxr-xr-x',
42+
)
43+
endforeach
44+
45+
install_headers(
46+
'mpi.h'
47+
)
48+
49+
library(
50+
'mpi_abi',
51+
'mpistubs.c',
52+
version: '0',
53+
install : true,
54+
)

include/mpi.h renamed to mpi.h

File renamed without changes.

mpicc.in

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
# install-dirs
4+
includedir="@includedir@"
5+
libdir="@libdir@"
6+
7+
@CC@=@cc@
8+
if [[ -n "$MPI_@CC@" ]]; then
9+
# shellcheck disable=SC2034
10+
MPI_@CC@_OLD="$@CC@"
11+
@CC@="$MPI_@CC@"
12+
fi
13+
14+
Exec="exec"
15+
mode="link"
16+
arglist=("$@")
17+
argindex=0
18+
for arg in "$@" ; do
19+
addarg=no
20+
case "$arg" in
21+
-c|-S|-E|-M|-MM)
22+
mode="compile"
23+
addarg=yes
24+
;;
25+
-@op@=*)
26+
@CC@="${arg#*=}"
27+
;;
28+
-show|-showme)
29+
Exec="echo"
30+
;;
31+
-show-compile-info|-showme:compile)
32+
mode="show-compile"
33+
;;
34+
-show-link-info|-showme:link)
35+
mode="show-link"
36+
;;
37+
-show-incdir|-showme:incdir)
38+
mode="show-incdir"
39+
;;
40+
-show-libdir|-showme:libdir)
41+
mode="show-libdir"
42+
;;
43+
-show-libs|-showme:libs)
44+
mode="show-libs"
45+
;;
46+
*)
47+
addarg=yes
48+
;;
49+
esac
50+
if [[ "$addarg" = "no" ]]; then
51+
unset 'arglist[$argindex]'
52+
fi
53+
argindex=$((argindex + 1))
54+
unset addarg
55+
done
56+
unset argindex
57+
58+
if [[ $# -eq 0 ]]; then
59+
printf "%s: command line argument is required\n" "$0"
60+
"$@CC@" --help
61+
exit 1
62+
fi
63+
if [[ "@${arglist[*]}" = "@-v" ]]; then
64+
mode=""
65+
fi
66+
67+
if [[ "$mode" = "compile" ]]; then
68+
$Exec "${@CC@}" "${arglist[@]}" -I"${includedir}"
69+
elif [[ "$mode" = "link" ]]; then
70+
$Exec "${@CC@}" "${arglist[@]}" -I"${includedir}" -L"${libdir}" -lmpi_abi
71+
elif [[ "$mode" = "" ]]; then
72+
$Exec "${@CC@}" "${arglist[@]}"
73+
else
74+
case "$mode" in
75+
show-compile) printf -- "-I%s\n" "${includedir}";;
76+
show-link) printf -- "-L%s -l%s\n" "${libdir}" mpi_abi;;
77+
show-incdir) printf -- "%s\n" "${includedir}";;
78+
show-libdir) printf -- "%s\n" "${libdir}";;
79+
show-libs) printf -- "%s\n" mpi_abi;;
80+
esac
81+
fi

0 commit comments

Comments
 (0)