|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# @file Makefile |
| 3 | +# @brief Makefile for Software/Config/Archon/Build/ |
| 4 | +# @author David Hale |
| 5 | +# @date 2015-xx-xx |
| 6 | +# @modified 2016-01-14 |
| 7 | +# @modified 2016-01-27 added fixrawendline (special case for Peter) |
| 8 | +# @modified 2016-01-28 removed clean. Use @F.h instead of HFILE=archon.h |
| 9 | +# @modified 2016-03-31 change how .mod is parsed |
| 10 | +# @modified 2016-04-04 add INCPARSER and checks for file existence |
| 11 | +# @modified 2016-04-07 add plotting option and check for WAVGEN exit code |
| 12 | +# @modified 2016-04-19 changes to implement INCLUDE_FILE= in *.conf |
| 13 | +# @modified 2016-04-20 read CDS_FILE and MODULE_FILE from .conf |
| 14 | +# @modified 2017-02-08 added modegen |
| 15 | +# @modified 2017-11-09 remove copying of acf files to camera computers |
| 16 | +# @modified 2020-12-21 added insert_hash |
| 17 | +# |
| 18 | +# This Makefile uses the general preprocessor GPP 2.24 for macro processing. |
| 19 | +# It also requires the ini2acf.pl Perl script for creating an Archon acf file. |
| 20 | +# |
| 21 | +# ----------------------------------------------------------------------------- |
| 22 | +# |
| 23 | + |
| 24 | +# Copyright (C) <2018> California Institute of Technology |
| 25 | +# Software written by: <Dave Hale and Peter Mao> |
| 26 | +# |
| 27 | +# This program is part of the Waveform Definition Language (WDL) developed |
| 28 | +# for ZTF. This program is free software: you can redistribute it and/or |
| 29 | +# modify it under the terms of the GNU General Public License as published |
| 30 | +# by the Free Software Foundation, either version 3 of the License, or |
| 31 | +# any later version. |
| 32 | +# |
| 33 | +# This program is distributed in the hope that it will be useful, |
| 34 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 35 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 36 | +# GNU General Public License for more details. |
| 37 | +# |
| 38 | +# Please see the GNU General Public License at: |
| 39 | +# <http://www.gnu.org/licenses/>. |
| 40 | +# |
| 41 | +# Report any bugs or suggested improvements to: |
| 42 | +# |
| 43 | +# David Hale <dhale@caltech.edu> or |
| 44 | +# Stephen Kaye <skaye@caltech.edu> |
| 45 | + |
| 46 | +# ----------------------------------------------------------------------------- |
| 47 | +# @file Makefile |
| 48 | +# @brief Makefile for Software/wdl/demo |
| 49 | +# @author David Hale |
| 50 | +# @date 2015-xx-xx |
| 51 | +# @modified 2024-08-02 made generic for demo |
| 52 | +# |
| 53 | +# This Makefile uses the general preprocessor GPP 2.24 for macro processing. |
| 54 | +# It also requires the ini2acf.pl Perl script for creating an Archon acf file. |
| 55 | +# |
| 56 | +# ----------------------------------------------------------------------------- |
| 57 | +# |
| 58 | + |
| 59 | +# set to path to gpp |
| 60 | +GPP = /opt/homebrew/Cellar/gpp/2.28/bin/gpp |
| 61 | +# set to path to wdl code |
| 62 | +WDLPATH = /Users/elijah/wdl-dev/wdl |
| 63 | +# output for *.acf file |
| 64 | +ACFPATH = /Users/elijah/wdl-dev/wdlfiles/acf |
| 65 | + |
| 66 | +PLOT = False # True # show waveform plots by default, True | False |
| 67 | +GFLAGS = +c "/*" "*/" +c "//" "\n" +c "\\\n" "" |
| 68 | +SEQPARSER = $(WDLPATH)/wdl/seqParserDriver.py |
| 69 | +INCPARSER = $(WDLPATH)/wdl/incParserDriver.py |
| 70 | +WDLPARSER = $(WDLPATH)/wdl/wdlParserDriver.py |
| 71 | +MODPARSER = $(WDLPATH)/wdl/modParserDriver.py |
| 72 | +WAVGEN = $(WDLPATH)/wdl/wavgenDriver.py |
| 73 | +MODEGEN = $(WDLPATH)/wdl/modegenDriver.py |
| 74 | +I2A = $(WDLPATH)/wdl/ini2acf.pl |
| 75 | +INCL = -I$(CURDIR) |
| 76 | + |
| 77 | +# Global variable to store the filename |
| 78 | +FILE_NAME := |
| 79 | + |
| 80 | +SCAN_CDSFILE = cat $(FILE_NAME).conf | $(GPP) $(GFLAGS) $(INCL) | \ |
| 81 | + awk -F= '{gsub(" |\t","",$$1)} $$1=="CDS_FILE"{print $$2}' | cut -d'"' -f2 |
| 82 | +SCAN_MODFILE = cat $(FILE_NAME).conf | $(GPP) $(GFLAGS) $(INCL) | \ |
| 83 | + awk -F= '{gsub(" |\t","",$$1)} $$1=="MODULE_FILE"{print $$2}' | cut -d'"' -f2 |
| 84 | +SCAN_MODEFILE = cat $(FILE_NAME).conf | $(GPP) $(GFLAGS) $(INCL) | \ |
| 85 | + awk -F= '{gsub(" |\t","",$$1)} $$1=="MODE_FILE"{print $$2}' | cut -d'"' -f2 |
| 86 | + |
| 87 | +F_TMP = $(FILE_NAME)_TMP |
| 88 | + |
| 89 | +DEBUG ?= 0 |
| 90 | + |
| 91 | +ifeq ($(DEBUG), 1) |
| 92 | + debug_message = @echo "Debug: $(1)" |
| 93 | +else |
| 94 | + debug_message = @true |
| 95 | +endif |
| 96 | + |
| 97 | +# Main rule for building the target |
| 98 | +%: |
| 99 | + $(eval FILE_NAME := $(@F)) |
| 100 | + $(call debug_message, "Current filename: $(FILE_NAME)") |
| 101 | + @$(MAKE) generate_wdl FILE_NAME=$(@F) |
| 102 | + @$(MAKE) generate_script_states FILE_NAME=$(@F) |
| 103 | + @$(MAKE) assemble_acf FILE_NAME=$(@F) |
| 104 | + |
| 105 | +# Rule for generating WDL |
| 106 | +generate_wdl: |
| 107 | + $(eval MODFILE := $(shell $(SCAN_MODFILE))) |
| 108 | + @echo "Looking for MODULE_FILE = $(MODFILE) ..." |
| 109 | + @test -f $(FILE_NAME).conf || { echo "$(FILE_NAME).conf does not exist"; exit 1; } |
| 110 | + $(call debug_message, "Found configuration file: $(FILE_NAME).conf") |
| 111 | + |
| 112 | + @echo "Making $(F_TMP).wdl from $(FILE_NAME).conf ..." |
| 113 | + @cat $(FILE_NAME).conf | $(SEQPARSER) - | $(GPP) $(GFLAGS) $(INCL) | $(WDLPARSER) - > $(F_TMP).wdl |
| 114 | + $(call debug_message, "Created WDL file: $(F_TMP).wdl") |
| 115 | + |
| 116 | + @echo "Making $(F_TMP).script and $(F_TMP).states from $(F_TMP).wdl ..." |
| 117 | + @test -f $(MODFILE) || { echo "$(MODFILE) does not exist"; exit 1; } |
| 118 | + $(call debug_message, "Found MODULE_FILE: $(MODFILE)") |
| 119 | + |
| 120 | + @cat $(MODFILE) | $(GPP) $(GFLAGS) $(INCL) | $(MODPARSER) |
| 121 | + @test -f .modules && mv .modules $(F_TMP).modules || echo "No .modules file created" |
| 122 | + @test -f .system && mv .system $(F_TMP).system || echo "No .system file created" |
| 123 | + $(call debug_message, "Processed MODULE_FILE: $(MODFILE)") |
| 124 | + |
| 125 | + @$(WAVGEN) $(F_TMP) $(PLOT) || { echo "Waveform generation failed"; exit 1; } |
| 126 | + $(call debug_message, "Finished waveform generation for $(F_TMP) with plot: $(PLOT)") |
| 127 | + |
| 128 | +# Rule for generating script states |
| 129 | +generate_script_states: |
| 130 | + @echo "Assembling $(FILE_NAME).acf ..." |
| 131 | + $(eval CDSFILE := $(shell $(SCAN_CDSFILE))) |
| 132 | + $(call debug_message, "Looking for CDS_FILE = $(CDSFILE) ...") |
| 133 | + @test -f $(CDSFILE) || { echo "$(CDSFILE) does not exist"; exit 1; } |
| 134 | + $(call debug_message, "Preparing to assemble $(FILE_NAME).acf file using:") |
| 135 | + $(call debug_message, "INCPARSER: $(INCPARSER)") |
| 136 | + $(call debug_message, "CDSFILE: $(CDSFILE)") |
| 137 | + $(call debug_message, "GPP Flags: $(GFLAGS)") |
| 138 | + @echo "Assembling $(FILE_NAME).acf file ..." |
| 139 | + @cat $(FILE_NAME).conf | $(INCPARSER) - | cat - $(CDSFILE) | $(GPP) $(GFLAGS) $(INCL) | \ |
| 140 | + cat - $(F_TMP).script $(F_TMP).modules $(F_TMP).states $(F_TMP).system | \ |
| 141 | + $(I2A) - > $(FILE_NAME).acf |
| 142 | + |
| 143 | +# Rule for assembling the ACF |
| 144 | +assemble_acf: |
| 145 | + $(eval MODEFILE := $(shell $(SCAN_MODEFILE))) |
| 146 | + @$(MODEGEN) $(MODEFILE) $(FILE_NAME).acf |
| 147 | + @if [ -d ".git" ]; then \ |
| 148 | + echo "Inserting REV keyword ..."; $(WDLPATH)/insert_hash $(FILE_NAME).acf; \ |
| 149 | + else \ |
| 150 | + echo "Not a git archive, skipping REV keyword"; \ |
| 151 | + fi |
| 152 | + @echo "Done" |
0 commit comments