mk-2nd.awk revision 62449
162449Speter# $Id: mk-2nd.awk,v 1.12 2000/04/01 20:50:36 tom Exp $
250276Speter##############################################################################
350276Speter# Copyright (c) 1998 Free Software Foundation, Inc.                          #
450276Speter#                                                                            #
550276Speter# Permission is hereby granted, free of charge, to any person obtaining a    #
650276Speter# copy of this software and associated documentation files (the "Software"), #
750276Speter# to deal in the Software without restriction, including without limitation  #
850276Speter# the rights to use, copy, modify, merge, publish, distribute, distribute    #
950276Speter# with modifications, sublicense, and/or sell copies of the Software, and to #
1050276Speter# permit persons to whom the Software is furnished to do so, subject to the  #
1150276Speter# following conditions:                                                      #
1250276Speter#                                                                            #
1350276Speter# The above copyright notice and this permission notice shall be included in #
1450276Speter# all copies or substantial portions of the Software.                        #
1550276Speter#                                                                            #
1650276Speter# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
1750276Speter# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
1850276Speter# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
1950276Speter# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
2050276Speter# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
2150276Speter# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
2250276Speter# DEALINGS IN THE SOFTWARE.                                                  #
2350276Speter#                                                                            #
2450276Speter# Except as contained in this notice, the name(s) of the above copyright     #
2550276Speter# holders shall not be used in advertising or otherwise to promote the sale, #
2650276Speter# use or other dealings in this Software without prior written               #
2750276Speter# authorization.                                                             #
2850276Speter##############################################################################
2950276Speter#
3050276Speter# Author: Thomas E. Dickey <dickey@clark.net> 1996,1997
3150276Speter#
3250276Speter# Generate compile-rules for the modules that we are using in libraries or
3350276Speter# programs.  We are listing them explicitly because we have turned off the
3450276Speter# suffix rules (to force compilation with the appropriate flags).  We could use
3550276Speter# make-recursion but that would result in makefiles that are useless for
3650276Speter# development.
3750276Speter#
3850276Speter# Variables:
3950276Speter#	model
4050276Speter#	MODEL (uppercase version of "model"; toupper is not portable)
4150276Speter#	echo (yes iff we will show the $(CC) lines)
4250276Speter#	subset ("none", "base", "base+ext_funcs" or "termlib")
4350276Speter#
4450276Speter# Fields in src/modules:
4550276Speter#	$1 = module name
4650276Speter#	$2 = progs|lib|c++
4750276Speter#	$3 = source-directory
4850276Speter#
4950276Speter# Fields in src/modules past $3 are dependencies
5050276Speter#
5150276SpeterBEGIN	{
5250276Speter		found = 0
5350276Speter		using = 0
5450276Speter	}
5550276Speter	/^@/ {
5650276Speter		using = 0
5750276Speter		if (subset == "none") {
5850276Speter			using = 1
5950276Speter		} else if (index(subset,$2) > 0) {
6050276Speter			if (using == 0) {
6150276Speter				if (found == 0) {
6250276Speter					print  ""
6350276Speter					print  "# generated by mk-2nd.awk"
6450276Speter					print  ""
6550276Speter				}
6650276Speter				using = 1
6750276Speter			}
6850276Speter		}
6950276Speter	}
7062449Speter	/^[@#]/ {
7162449Speter		next
7262449Speter	}
7362449Speter	$1 ~ /trace/ {
7462449Speter		if (traces != "all" && traces != MODEL && $1 != "lib_trace")
7562449Speter			next
7662449Speter	}
7762449Speter	{
7850276Speter		if ($0 != "" \
7950276Speter		 && using != 0) {
8050276Speter			found = 1
8150276Speter			if ( $1 != "" ) {
8250276Speter				print  ""
8350276Speter				if ( $2 == "c++" ) {
8450276Speter					compile="CXX"
8550276Speter					suffix=".cc"
8650276Speter				} else {
8750276Speter					compile="CC"
8850276Speter					suffix=".c"
8950276Speter				}
9050276Speter				printf "../%s/%s.o :\t%s/%s%s", model, $1, $3, $1, suffix
9150276Speter				for (n = 4; n <= NF; n++) printf " \\\n\t\t\t%s", $n
9250276Speter				print  ""
9350276Speter				if ( echo == "yes" )
9450276Speter					atsign=""
9550276Speter				else {
9650276Speter					atsign="@"
9750276Speter					printf "\t@echo 'compiling %s (%s)'\n", $1, model
9850276Speter				}
9950276Speter				if ( $3 == "." || srcdir == "." ) {
10050276Speter					dir = $3 "/"
10150276Speter					sub("^\\$\\(srcdir\\)/","",dir);
10250276Speter					sub("^\\./","",dir);
10350276Speter					printf "\t%scd ../%s; $(%s) $(CFLAGS_%s) -c ../%s/%s%s%s", atsign, model, compile, MODEL, name, dir, $1, suffix
10450276Speter				} else
10550276Speter					printf "\t%scd ../%s; $(%s) $(CFLAGS_%s) -c %s/%s%s", atsign, model, compile, MODEL, $3, $1, suffix
10650276Speter			} else {
10750276Speter				printf "%s", $1
10850276Speter				for (n = 2; n <= NF; n++) printf " %s", $n
10950276Speter			}
11050276Speter			print  ""
11150276Speter		}
11250276Speter	}
11350276SpeterEND	{
11450276Speter		print  ""
11550276Speter	}
116