1#-----------------------------------------------------------------------------
2# GNU makefile for building the WCSLIB 7.7 FORTRAN wrappers.
3#
4# Summary of the main targets
5# ---------------------------
6#   build:     Build the library
7#
8#   clean:     Delete intermediate object files.
9#
10#   cleaner:   clean, and also delete the test executables.
11#
12#   cleanest (distclean, or realclean): cleaner, and also delete the
13#              object library.
14#
15#   check (or test): Compile and run the test programs.  By default they are
16#              executed in batch mode, and non-graphical tests only report
17#              "PASS" on success.  Use
18#
19#                make MODE=interactive check
20#
21#              to run them interactively with full diagnostic output.  To skip
22#              graphical tests even if PGPLOT is available, use
23#
24#                make CHECK=nopgplot check
25#
26#   tests:     Compile the test programs (but don't run them).
27#
28# Notes:
29#   1) If you need to make changes then preferably modify ../makedefs.in
30#      instead and re-run configure.
31#
32#   2) This makefile assumes that the WCSLIB 7.7 sources reside in ../C
33#      (as in the distribution kit).
34#
35#   3) twcstab assumes that ../C/wcstab.fits has already been generated by
36#      the corresponding C test program.
37#
38# Author: Mark Calabretta, Australia Telescope National Facility, CSIRO.
39# http://www.atnf.csiro.au/people/Mark.Calabretta
40# $Id: GNUmakefile,v 7.7 2021/07/12 06:36:49 mcalabre Exp $
41#-----------------------------------------------------------------------------
42# Get configure settings.
43SUBDIR := Fortran
44include ../makedefs
45
46MODULES := $(sort $(patsubst %.c,%.o,$(wildcard *.c)))
47MODULES += $(sort $(patsubst %.f,%.o,$(wildcard *.f)))
48
49# Including getwcstab_f.c causes the sharable library to depend on CFITSIO.
50MODULES := $(filter-out getwcstab_f.o,$(MODULES))
51
52ifdef GETWCSTAB
53  FGETWCSTAB := ../C/getwcstab.o
54endif
55
56WCSLIB  := ../C/$(WCSLIB)
57LIBLOCK := ../C/lib.lock
58
59# Build the sharable library?
60ifneq "$(SHRLIB)" ""
61  PICLIB := ../C/libwcs-PIC.a
62  SHRLIB := ../C/$(SHRLIB)
63endif
64
65CPPFLAGS += -I.. -I../C
66
67vpath %.h  ..:../C
68vpath %.in ..
69
70
71# For building and exercising the test suite
72# ------------------------------------------
73# Test programs that don't require CFITSIO or PGPLOT.
74TEST_N := tlin tdis1 tdis2 tlog tprj1 tsph tspx ttab1 twcs twcssub tpih1 \
75          tfitshdr tunits twcsfix
76
77# Test programs that require CFITSIO (they don't need PGPLOT).
78TEST_C := twcstab
79
80# Test programs that require PGPLOT but not PGSBOX.
81TEST_P := tspc tprj2 tcel1 ttab2 ttab3 twcsmix
82
83# Test programs that require PGPLOT and PGSBOX.
84TEST_B := tpih2
85
86TESTS  := $(TEST_N)
87
88# Do we have CFITSIO?
89DO_CFITSIO := 1
90ifeq "$(CFITSIOLIB)" ""
91  DO_CFITSIO := 0
92endif
93
94ifeq "$(DO_CFITSIO)" "1"
95  # Yes, add test programs that use it.
96  TESTS += $(TEST_C)
97  CFITSIO_CFLAGS := $(filter-out -Wpadded,$(CFLAGS))
98endif
99
100# Do we have PGPLOT?
101DO_PGPLOT := 0
102ifneq "$(CHECK)" "nopgplot"
103  DO_PGPLOT := 1
104  ifeq "$(PGPLOTLIB)" ""
105    DO_PGPLOT := 0
106  endif
107
108  ifeq "$(DO_PGPLOT)" "1"
109    # Yes, add test programs that use it.
110    TESTS += $(TEST_P) $(TEST_B)
111  endif
112endif
113
114PGSBOXLIB := ../pgsbox/libpgsbox-$(LIBVER).a
115PGPLOTLIB := $(PGPLOTLIB)
116
117
118# Pattern rules
119#--------------
120
121$(WCSLIB)(%.o) : %.c
122	-@ echo ''
123	   $(CC) $(CPPFLAGS) $(CFLAGS) -c $<
124	 @ if [ ! -f $(LIBLOCK) ] ; then \
125	     echo $(AR) r$(ARFLAGS) $(WCSLIB) $% ; \
126	     $(AR) r$(ARFLAGS) $(WCSLIB) $% ; \
127	     $(RM) $% ; \
128	   fi
129
130$(WCSLIB)(%.o) : %.f
131	-@ echo ''
132	   $(FC) $(FFLAGS) -c $<
133	 @ if [ ! -f $(LIBLOCK) ] ; then \
134	     echo $(AR) r$(ARFLAGS) $(WCSLIB) $% ; \
135	     $(AR) r$(ARFLAGS) $(WCSLIB) $% ; \
136	     $(RM) $% ; \
137	   fi
138
139$(PICLIB)(%_f.o) : $(WCSLIB)(%_f.o)
140	-@ echo ''
141	   $(CC) $(CPPFLAGS) $(CFLAGS) $(SHRFLAGS) -c $(%:.o=.c)
142	 @ if [ ! -f $(LIBLOCK) ] ; then \
143	     echo $(AR) r$(ARFLAGS) $(PICLIB) $% ; \
144	     $(AR) r$(ARFLAGS) $(PICLIB) $% ; \
145	     $(RM) $% ; \
146	   fi
147
148$(PICLIB)(%_data.o) : $(WCSLIB)(%_data.o)
149	-@ echo ''
150	   $(FC) $(FFLAGS) $(SHRFLAGS) -c $(%:.o=.f)
151	 @ if [ ! -f $(LIBLOCK) ] ; then \
152	     echo $(AR) r$(ARFLAGS) $(PICLIB) $% ; \
153	     $(AR) r$(ARFLAGS) $(PICLIB) $% ; \
154	     $(RM) $% ; \
155	   fi
156
157%.i : %.c
158	-@ echo ''
159	-@ $(RM) $@
160	   $(CPP) $(CPPFLAGS) $(CFLAGS) $< > $@
161
162# Print out include file dependencies.
163%.d : %.c
164	-@ echo ''
165	-@ $(CPP) $(CPPFLAGS) $(CFLAGS) $< | \
166	   sed -n -e 's|^# 1 "\([^/].*\.h\)".*|\1|p' | \
167	   sed -e 's|.*/||' | \
168	   sort -u
169
170%.o : %.f
171	-@ echo ''
172	   $(FC) $(FFLAGS) -c $<
173
174%.fits : ../C/test/%.keyrec tofits
175	   ./tofits < $< > $@
176
177run_% : %
178	-@ echo ''
179	-@ $(TIMER)
180	 @ if [ '$(MODE)' = interactive -o '$(VALGRIND)' ] ; then \
181	     printf 'Press <CR> to run $<: ' ; \
182	     read DUMMY ; \
183	   fi ; \
184	   if [ '$(VALGRIND)' ] ; then \
185	     if [ '$<' = tunits ] ; then \
186	       $(VALGRIND) ./$< < test/units_test ; \
187	     else \
188	       $(VALGRIND) ./$< ; \
189	     fi ; \
190	   else \
191	     if [ '$(filter $<, $(TEST_N) $(TEST_C))' ] ; then \
192	       if [ '$<' = tunits ] ; then \
193	         if [ '$(MODE)' = interactive ] ; then \
194	           ./$< < ../C/test/units_test 2>&1 | tee $<.out ; \
195	         else \
196	           ./$< < ../C/test/units_test > $<.out 2>&1 ; \
197	         fi ; \
198	       else \
199	         if [ '$(MODE)' = interactive ] ; then \
200	           ./$< < /dev/null 2>&1 | tee $<.out ; \
201	         else \
202	           ./$< < /dev/null > $<.out 2>&1 ; \
203	         fi ; \
204	       fi ; \
205	       if grep 'FAIL:' $<.out > /dev/null ; then \
206	         if [ '$(MODE)' != interactive ] ; then \
207	           head -2 $<.out ; \
208	           grep 'FAIL:' $<.out ; \
209	         fi ; \
210	         echo 'FAIL: Fortran/$<' >> test_results ; \
211	       elif grep 'PASS:' $<.out > /dev/null ; then \
212	         if [ '$(MODE)' != interactive ] ; then \
213	           head -2 $<.out ; \
214	           grep 'PASS:' $<.out ; \
215	         fi ; \
216	         echo 'PASS: Fortran/$<' >> test_results ; \
217	       elif [ -f 'test/$<.out' ] ; then \
218	         trap 'rm -f run_$<.tmp' 0 1 2 3 15 ; \
219	         sed -e 's/0x[0-9a-f][0-9a-f][0-9a-f]*/0x<address>/g' $<.out > \
220	           run_$<.tmp ; \
221	         mv -f run_$<.tmp $<.out ; \
222	         if cmp -s $<.out test/$<.out ; then \
223	           if [ '$(MODE)' != interactive ] ; then \
224	             head -2 $<.out ; \
225	             echo 'PASS: Output agrees with Fortran/test/$<.out' ; \
226	           fi ; \
227	           echo 'PASS: Fortran/$<' >> test_results ; \
228	         else \
229	           if [ '$(MODE)' != interactive ] ; then \
230	             cat $<.out ; \
231	           fi ; \
232	           echo '' ; \
233	           echo 'FAIL: Output disagrees with Fortran/test/$<.out' ; \
234	           echo 'FAIL: Fortran/$<' >> test_results ; \
235	         fi ; \
236	       elif [ '$(MODE)' != interactive ] ; then \
237	         cat $<.out ; \
238	         echo 'FAIL: Fortran/$<' >> test_results ; \
239	       fi ; \
240	     elif [ '$(MODE)' = interactive ] ; then \
241	       ./$< ; \
242	     else \
243	       if [ '$<' = tcel2 ] ; then \
244	         echo N | ./$< ; \
245	       else \
246	         yes | ./$< 2>&1 ; \
247	       fi ; \
248	     fi ; \
249	   fi
250	-@ echo ''
251
252# Static and static pattern rules
253#--------------------------------
254
255.PHONY : build check clean cleaner cleanest distclean install lib realclean \
256         test tests uninstall
257
258build : lib
259
260lib :
261	 @ $(MAKE) -C ../C lib
262	-@ echo ''
263	-@ echo 'Building WCSLIB Fortran wrappers...'
264	 @ $(MAKE) --no-print-directory $(WCSLIB)
265
266$(WCSLIB) : $(LIBLOCK) $(MODULES:%=$(WCSLIB)(%))
267	-@ echo ''
268	 @ set *.o ; \
269	     if [ "$$1" != "*.o" ] ; then \
270	       echo $(AR) r$(ARFLAGS) $@ *.o ; \
271	       $(AR) r$(ARFLAGS) $@ *.o ; \
272	       echo $(RANLIB) $@ ; \
273	       $(RANLIB) $@ ; \
274	       $(RM) *.o ; \
275	     fi
276	-@ $(RM) $<
277	 @ if [ "$(SHRLIB)" != "" ] ; then \
278	     $(MAKE) --no-print-directory $(SHRLIB) ; \
279	   fi
280
281$(SHRLIB) : $(PICLIB)
282	-@ echo ''
283	-@ $(RM) -r tmp
284	   mkdir tmp && \
285	     cd tmp && \
286	     trap 'cd .. ; $(RM) -r tmp' 0 1 2 3 15 ; \
287	     $(AR) x ../$(PICLIB) && \
288	     $(SHRLD) -o $(@F) *.o $(LDFLAGS) $(LIBS) && \
289	     mv $(@F) ../../C
290
291$(PICLIB) : $(LIBLOCK) $(MODULES:%.o=$(PICLIB)(%.o))
292	-@ echo ''
293	 @ set *.o ; \
294	     if [ "$$1" != "*.o" ] ; then \
295	       echo $(AR) r$(ARFLAGS) $@ *.o ; \
296	       $(AR) r$(ARFLAGS) $@ *.o ; \
297	       $(RM) *.o ; \
298	     fi
299	-@ $(RM) $<
300
301$(LIBLOCK) : FORCE
302	 @ $(RM) *.o
303	 @ touch $@
304
305install : build
306	$(MAKE) -C ../C install
307	$(INSTALL) -m 444 *.inc $(INCDIR)
308
309uninstall :
310	$(MAKE) -C ../C uninstall
311
312clean :
313	-  $(RM) *.o $(LIBLOCK) *.i a.out t*.out core fort.* *.dSYM
314	-  $(RM) -r $(EXTRA_CLEAN)
315
316cleaner : clean
317	-  $(RM) .gdb_history
318	-  $(RM) $(TEST_N)
319	-  $(RM) $(TEST_P) tpih2 twcstab
320	-  $(RM) tofits fitshdr.fits pih.fits TPV7.fits test_results
321
322cleanest distclean realclean : cleaner
323	-  $(RM) $(WCSLIB) $(PICLIB) $(SHRLIB)
324
325check test : tests $(TESTS:%=run_%)
326
327tests : $(TESTS)
328
329$(TEST_N) : % : test/%.f $(WCSLIB)
330	-@ echo ''
331	   $(FC) $(FFLAGS) -o $@ $< $(LDFLAGS) $(WCSLIB) $(LIBS)
332	-@ $(RM) $@.o
333
334$(TEST_P) : % : test/%.f $(WCSLIB)
335	-@ echo ''
336	   $(FC) $(FFLAGS) -o $@ $< $(LDFLAGS) $(WCSLIB) $(PGPLOTLIB) $(LIBS)
337	-@ $(RM) $@.o
338
339tpih2 : % : test/%.f $(PGSBOXLIB) $(WCSLIB)
340	-@ echo ''
341	   $(FC) $(FFLAGS) -o $@ $< $(LDFLAGS) $(PGSBOXLIB) $(WCSLIB) \
342	     $(PGPLOTLIB) $(LIBS)
343	-@ $(RM) $@.o
344
345twcstab : test/twcstab.f getwcstab_f.o getwcstab.inc $(FGETWCSTAB) \
346    $(WCSLIB)
347	-@ echo ''
348	   $(FC) $(FFLAGS) -o $@ $< getwcstab_f.o $(FGETWCSTAB) \
349	     $(LDFLAGS) $(CFITSIOLIB) $(WCSLIB) $(LIBS)
350	-@ $(RM) $@.o $(FGETWCSTAB)
351
352getwcstab_f.o : getwcstab_f.c getwcstab.h
353	-@ echo ''
354	   $(CC) $(CPPFLAGS) $(CFITSIO_CFLAGS) $(CFITSIOINC) -c $<
355
356../C/getwcstab.o ::
357	-@ echo ''
358	   $(MAKE) -C ../C getwcstab.o
359
360$(PGSBOXLIB) :
361	-@ echo ''
362	   $(MAKE) -C ../pgsbox lib
363
364tofits : ../C/test/tofits.c
365	   $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $<
366
367../C/wcstab.fits : ;
368
369GNUmakefile : ../makedefs ;
370
371../makedefs ../wcsconfig.h ../wcsconfig_f77.h : makedefs.in wcsconfig.h.in \
372    wcsconfig_f77.h.in ../config.status
373	-@ $(RM) ../wcsconfig.h ../wcsconfig_f77.h
374	   cd .. && ./config.status
375
376show ::
377	-@ echo '  MODULES     := $(MODULES)'
378	-@ echo '  DO_CFITSIO  := $(DO_CFITSIO)'
379	-@ echo '  DO_PGPLOT   := $(DO_PGPLOT)'
380	-@ echo '  TESTS       := $(TESTS)'
381
382# Dependencies (use the %.d pattern rule to list them)
383#-----------------------------------------------------
384
385$(WCSLIB)(cel_f.o)      : cel.h prj.h wcsconfig_f77.h wcserr.h wcsutil.h
386$(WCSLIB)(dis_f.o)      : dis.h wcsconfig_f77.h wcserr.h wcsutil.h
387$(WCSLIB)(fitshdr_f.o)  : fitshdr.h wcsconfig.h wcsconfig_f77.h wcsutil.h
388$(WCSLIB)(getwcstab_f.o): getwcstab.h wcsconfig_f77.h
389$(WCSLIB)(lin_f.o)      : dis.h lin.h wcsconfig_f77.h wcserr.h wcsutil.h
390$(WCSLIB)(log_f.o)      : log.h wcsconfig_f77.h
391$(WCSLIB)(prj_f.o)      : prj.h wcsconfig_f77.h wcserr.h wcsutil.h
392$(WCSLIB)(spc_f.o)      : spc.h spx.h wcsconfig_f77.h wcserr.h wcsutil.h
393$(WCSLIB)(sph_f.o)      : sph.h wcsconfig_f77.h
394$(WCSLIB)(spx_f.o)      : spx.h wcsconfig_f77.h wcserr.h
395$(WCSLIB)(tab_f.o)      : tab.h wcsconfig_f77.h wcserr.h wcsutil.h
396$(WCSLIB)(wcs_f.o)      : cel.h lin.h prj.h spc.h spx.h wcs.h \
397                          wcsconfig_f77.h wcserr.h wcsutil.h
398$(WCSLIB)(wcsfix_f.o)   : cel.h lin.h prj.h spc.h spx.h wcs.h \
399                          wcsconfig_f77.h wcserr.h wcsfix.h
400$(WCSLIB)(wcshdr_f.o)   : cel.h lin.h prj.h spc.h spx.h wcs.h \
401                          wcsconfig_f77.h wcshdr.h
402$(WCSLIB)(wcsunits_f.o) : wcsconfig_f77.h wcserr.h wcsunits.h wcsutil.h
403
404tcel1   : cel.inc prj.inc
405tdis1   : lin.inc wcs.inc wcserr.inc wcshdr.inc
406tdis2   : dis.inc lin.inc wcs.inc wcserr.inc wcshdr.inc
407tfitshdr: fitshdr.inc wcshdr.inc
408tlin    : lin.inc
409tlog    : log.inc
410tpih1   : wcs.inc wcsfix.inc wcshdr.inc
411tpih2   : wcs.inc wcshdr.inc
412tprj1   : prj.inc
413tprj2   : prj.inc
414tspc    : spc.inc spx.inc
415tspx    : spx.inc
416ttab1   : tab.inc
417ttab2   : tab.inc
418ttab3   : prj.inc tab.inc
419tunits  : wcsunits.inc
420twcs    : cel.inc prj.inc wcs.inc wcserr.inc wcsmath.inc
421twcsfix : wcs.inc wcsfix.inc wcsunits.inc
422twcsmix : cel.inc lin.inc prj.inc wcs.inc
423twcssub : wcs.inc wcserr.inc
424twcstab : getwcstab.inc wcs.inc wcsfix.inc wcshdr.inc
425
426run_tdis1 run_tdis2 : TPV7.fits
427run_tfitshdr : fitshdr.fits
428run_tpih1 run_tpih2: pih.fits
429run_twcstab: ../C/wcstab.fits
430