Skip to content

Commit

Permalink
Fetch DANTON_PREFIX from env
Browse files Browse the repository at this point in the history
  • Loading branch information
niess committed Nov 5, 2021
1 parent 08df122 commit 7d0ceed
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 59 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@
[submodule "turtle"]
path = deps/turtle
url = https://github.com/niess/turtle
[submodule "whereami"]
path = deps/whereami
url = https://github.com/gpakosz/whereami.git
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ DANTON_GEOID= share/$(NAME)/geoid/egm96.png
DANTON_MDF= share/$(NAME)/materials/materials.xml
DANTON_PDF= share/$(NAME)/pdf/CT14nlo_0000.dat

# Compiler flags
CFLAGS= -O3 -Wall
# Compiler options
CC=gcc
FC=gcc
CFLAGS= -O3 -Wall -std=c99
FFLAGS= -O3 -fno-second-underscore -fno-backslash -fno-automatic \
-ffixed-line-length-132 -std=legacy

# OSX additional flags
# OS dependent flags
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SOEXT= dylib
Expand All @@ -24,6 +26,8 @@ else
SOEXT= so
SHARED= -shared
RPATH= '-Wl,-rpath,$$ORIGIN/../lib'

TINYDIR_CFLAGS= -Wno-restrict
endif

BINDIR= $(PREFIX)/bin
Expand All @@ -48,8 +52,8 @@ lib: $(LIB)

# Build the danton executable
EXE_INCLUDES= -Iinclude -Ideps/jsmn-tea/include -Ideps/roar/include \
-Ideps/turtle/src/deps -Ideps/whereami/src
EXE_SRCS= src/danton-x.c deps/whereami/src/whereami.c
-Ideps/turtle/src/deps
EXE_SRCS= src/danton-x.c

$(EXEC): $(EXE_SRCS) $(LIB)
@mkdir -p $(BINDIR)
Expand All @@ -73,6 +77,7 @@ LIB_OBJS += $(addprefix build/, \
png16.lo)

$(LIB): $(LIB_OBJS)
@mkdir -p $(LIBDIR)
@$(CC) -o $@ $(CFLAGS) $(SHARED) $(LIB_OBJS) -lm -ldl

LIB_INCLUDES= -Iinclude -Ideps/ent/include -Ideps/pumas/include \
Expand Down Expand Up @@ -119,8 +124,8 @@ build/%.lo: deps/ent/src/%.c
# Build JSMN-TEA
build/%.lo: deps/jsmn-tea/src/%.c deps/jsmn-tea/include/%.h
@$(call build_c,-Ideps/jsmn-tea/include -Ideps/turtle/src/deps \
-Ideps/roar/include -DROAR_IMPLEMENTATION)
-Ideps/roar/include -DROAR_IMPLEMENTATION)

# Build PUMAS
build/%.lo: deps/pumas/src/%.c
@$(call build_c,-Ideps/pumas/include)
Expand All @@ -139,4 +144,5 @@ build/%.lo: deps/turtle/src/%.c deps/turtle/include/%.h
@$(call build_c,-Ideps/turtle/include -Ideps/turtle/src)

build/%.lo: deps/turtle/src/deps/%.c deps/turtle/src/deps/%.h
@$(call build_c,-Ideps/turtle/include -Ideps/turtle/src)
@$(call build_c,-Ideps/turtle/include -Ideps/turtle/src \
$(TINYDIR_CFLAGS))
1 change: 0 additions & 1 deletion deps/whereami
Submodule whereami deleted from f15606
42 changes: 42 additions & 0 deletions dist/linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#! /bin/bash

# Generate the binaries
SCRIPT=$(cat <<-END
echo "building danton with \$(gcc --version | head -n 1)"
cd /work
make PREFIX=AppDir
chown --recursive $(id -u):$(id -g) AppDir build
END
)

mkdir -p AppDir
make clean
docker run --mount type=bind,source=$(pwd),target=/work \
quay.io/pypa/manylinux1_x86_64 /bin/bash -c "${SCRIPT}"

# Copy extra application data
mkdir -p AppDir/share
cp -rL share/danton AppDir/share
cp -rL include AppDir

# Force the generation of the materials dump
./AppDir/bin/danton examples/cards/backward-tau-decays.json > /dev/null
rm -f steps.json

# Bundle AppImage meta and entry point
cat << END > AppDir/danton.desktop
[Desktop Entry]
Type=Application
Name=danton
Exec=danton
Comment=Simulate the coupled transport of ultra high energy taus and neutrinos through the Earth, by Monte-Carlo
Icon=danton
Categories=Science;
Terminal=true
END

cat << END > AppDir/AppRun
#! /bin/bash
DANTON_PREFIX=\$APPDIR \$APPDIR/bin/danton \$*
END
chmod u+x AppDir/AppRun
48 changes: 1 addition & 47 deletions src/danton-x.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
/* Jasmine with some tea, for parsing the data card in JSON format. */
#include "jsmn-tea.h"

/* The whereami library, for getting the runtime prefix. */
#include "whereami.h"

/* Handle for the simulation context. */
static struct danton_context * context = NULL;

Expand Down Expand Up @@ -527,48 +524,6 @@ static int dump_steps(struct danton_context * context,
return EXIT_SUCCESS;
}

static char * get_prefix(void)
{
/* Get the runtime path using whereami. */
char * prefix = NULL;
const int length = wai_getExecutablePath(NULL, 0, NULL);
if (length < 0) goto error;

size_t size = (length > 4) ? length + 1 : 5;
prefix = malloc(size);
if (prefix == NULL) goto error;

wai_getExecutablePath(prefix, length, NULL);
prefix[length] = 0x0;

/* Get the runtime directory name. */
char * end = strrchr(prefix, '/');
if (end == NULL) {
/* A relative path is returned and the executable is called from
* within the same directory. Since an absolute path is
* returned, this is not expected to happen. But to be safe let
* us handle this case anyway.
*/
memcpy(prefix, "./..", 5);
return prefix;
} else {
*end = 0x0;
}

/* Get the directory above, i.e. the actual prefix since the runtime
* is expected to be located under bin.
*/
end = strrchr(prefix, '/');
if (end == NULL) goto error;
*end = 0x0;

return prefix;
error:
free(prefix);
fprintf(stderr, "error: could not resolve the runtime prefix\n");
exit(EXIT_FAILURE);
}

int main(int argc, char * argv[])
{
/* Configure the error handler. */
Expand All @@ -582,9 +537,8 @@ int main(int argc, char * argv[])
if (argc <= 1) exit_with_help(EXIT_SUCCESS);

/* Initialise DANTON. */
char * prefix = get_prefix();
char * prefix = getenv("DANTON_PREFIX");
const int rc = danton_initialise(prefix, NULL, NULL);
free(prefix);
if (rc != EXIT_SUCCESS) {
ROAR_ERRWP_MESSAGE(&handler, &main, -1, "danton error",
danton_error_pop(NULL));
Expand Down

0 comments on commit 7d0ceed

Please sign in to comment.