Home | History | Annotate | Line # | Download | only in dspgen
do_subst.awk revision 1.2.2.2
      1  1.2.2.2  nathanw # $NetBSD: do_subst.awk,v 1.2.2.2 2001/06/21 19:22:38 nathanw Exp $
      2      1.1      uch #
      3      1.1      uch # Copyright (c) 1999, 2000 Christopher G. Demetriou.  All rights reserved.
      4      1.1      uch #
      5      1.1      uch # Redistribution and use in source and binary forms, with or without
      6      1.1      uch # modification, are permitted provided that the following conditions
      7      1.1      uch # are met:
      8      1.1      uch # 1. Redistributions of source code must retain the above copyright
      9      1.1      uch #    notice, this list of conditions and the following disclaimer.
     10      1.1      uch # 2. Redistributions in binary form must reproduce the above copyright
     11      1.1      uch #    notice, this list of conditions and the following disclaimer in the
     12      1.1      uch #    documentation and/or other materials provided with the distribution.
     13      1.1      uch # 3. All advertising materials mentioning features or use of this software
     14      1.1      uch #    must display the following acknowledgement:
     15      1.1      uch #      This product includes software developed by Christopher G. Demetriou
     16      1.1      uch #      for the NetBSD Project.
     17      1.1      uch # 4. The name of the author may not be used to endorse or promote products
     18      1.1      uch #    derived from this software without specific prior written permission
     19      1.1      uch #
     20      1.1      uch # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21      1.1      uch # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22      1.1      uch # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23      1.1      uch # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24      1.1      uch # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25      1.1      uch # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26      1.1      uch # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27      1.1      uch # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28      1.1      uch # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29      1.1      uch # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30      1.1      uch 
     31      1.2      uch function setup_md_files (arch, env, srclist) {
     32      1.1      uch 	srclist=""
     33      1.1      uch 	asm_tmpl="dspgen/asm_build." arch
     34      1.1      uch 	prop_tmpl="dspgen/property." arch
     35      1.1      uch 
     36      1.1      uch 	sz = split(ENVIRON[env], a, "[ \t\n]+");
     37      1.1      uch 	for (i = 1; i <= sz; i++) {
     38      1.1      uch 		if (a[i] == "") {
     39      1.1      uch 			continue
     40      1.1      uch 		}
     41      1.1      uch 		if (srclist != "") {
     42      1.1      uch 			srclist=srclist "\n"
     43      1.1      uch 		}
     44      1.1      uch 		srclist=srclist "# Begin Source File\n"
     45      1.1      uch 		srclist=srclist "\n"
     46      1.1      uch 		srclist=srclist "SOURCE=.\\" a[i] "\n"
     47      1.1      uch 		base = index (a[i], ".asm")
     48      1.1      uch 		if (base != 0) {
     49      1.1      uch 		  basename = substr (a[i], 0, base - 1)
     50      1.1      uch 		  while (getline < asm_tmpl > 0) {
     51      1.1      uch 		    gsub ("%%% ASM_BASENAME %%%", basename)
     52      1.1      uch 		    srclist=srclist $0 "\n"
     53      1.1      uch 		  }
     54      1.1      uch 		  close (asm_tmpl)
     55      1.1      uch 		} else {
     56      1.1      uch 		  while (getline < prop_tmpl > 0)
     57      1.1      uch 		    srclist=srclist $0 "\n"
     58      1.1      uch 		    close (prop_tmpl)
     59      1.1      uch 		}
     60      1.1      uch 		srclist=srclist "# End Source File"
     61      1.1      uch 	}
     62      1.1      uch 	return srclist
     63      1.1      uch }
     64      1.1      uch 
     65      1.1      uch BEGIN {
     66      1.1      uch 	NAME=ENVIRON["NAME"]
     67      1.1      uch 
     68      1.1      uch 	SRCFILES=""
     69      1.1      uch 	sz = split(ENVIRON["SRCFILE_LIST"], a, "[ \t\n]+");
     70      1.1      uch 	for (i = 1; i <= sz; i++) {
     71      1.1      uch 		if (a[i] == "") {
     72      1.1      uch 			continue
     73      1.1      uch 		}
     74      1.1      uch 		if (SRCFILES != "") {
     75      1.1      uch 			SRCFILES=SRCFILES "\n"
     76      1.1      uch 		}
     77      1.1      uch 		SRCFILES=SRCFILES "# Begin Source File\n"
     78      1.1      uch 		SRCFILES=SRCFILES "\n"
     79      1.1      uch 		SRCFILES=SRCFILES "SOURCE=.\\" a[i] "\n"
     80      1.1      uch 		SRCFILES=SRCFILES "# End Source File"
     81      1.1      uch 	}
     82      1.1      uch 
     83      1.2      uch 	SRCFILES_ARM = setup_md_files("ARM", "SRCFILE_LIST_ARM", SRCFILES_ARM)
     84      1.2      uch 	SRCFILES_SH3 = setup_md_files("SH3", "SRCFILE_LIST_SH3", SRCFILES_SH3)
     85  1.2.2.1  nathanw 	SRCFILES_SH4 = setup_md_files("SH4", "SRCFILE_LIST_SH3", SRCFILES_SH3)
     86      1.2      uch 	SRCFILES_SH = setup_md_files("SH", "SRCFILE_LIST_SH3", SRCFILES_SH3)
     87      1.2      uch 	SRCFILES_MIPS = setup_md_files("MIPS", "SRCFILE_LIST_MIPS",
     88      1.2      uch 				       SRCFILES_MIPS)
     89      1.1      uch 
     90      1.1      uch 	CPPDEFS=""
     91      1.1      uch 	sz = split(ENVIRON["STD_CPPDEF_LIST"], a, "[ \t\n]+");
     92      1.1      uch 	for (i = 1; i <= sz; i++) {
     93      1.1      uch 		if (a[i] == "") {
     94      1.1      uch 			continue
     95      1.1      uch 		}
     96      1.1      uch 		if (CPPDEFS != "") {
     97      1.1      uch 			CPPDEFS=CPPDEFS " "
     98      1.1      uch 		}
     99  1.2.2.2  nathanw 		a[i] = gensub("([^\\\\]|^)#", "\\1 ", "g", a[i])
    100  1.2.2.2  nathanw 		a[i] = gensub("\\\\#", "#", "g", a[i])
    101  1.2.2.2  nathanw 		CPPDEFS=CPPDEFS "/D " a[i]
    102      1.1      uch 	}
    103      1.1      uch 	sz = split(ENVIRON["CPPDEF_LIST"], a, "[ \t\n]+");
    104      1.1      uch 	for (i = 1; i <= sz; i++) {
    105      1.1      uch 		if (a[i] == "") {
    106      1.1      uch 			continue
    107      1.1      uch 		}
    108      1.1      uch 		if (CPPDEFS != "") {
    109      1.1      uch 			CPPDEFS=CPPDEFS " "
    110      1.1      uch 		}
    111  1.2.2.2  nathanw 		a[i] = gensub("([^\\\\]|^)#", "\\1 ", "g", a[i])
    112  1.2.2.2  nathanw 		a[i] = gensub("\\\\#", "#", "g", a[i])
    113  1.2.2.2  nathanw 		CPPDEFS=CPPDEFS "/D " a[i]
    114      1.1      uch 	}
    115      1.1      uch 
    116      1.1      uch 	INCDIRS=""
    117      1.1      uch 	sz = split(ENVIRON["STD_INCDIR_LIST"], a, "[ \t\n]+");
    118      1.1      uch 	for (i = 1; i <= sz; i++) {
    119      1.1      uch 		if (a[i] == "") {
    120      1.1      uch 			continue
    121      1.1      uch 		}
    122      1.1      uch 		if (INCDIRS != "") {
    123      1.1      uch 			INCDIRS=INCDIRS " "
    124      1.1      uch 		}
    125      1.1      uch 		INCDIRS=INCDIRS "/I \"" a[i] "\""
    126      1.1      uch 	}
    127      1.1      uch 	sz = split(ENVIRON["INCDIR_LIST"], a, "[ \t\n]+");
    128      1.1      uch 	for (i = 1; i <= sz; i++) {
    129      1.1      uch 		if (a[i] == "") {
    130      1.1      uch 			continue
    131      1.1      uch 		}
    132      1.1      uch 		if (INCDIRS != "") {
    133      1.1      uch 			INCDIRS=INCDIRS " "
    134      1.1      uch 		}
    135      1.1      uch 		INCDIRS=INCDIRS "/I \"" a[i] "\""
    136      1.1      uch 	}
    137      1.1      uch 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    138      1.1      uch 	for (i = 1; i <= sz; i++) {
    139      1.1      uch 		if (a[i] == "") {
    140      1.1      uch 			continue
    141      1.1      uch 		}
    142      1.1      uch 		if (INCDIRS != "") {
    143      1.1      uch 			INCDIRS=INCDIRS " "
    144      1.1      uch 		}
    145      1.1      uch 		INCDIRS=INCDIRS "/I \"..\\" a[i] "\""
    146      1.1      uch         }
    147      1.1      uch 
    148      1.1      uch 	LIBRARIES=""
    149      1.1      uch 	sz = split(ENVIRON["STD_LIBRARY_LIST"], a, "[ \t\n]+");
    150      1.1      uch 	for (i = 1; i <= sz; i++) {
    151      1.1      uch 		if (a[i] == "") {
    152      1.1      uch 			continue
    153      1.1      uch 		}
    154      1.1      uch 		if (LIBRARIES != "") {
    155      1.1      uch 			LIBRARIES=LIBRARIES " "
    156      1.1      uch 		}
    157      1.1      uch 		LIBRARIES=LIBRARIES a[i] ".lib"
    158      1.1      uch 	}
    159      1.1      uch 	sz = split(ENVIRON["LIBRARY_LIST"], a, "[ \t\n]+");
    160      1.1      uch 	for (i = 1; i <= sz; i++) {
    161      1.1      uch 		if (a[i] == "") {
    162      1.1      uch 			continue
    163      1.1      uch 		}
    164      1.1      uch 		if (LIBRARIES != "") {
    165      1.1      uch 			LIBRARIES=LIBRARIES " "
    166      1.1      uch 		}
    167      1.1      uch 		LIBRARIES=LIBRARIES a[i] ".lib"
    168      1.1      uch         }
    169      1.1      uch 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    170      1.1      uch 	for (i = 1; i <= sz; i++) {
    171      1.1      uch 		if (a[i] == "") {
    172      1.1      uch 			continue
    173      1.1      uch 		}
    174      1.1      uch 		if (LIBRARIES != "") {
    175      1.1      uch 			LIBRARIES=LIBRARIES " "
    176      1.1      uch 		}
    177      1.1      uch 		LIBRARIES=LIBRARIES a[i] ".lib"
    178      1.1      uch 	}
    179      1.1      uch 
    180      1.1      uch 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    181      1.1      uch 	DEBUG_LIBPATH=""
    182      1.1      uch 	RELEASE_LIBPATH=""
    183      1.1      uch 	for (i = 1; i <= sz; i++) {
    184      1.1      uch 		if (a[i] == "") {
    185      1.1      uch 			continue
    186      1.1      uch 		}
    187      1.1      uch 		if (i > 1) {
    188      1.1      uch 			DEBUG_LIBPATH=DEBUG_LIBPATH " "
    189      1.1      uch 			RELEASE_LIBPATH=RELEASE_LIBPATH " "
    190      1.1      uch 		}
    191      1.1      uch 		DEBUG_LIBPATH=DEBUG_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSDbg\""
    192      1.1      uch 		RELEASE_LIBPATH=RELEASE_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSRel\""
    193      1.1      uch 	}
    194      1.1      uch }
    195      1.1      uch {
    196      1.1      uch 	gsub("%%% SRCFILES %%%", SRCFILES)
    197      1.1      uch 	gsub("%%% SRCFILES_ARM %%%", SRCFILES_ARM)
    198      1.1      uch 	gsub("%%% SRCFILES_SH3 %%%", SRCFILES_SH3)
    199  1.2.2.1  nathanw 	gsub("%%% SRCFILES_SH4 %%%", SRCFILES_SH4)
    200      1.2      uch 	gsub("%%% SRCFILES_SH %%%", SRCFILES_SH)
    201      1.1      uch 	gsub("%%% SRCFILES_MIPS %%%", SRCFILES_MIPS)
    202      1.1      uch 	gsub("%%% CPPDEFS %%%", CPPDEFS)
    203      1.1      uch 	gsub("%%% INCDIRS %%%", INCDIRS)
    204      1.1      uch 	gsub("%%% LIBRARIES %%%", LIBRARIES)
    205      1.1      uch 	gsub("%%% DEBUG_LIBPATH %%%", DEBUG_LIBPATH)
    206      1.1      uch 	gsub("%%% RELEASE_LIBPATH %%%", RELEASE_LIBPATH)
    207      1.1      uch 	gsub("%%% NAME %%%", NAME)
    208      1.1      uch 	print $0
    209      1.1      uch }
    210