/* This cookfile contains the instructions on how to build all the "programs" required for the "wind_gen" project. ---- Fortran version ---- This cookfile assumes: All shared project source files are in the "libf" directory. All program specific source files are in their respective program directories. All shared project include files are in the "include" directory. All program specific include files are in their respective program directories. All program binaries for the project are named according to their respective program directory names. Each program binary must have a "main.c" residing in their respective program directory. All built binaries from the project will end up in the "bin" directory. The benefits of this directory structure/scheme is that additional files/programs can be added to the project without any changes to the "cookfile" being required (usually). */ fc = lf95; fc_flags = -nco; /* do not display compiler option settings */ fc_flags += -chk; /* subscript bounds checking */ fc_flags += -stchk; /* stack checking */ fc_flags += -in; /* declare type of all symbols */ fc_flags += -w; /* issue warnings and informational messages */ fc_flags += -trace; /* generate traceback if error */ fc_dflags = ; ar = lm; ar_flags = ; ld = lf95; ld_flags = -nobanner; /* operate linker quietly */ ld_flags += -twocase; /* enables case-sensitive symbols */ ld_flags += -nomap; /* no link map generated */ ld_flags += -warn; /* enable warnings */ ld_dflags = ; ld_libs = ; LIB = ; /* lib prefix */ A = .lib; OBJ = .obj; EXE = .exe; if [defined DEBUG] then { echo "compiling with DEBUG options enabled"; fc_flags = [fc_dflags] [fc_flags]; ld_flags = [ld_dflags] [ld_flags]; } /* determine all src files (*.for *.fi, etc.) of project */ manifest = [fromto ./%0% %0% [collect find . ! -type d -print] ]; /* echo "manifest list is: " [manifest]; */ /* find the dependency files from the manifest */ /* and "magically include them (#include-cooked) */ dep-files = [addsuffix .d [match_mask %0%.for [manifest] ] [match_mask %0%.fi [manifest] ] ]; #include-cooked [dep-files] /* echo "dependency files are: " [dep-files]; */ /* find all the object files from the manifest */ all_obj = [fromto %0%.for %0%[OBJ] [match_mask "%0%.for" [manifest] ] ]; /* echo "all object files are: " [all_obj]; */ /* find all the library object files from the manifest */ libf/[LIB]libf[A]_obj = [fromto %0%.for %0%[OBJ] [match_mask "libf/%0%.for" [manifest] ] ]; /* echo "library and src files are: " [libf/[LIB]libf[A]_obj]; */ /* find all the program files from the manifest */ programs = [fromto %/main.for %[EXE] /* add .exe extension if necessary */ [match_mask %/main.for [manifest] ] ]; /* echo "The program files are: " [programs]; */ program_roots = [fromto %0%[EXE] %0% [programs]]; /* remove .exe extension */ /* determine all the src files (and libraries) */ /* needed for each program (exe) file from the manifest */ /* Note the need for temporary variables as they get destroyed in the loop */ tmp_program_list = [program_roots]; /* no .exe extension */ loop { tmp_program = [head [tmp_program_list]]; if [not [count [tmp_program]]] then loopstop; /* remove first (leading) program from list each time through loop */ tmp_program_list = [tail [tmp_program_list]]; bin/[tmp_program]_obj = [fromto %0%.for %0%[OBJ] [match_mask [tmp_program]/%0%.for [manifest]] ] /* libf/[LIB]libf[A] */ /* lib and it's path now include in recipe */ ; /* echo "program obj files for each program are: " [bin/[tmp_program]_obj]; */ } /* echo "The program files are: " [programs]; echo "The program file roots are: " [program_roots]; */ /************** RECIPE section *********************/ /* recipe to build "dependency" files */ %0%.for.d: %0%.for set nocascade { c_incl -nc -ns -nrec "--l=optimistic" -I [dirname %0%.for] -Iinclude %0%.for -prefix "'cascade %0%.for ='" -suffix "';'" -o [target]; } /* recipe to build "dependency" files */ %0%.fi.d: %0%.fi set nocascade { c_incl -nc -ns -nrec "--l=optimistic" -I[dirname %0%.fi] -Iinclude %0%.fi -prefix "'cascade %0%.fi ='" -suffix "';'" -o [target]; } /* recipe to build "obj" files */ %0%[OBJ]: %0%.for { [fc] [fc_flags] -I \"[dos-path [dirname %0]]\;include\" -c %0%.for -o [target]; } /* recipe to build "library" files */ /* had to add "libf" to keep from accessing non-existant variables */ libf/[LIB]%[A]: [[target]_obj] set unlink { /* am looping to keep commandline from getting too long */ tmp_target_obj_list = [[target]_obj]; loop { tmp_target_obj = [head [tmp_target_obj_list]]; if [not [count [tmp_target_obj]]] then loopstop; /* remove first (leading) obj from list each time through loop */ tmp_target_obj_list = [tail [tmp_target_obj_list]]; [ar] [subst \\ \\\\ [dos-path [target]]] -+[tmp_target_obj]\\\;; } } /* recipe to build "binary" files (programs) */ bin/%: [[target]_obj] libf/[LIB]libf[A] set mkdir { /* echo "[[target]_obj]" "[target]" [[target]_obj] [target]; */ [fc] [fc_flags] [ld_flags] -out [target][EXE] [[target]_obj] -libpath libf -lib [LIB]libf[A]; } /************** TARGET section *********************/ /* tell cook to build all "programs" */ all: [addprefix bin/ [program_roots]]; test: { echo "[addprefix bin/ [programs]] " [addprefix bin/ [programs]]; echo "[addprefix bin/ [program_roots]] " [addprefix bin/ [program_roots]]; } clean: /* get all intermediate and binary files */ { rm -f [addprefix bin/ [programs]] [all_obj] set clearstat; } clobber: clean /* get those dependency files as well */ { rm -f [dep-files] set clearstat; }