3 # Copyright (c) 2012-2022. The SimGrid Team. All rights reserved.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the license (GNU LGPL) which comes with this package.
8 SIMGRID_VERSION="@SIMGRID_VERSION_STRING@"
9 SIMGRID_GITHASH="@GIT_VERSION@"
11 REAL_FORTRAN_COMPILER=@SMPI_Fortran_COMPILER@
15 list_set INCLUDEARGS @includeflag@
16 list_set CMAKE_LINKARGS "-L@libdir@"
18 list_set FFLAGS @SMPI_Fortran_FLAGS@
19 list_set LINKARGS "-lsimgrid" @SMPI_Fortran_LIBS@ "-lm"
20 if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
21 list_add LINKARGS "-shared"
22 if [ "x${SMPI_NO_UNDEFINED_CHECK}" = "x" ]; then
23 if [ "x@APPLE@" != "x1" ]; then
24 list_add LINKARGS "-Wl,-z,defs"
26 list_add LINKARGS "-Wl,-undefined,error"
30 echo "Warning: smpiff pretends to be a regular compiler (SMPI_PRETEND_CC is set). Produced binaries will not be usable in SimGrid."
35 eval $(list_get TMPFILES)
40 filter_and_compile_f77() {
41 if [ "x${SMPI_PRETEND_CC}" = "x" ] && [ "x${TMPFILE}" != "x" ]; then
42 list_add TMPFILES "${TMPFILE}"
43 #replace "program main_name by subroutine user_main (and the end clause as well)"
44 if [ "$TRACE_CALL_LOCATION" -gt 0 ]; then
45 echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > "${TMPFILE}"
46 echo "#line 1 \"${ARG}\"" >> "${TMPFILE}"
48 sed 's/^[[:space:]]\{6\}[[:space:]]*\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][^a-zA-Z0-9]*\([a-zA-Z0-9_]*\)/ \1subroutine user_main /g' "${ARG}" >> "${TMPFILE}"
53 list_add CMDLINE "${SRCFILE}"
55 filter_and_compile_f90() {
56 if [ "x${SMPI_PRETEND_CC}" = "x" ] && [ "x${TMPFILE}" != "x" ]; then
57 list_add TMPFILES "${TMPFILE}"
58 #replace "program main_name by subroutine user_main (and the end clause as well)"
59 if [ "$TRACE_CALL_LOCATION" -gt 0 ]; then
60 echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > "${TMPFILE}"
61 echo "#line 1 \"${ARG}\"" >> "${TMPFILE}"
63 sed 's/^\([[:space:]]*\)\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][^a-zA-Z0-9]*\([a-zA-Z0-9_]*\)/\1\2subroutine user_main /g' "${ARG}" >> "${TMPFILE}"
68 list_add CMDLINE "${SRCFILE}"
73 list_set CMDLINE "${REAL_FORTRAN_COMPILER}"
74 list_add_not_empty CMDLINE "${FFLAGS}"
75 while [ $# -gt 0 ]; do
85 FILENAME=$(basename "${ARG}")
86 if [ "$TRACE_CALL_LOCATION" -gt 0 ] || main=$(grep -q -i "program" "${ARG}"); then
87 TMPFILE=$(mymktemp "${ARG}" ".f")
89 ORIGFILE="${FILENAME%.f}"
90 filter_and_compile_f77
93 FILENAME=$(basename "${ARG}")
94 if [ "$TRACE_CALL_LOCATION" -gt 0 ] || main=$(grep -q -i "program" "${ARG}"); then
95 TMPFILE=$(mymktemp "${ARG}" ".F")
97 ORIGFILE="${FILENAME%.F}"
98 filter_and_compile_f77
101 FILENAME=$(basename "${ARG}")
102 if [ "$TRACE_CALL_LOCATION" -gt 0 ] || main=$(grep -q -i "program" "${ARG}"); then
103 TMPFILE=$(mymktemp "${ARG}" ".f90")
105 ORIGFILE="${FILENAME%.f90}"
106 filter_and_compile_f90
109 FILENAME=$(basename "${ARG}")
110 if [ "$TRACE_CALL_LOCATION" -gt 0 ] || main=$(grep -q -i "program" "${ARG}"); then
111 TMPFILE=$(mymktemp "${ARG}" ".F90")
113 ORIGFILE="${FILENAME%.F90}"
114 filter_and_compile_f90
116 '-version' | '--version')
117 printf '%b\n' "$SIMGRID_VERSION"
120 "-git-version" | "--git-version")
121 printf '%b\n' "$SIMGRID_GITHASH"
124 '-compiler-version' | '--compiler-version')
125 ${REAL_FORTRAN_COMPILER} --version
127 '-trace-call-location')
128 TRACE_CALL_LOCATION=1
129 # This should be list_add FFLAGS but it's not possible
130 # anymore: FFLAGS was already moved into CMDLINE above.
131 list_add_not_empty CMDLINE "-ffixed-line-length-none" "-cpp"
134 list_add CMDLINE "-o$1"
138 '-show'|'-compile-info'|'-link-info')
139 # Dry run displaying commands instead of executing them. Useful to cmake
143 list_add CMDLINE "${ARG}"
148 if [ $NEEDS_OUTPUT -ne 0 ]; then
149 list_add CMDLINE "-o${ORIGFILE}.o"
152 list_add_not_empty CMDLINE "${INCLUDEARGS}"
153 list_add_not_empty CMDLINE "${CMAKE_LINKARGS}"
154 list_add_not_empty CMDLINE "${LINKARGS}"
156 eval $(list_get CMDLINE)
157 if [ "x$VERBOSE" = x1 ] || [ "x$show" = x1 ] ; then
159 [ "x$show" = x1 ] && exit 0