mk-2nd.awk revision 50276
150276Speter# $Id: mk-2nd.awk,v 1.11 1998/10/17 21:54:21 Alexander.V.Lukyanov 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	}
7050276Speter	!/^[@#]/ {
7150276Speter		if ($0 != "" \
7250276Speter		 && using != 0) {
7350276Speter			found = 1
7450276Speter			if ( $1 != "" ) {
7550276Speter				print  ""
7650276Speter				if ( $2 == "c++" ) {
7750276Speter					compile="CXX"
7850276Speter					suffix=".cc"
7950276Speter				} else {
8050276Speter					compile="CC"
8150276Speter					suffix=".c"
8250276Speter				}
8350276Speter				printf "../%s/%s.o :\t%s/%s%s", model, $1, $3, $1, suffix
8450276Speter				for (n = 4; n <= NF; n++) printf " \\\n\t\t\t%s", $n
8550276Speter				print  ""
8650276Speter				if ( echo == "yes" )
8750276Speter					atsign=""
8850276Speter				else {
8950276Speter					atsign="@"
9050276Speter					printf "\t@echo 'compiling %s (%s)'\n", $1, model
9150276Speter				}
9250276Speter				if ( $3 == "." || srcdir == "." ) {
9350276Speter					dir = $3 "/"
9450276Speter					sub("^\\$\\(srcdir\\)/","",dir);
9550276Speter					sub("^\\./","",dir);
9650276Speter					printf "\t%scd ../%s; $(%s) $(CFLAGS_%s) -c ../%s/%s%s%s", atsign, model, compile, MODEL, name, dir, $1, suffix
9750276Speter				} else
9850276Speter					printf "\t%scd ../%s; $(%s) $(CFLAGS_%s) -c %s/%s%s", atsign, model, compile, MODEL, $3, $1, suffix
9950276Speter			} else {
10050276Speter				printf "%s", $1
10150276Speter				for (n = 2; n <= NF; n++) printf " %s", $n
10250276Speter			}
10350276Speter			print  ""
10450276Speter		}
10550276Speter	}
10650276SpeterEND	{
10750276Speter		print  ""
10850276Speter	}
109