/* This cookfile contains the instructions on how to build all the "programs" required for the "wind_gen" project. This cookfile assumes: All shared project source files are in the "lib" 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 default method to build the executables is: cook or cook DEBUG=1 - enables additional debugging info To build "standalone" executables that will run on PC's without the Cygwin environment available, use the following command: cook MINGW=1 Note that the user must have a MINGW (or Windows compatible) compiler installed and properly configured for it to work with cook (presumably running under Cygwin) to do a "Windows only" build. 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). */ /* Determin the system we are running cook under, e.g. Linux/Unix or Cygwin */ /*OS booleans */ is_unix = [in [downcase [os system]] unix linux sunos]; is_windows = [not [is_unix] ]; /* presumably Cygwin */ function print "is_unix:" [is_unix]; function print "is_windows:" [is_windows]; mode = ; cross = ; fc_name = ; cc_version = ; fc_version = ; ld_version = ; ar_version = ; dep.dir = ; build.dir = ; dist.dir = ; /* Set the default (generic) compiler vars */ { cc = gcc; cc_flags = -W -O; cc_dflags = -v -H -g; ld = ld; ld_flags = -static; ld_dflags = -v; ld_libs = -lm; /* math lib */ ar = ar; if [is_windows] then /* for Cygwin builds */ { EXE = .exe; OBJ = .obj; ld_libs = [ld_libs] -liberty; /* needed for getopt() */ } else { EXE = ; /* Unix */ OBJ = .o; } } if [defined MINGW] then { /* Set path */ cpath = [shell cygpath -ws '"c:/Program\ Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin"' | cygpath -uf -]; function print "cygwin MINGW gcc path is:" [cpath]; cc = [cpath]/gcc.exe; function print "cygwin MINGW C compiler:" [cc]; ld = [cpath]/ld.exe; ar = [cpath]/ar.exe; } if [defined DEBUG] then { echo "compiling with DEBUG options enabled"; cc_flags = [cc_dflags] [cc_flags]; ld_flags = [ld_dflags] [ld_flags]; } /* determine all src files (*.c *.h, 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%.c [manifest] ] [match_mask %0%.h [manifest] ] ]; #include-cooked [dep-files] /* echo "dependency files are: " [dep-files]; */ /* find all the object files from the manifest */ all_obj = [fromto %0%.c %0%[OBJ] [match_mask "%0%.c" [manifest] ] ]; /* echo "all object files are: " [all_obj]; */ /* find all the library object files from the manifest */ lib/liblib.a_obj = [fromto %0%.c %0%[OBJ] [match_mask "lib/%0%.c" [manifest] ] ]; /* echo "library and src files are: " [lib/liblib.a_obj]; */ /* find all the program files from the manifest */ programs = [fromto %/main.c % [match_mask %/main.c [manifest] ] ]; echo "The program files are: " [programs]; /* 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 = [programs]; 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%.c %0%[OBJ] [match_mask [tmp_program]/%0%.c [manifest]] ] lib/liblib.a ; /* echo "program obj files for each program are: " [bin/[tmp_program]_obj]; */ } /* echo "The program files are: " [programs]; */ /************** RECIPE section *********************/ /* recipe to build "dependency" files */ %0%.c.d: %0%.c set nocascade { c_incl -nc -ns -nrec -I[dirname %0%.c] -Iinclude %0%.c -prefix "'cascade %0%.c ='" -suffix "';'" -o [target]; } /* recipe to build "dependency" files */ %0%.h.d: %0%.h set nocascade { c_incl -nc -ns -nrec -I[dirname %0%.h] -Iinclude %0%.h -prefix "'cascade %0%.h ='" -suffix "';'" -o [target]; } /* recipe to build "obj" files */ %0%[OBJ]: %0%.c { [cc] [cc_flags] -I[dirname %0%.c] -Iinclude -c %0%.c -o [target]; } /* recipe to build "library" files */ %/lib%.a: [[target]_obj] set unlink { [ar] cq [target] [[target]_obj]; if [not [defined FCC]] then { [ar] -d [target] my_getopt[OBJ]; /* ar t [target]; */ } } /* recipe to build "binary" files (programs) */ bin/%: [[target]_obj] set mkdir { [cc] -o [target][EXE] [[target]_obj] [ld_flags] [ld_libs]; } /************** TARGET section *********************/ /* tell cook to build all "programs" */ all: [addprefix bin/ [programs]]; test: { echo "[addprefix bin/ [programs]] " [addprefix bin/ [programs]]; } clean: /* get all intermediate and binary files */ { rm -f [all_obj] lib/liblib.a set clearstat; } clobber: clean /* get those dependency files as well */ { rm -f [dep-files] set clearstat; } show:{ function print "Datetime:" [collect date]; function print "Computer:" [os node]; function print "User:" [collect whoami]; function print "System:" [os system] "Arch:" [os machine]; function print "Release:" [os release] "Version:" [os version]; function print "Compiler:" [cc]; function print "Linker:" [ld]; function print "Archiver:" [ar]; function print "SVN Revision:" [collect svn info | grep "Revision:" | sed "s/Revision://"]; function print "Local Mods:" [collect svn status -q | wc -l]; } /* not yet implemented in this cookfile */ showmore:{ function print "Mode:" [mode]; function print "Cross Compile:" [cross]; function print "Fortran Compiler:" [fc_name]; function print "Fortran Compiler Version:" [fc_version]; function print "Linker Version:" [ld_version]; function print "Archiver Version:" [ar_version]; function print "Dependencies:" [dep.dir]/; function print "Build Artifacts:" [build.dir]/; function print "Distributables:" [dist.dir]/; }