1 |
cnh |
1.1 |
#! /usr/bin/env bash |
2 |
|
|
# |
3 |
|
|
# Cheap shell script for building makefile |
4 |
|
|
# Has various missing features |
5 |
|
|
# o can't cope with source files that have duplicate names but that |
6 |
|
|
# are in different libraries |
7 |
|
|
# o doesn't have any explicit concept of ordering |
8 |
|
|
# o needs to deal with .F, .F90 and .c suffixes |
9 |
|
|
# |
10 |
|
|
# Debug settings |
11 |
|
|
# set -uvx |
12 |
|
|
# |
13 |
|
|
if test -f makemake.header ; then |
14 |
|
|
cat makemake.header |
15 |
|
|
fi |
16 |
|
|
|
17 |
|
|
F90_SUFF=F90 |
18 |
|
|
OBJ_SUFF='o' |
19 |
|
|
MOD_SUFF='mod' |
20 |
|
|
F90C=gfortran |
21 |
|
|
F90C=ifort |
22 |
|
|
F90C_ARGS='-fixed -O0 -c -CB -g -o' |
23 |
|
|
F90C_ARGS='-fixed -O0 -c -g -o' |
24 |
|
|
LINK=gfortran |
25 |
|
|
LINK=ifort |
26 |
|
|
EXE=a.out |
27 |
|
|
EXE=dummy_f90_objects_target |
28 |
|
|
# |
29 |
|
|
dlist='.' |
30 |
|
|
command=`which $0` |
31 |
|
|
tdir=.`echo ${command} | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`.$$ |
32 |
|
|
echo "# Searching directories "${dlist} |
33 |
|
|
echo "# Using temporary directory "${tdir} |
34 |
|
|
|
35 |
|
|
echo ifndef F90C |
36 |
|
|
echo F90C=${F90C} |
37 |
|
|
echo endif |
38 |
|
|
|
39 |
|
|
echo F90C_ARGS=${F90C_ARGS} |
40 |
|
|
echo OBJ_SUFF=${OBJ_SUFF} |
41 |
|
|
echo MOD_SUFF=${MOD_SUFF} |
42 |
|
|
|
43 |
|
|
echo ifndef F90C |
44 |
|
|
echo LINK=${LINK} |
45 |
|
|
echo endif |
46 |
|
|
|
47 |
|
|
echo ifndef EXE |
48 |
|
|
echo EXE=${EXE} |
49 |
|
|
echo endif |
50 |
|
|
|
51 |
|
|
mkdir ${tdir} |
52 |
|
|
|
53 |
|
|
# Set the includes |
54 |
|
|
echo IDIR='\' |
55 |
|
|
for d in ${dlist} ; do |
56 |
|
|
dl=`find -L $d -type d -not -regex '.*\.svn.*' -not -regex '.*\CVS*'` |
57 |
|
|
for di in ${dl} ; do |
58 |
|
|
echo '-I'${di}' \' |
59 |
|
|
done |
60 |
|
|
done |
61 |
|
|
echo '$(EXTRA_IDIR)' |
62 |
|
|
|
63 |
|
|
# Executable links all the .o from ${dlist} except libs which are built |
64 |
|
|
# from each ../pkg subdirectory |
65 |
|
|
ol='' |
66 |
|
|
ll='' |
67 |
|
|
lo='' |
68 |
|
|
for d in ${dlist} ; do |
69 |
|
|
if test "${d##*/}" = "pkg" ; then |
70 |
|
|
# All these are treated as separate library sources |
71 |
|
|
dl=`find -L $d -type d -not -regex '.*\.svn.*' -not -regex '.*\CVS*'` |
72 |
|
|
for dd in ${dl} ; do |
73 |
|
|
if test "${dd##*/}" != "pkg" ; then |
74 |
|
|
echo '## Library name = 'lib${dd##*/}.a |
75 |
|
|
lfl=`find -L ${dd} -maxdepth 1 -type f -not -regex '.*\.svn.*' -not -regex '.*\CVS*'` |
76 |
|
|
echo '## Library files = '${lfl##*/} |
77 |
|
|
ll=${ll}' 'lib${dd##*/}.a |
78 |
|
|
lo=${lo}' '-l${dd##*/} |
79 |
|
|
fi |
80 |
|
|
done |
81 |
|
|
else |
82 |
|
|
# All others are .o |
83 |
|
|
fl=`find -L $d -name '*.'${F90_SUFF} -not -regex '.*\.svn.*' -not -regex '.*\CVS*'` |
84 |
|
|
for f in ${fl} ; do |
85 |
|
|
fn=${f##*/} |
86 |
|
|
of=${fn%.*}.${OBJ_SUFF} |
87 |
|
|
ol=${ol}' '${of} |
88 |
|
|
done |
89 |
|
|
fi |
90 |
|
|
done |
91 |
|
|
|
92 |
|
|
# Write objlist |
93 |
|
|
echo 'OBJLIST=\' |
94 |
|
|
for o in ${ol} ; do |
95 |
|
|
echo ${o}' \' |
96 |
|
|
done |
97 |
|
|
echo ' ' |
98 |
|
|
|
99 |
|
|
# Write library list |
100 |
|
|
echo 'LIBLIST=\' |
101 |
|
|
for l in ${ll} ; do |
102 |
|
|
echo ${l}' \' |
103 |
|
|
done |
104 |
|
|
echo '$(EXTRA_LIB_LIST)' |
105 |
|
|
echo ' ' |
106 |
|
|
|
107 |
|
|
# Write library option |
108 |
|
|
# write it twice because gnu linker doesn't search backwards and we don't know the |
109 |
|
|
# right order (I think this is what ar and ranlib are for!) |
110 |
|
|
echo 'LIBOPT=\' |
111 |
|
|
for l in ${lo} ; do |
112 |
|
|
echo ${l}' \' |
113 |
|
|
done |
114 |
|
|
for l in ${lo} ; do |
115 |
|
|
echo ${l}' \' |
116 |
|
|
done |
117 |
|
|
echo ' ' |
118 |
|
|
|
119 |
|
|
|
120 |
|
|
# Set rule for executable |
121 |
|
|
echo '$(EXE): $(OBJLIST) $(LIBLIST)' |
122 |
|
|
echo -e \\t'echo built $(OBJLIST)' |
123 |
|
|
echo -e \\t'touch $(EXE)' |
124 |
|
|
|
125 |
|
|
# Set rule for libraries |
126 |
|
|
ol='' |
127 |
|
|
ll='' |
128 |
|
|
for d in ${dlist} ; do |
129 |
|
|
if test "${d##*/}" = "pkg" ; then |
130 |
|
|
# All these are treated as separate library sources |
131 |
|
|
dl=`find -L $d -type d -not -regex '.*\.svn.*' -not -regex '.*\CVS*'` |
132 |
|
|
for dd in ${dl} ; do |
133 |
|
|
if test "${dd##*/}" != "pkg" ; then |
134 |
|
|
lfl=`find -L ${dd} -maxdepth 1 -type f -not -regex '.*/\.[a-zA-Z].*' -not -regex '.*\CVS*'` |
135 |
|
|
# lfl=`find -L ${dd} -maxdepth 1 -type f -not -regex '.*\.svn.*'` |
136 |
|
|
fo='' |
137 |
|
|
for ff in ${lfl}; do |
138 |
|
|
f=${ff##*/} |
139 |
|
|
fo=${fo}' '${f%%.${F90_SUFF}}.${OBJ_SUFF} |
140 |
|
|
done |
141 |
|
|
echo lib${dd##*/}.a:' '${fo} |
142 |
|
|
echo -e \\t'@touch 'lib${dd##*/}.a |
143 |
|
|
echo -e \\t'@rm 'lib${dd##*/}.a |
144 |
|
|
echo -e \\t'$(AR) -rus' lib${dd##*/}.a ${fo} |
145 |
|
|
fi |
146 |
|
|
echo ' ' |
147 |
|
|
done |
148 |
|
|
fi |
149 |
|
|
done |
150 |
|
|
|
151 |
|
|
# Set rule for individual object and module files |
152 |
|
|
for d in ${dlist} ; do |
153 |
|
|
fl=`find -L $d -name '*.'${F90_SUFF} -not -regex '.*\.svn.*' -not -regex '.*\CVS*'` |
154 |
|
|
for f in ${fl} ; do |
155 |
|
|
fonly=${f##*/} |
156 |
|
|
base=${fonly%.*} |
157 |
|
|
echo ${base}.${OBJ_SUFF}: $f |
158 |
|
|
echo -e \\t'$(F90C) $(IDIR) $(F90C_ARGS) $@ $<' |
159 |
|
|
echo ${base}.${MOD_SUFF}: $f |
160 |
|
|
echo -e \\t'$(F90C) $(IDIR) $(F90C_ARGS) '${base}.${OBJ_SUFF}' $<' |
161 |
|
|
done |
162 |
|
|
done |
163 |
|
|
|
164 |
|
|
# Add dependency rules for source that includes another module via a USE |
165 |
|
|
# statement |
166 |
|
|
for d in ${dlist} ; do |
167 |
|
|
fl=`find -L $d -name '*.'${F90_SUFF} -not -regex '.*\.svn.*' -not -regex '.*\CVS*'` |
168 |
|
|
for f in ${fl} ; do |
169 |
|
|
fonly=${f##*/} |
170 |
|
|
base=${fonly%.*} |
171 |
|
|
mlist=`grep -i '^ *use *' ${f} | awk '{print $2}'` |
172 |
|
|
for m in ${mlist} ; do |
173 |
|
|
# echo ${base}.'$(OBJ_SUFF)': $m.'$(OBJ_SUFF)' |
174 |
|
|
if test -f makemake.externals; then |
175 |
|
|
chkext=`grep -i '^'$m' *$' makemake.externals ` |
176 |
|
|
extyn=$? |
177 |
|
|
fi |
178 |
|
|
if test "$extyn" != "0" ; then |
179 |
|
|
echo ${base}.'$(OBJ_SUFF)': $m.'$(MOD_SUFF)' |
180 |
|
|
echo ${base}.'$(MOD_SUFF)': $m.'$(MOD_SUFF)' |
181 |
|
|
fi |
182 |
|
|
done |
183 |
|
|
done |
184 |
|
|
done |
185 |
|
|
|
186 |
|
|
\rm -fr ${tdir} |