Home | History | Annotate | Line # | Download | only in dspgen
do_subst.awk revision 1.4.98.1
      1  1.4.98.1       rjs # $NetBSD: do_subst.awk,v 1.4.98.1 2008/02/28 21:47:53 rjs 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.4.98.1       rjs 	SRCFILES_ARMV4 = setup_md_files("ARMV4", "SRCFILE_LIST_ARM", SRCFILES_ARM)
     85       1.2       uch 	SRCFILES_SH3 = setup_md_files("SH3", "SRCFILE_LIST_SH3", SRCFILES_SH3)
     86       1.3       uch 	SRCFILES_SH4 = setup_md_files("SH4", "SRCFILE_LIST_SH3", SRCFILES_SH3)
     87       1.2       uch 	SRCFILES_SH = setup_md_files("SH", "SRCFILE_LIST_SH3", SRCFILES_SH3)
     88       1.2       uch 	SRCFILES_MIPS = setup_md_files("MIPS", "SRCFILE_LIST_MIPS",
     89       1.2       uch 				       SRCFILES_MIPS)
     90       1.1       uch 
     91       1.1       uch 	CPPDEFS=""
     92       1.1       uch 	sz = split(ENVIRON["STD_CPPDEF_LIST"], a, "[ \t\n]+");
     93       1.1       uch 	for (i = 1; i <= sz; i++) {
     94       1.1       uch 		if (a[i] == "") {
     95       1.1       uch 			continue
     96       1.1       uch 		}
     97       1.1       uch 		if (CPPDEFS != "") {
     98       1.1       uch 			CPPDEFS=CPPDEFS " "
     99       1.1       uch 		}
    100       1.4  takemura 		a[i] = gensub("([^\\\\]|^)#", "\\1 ", "g", a[i])
    101       1.4  takemura 		a[i] = gensub("\\\\#", "#", "g", a[i])
    102       1.4  takemura 		CPPDEFS=CPPDEFS "/D " a[i]
    103       1.1       uch 	}
    104       1.1       uch 	sz = split(ENVIRON["CPPDEF_LIST"], a, "[ \t\n]+");
    105       1.1       uch 	for (i = 1; i <= sz; i++) {
    106       1.1       uch 		if (a[i] == "") {
    107       1.1       uch 			continue
    108       1.1       uch 		}
    109       1.1       uch 		if (CPPDEFS != "") {
    110       1.1       uch 			CPPDEFS=CPPDEFS " "
    111       1.1       uch 		}
    112       1.4  takemura 		a[i] = gensub("([^\\\\]|^)#", "\\1 ", "g", a[i])
    113       1.4  takemura 		a[i] = gensub("\\\\#", "#", "g", a[i])
    114       1.4  takemura 		CPPDEFS=CPPDEFS "/D " a[i]
    115       1.1       uch 	}
    116       1.1       uch 
    117       1.1       uch 	INCDIRS=""
    118       1.1       uch 	sz = split(ENVIRON["STD_INCDIR_LIST"], a, "[ \t\n]+");
    119       1.1       uch 	for (i = 1; i <= sz; i++) {
    120       1.1       uch 		if (a[i] == "") {
    121       1.1       uch 			continue
    122       1.1       uch 		}
    123       1.1       uch 		if (INCDIRS != "") {
    124       1.1       uch 			INCDIRS=INCDIRS " "
    125       1.1       uch 		}
    126       1.1       uch 		INCDIRS=INCDIRS "/I \"" a[i] "\""
    127       1.1       uch 	}
    128       1.1       uch 	sz = split(ENVIRON["INCDIR_LIST"], a, "[ \t\n]+");
    129       1.1       uch 	for (i = 1; i <= sz; i++) {
    130       1.1       uch 		if (a[i] == "") {
    131       1.1       uch 			continue
    132       1.1       uch 		}
    133       1.1       uch 		if (INCDIRS != "") {
    134       1.1       uch 			INCDIRS=INCDIRS " "
    135       1.1       uch 		}
    136       1.1       uch 		INCDIRS=INCDIRS "/I \"" a[i] "\""
    137       1.1       uch 	}
    138       1.1       uch 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    139       1.1       uch 	for (i = 1; i <= sz; i++) {
    140       1.1       uch 		if (a[i] == "") {
    141       1.1       uch 			continue
    142       1.1       uch 		}
    143       1.1       uch 		if (INCDIRS != "") {
    144       1.1       uch 			INCDIRS=INCDIRS " "
    145       1.1       uch 		}
    146       1.1       uch 		INCDIRS=INCDIRS "/I \"..\\" a[i] "\""
    147       1.1       uch         }
    148       1.1       uch 
    149       1.1       uch 	LIBRARIES=""
    150       1.1       uch 	sz = split(ENVIRON["STD_LIBRARY_LIST"], a, "[ \t\n]+");
    151       1.1       uch 	for (i = 1; i <= sz; i++) {
    152       1.1       uch 		if (a[i] == "") {
    153       1.1       uch 			continue
    154       1.1       uch 		}
    155       1.1       uch 		if (LIBRARIES != "") {
    156       1.1       uch 			LIBRARIES=LIBRARIES " "
    157       1.1       uch 		}
    158       1.1       uch 		LIBRARIES=LIBRARIES a[i] ".lib"
    159       1.1       uch 	}
    160       1.1       uch 	sz = split(ENVIRON["LIBRARY_LIST"], a, "[ \t\n]+");
    161       1.1       uch 	for (i = 1; i <= sz; i++) {
    162       1.1       uch 		if (a[i] == "") {
    163       1.1       uch 			continue
    164       1.1       uch 		}
    165       1.1       uch 		if (LIBRARIES != "") {
    166       1.1       uch 			LIBRARIES=LIBRARIES " "
    167       1.1       uch 		}
    168       1.1       uch 		LIBRARIES=LIBRARIES a[i] ".lib"
    169       1.1       uch         }
    170       1.1       uch 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    171       1.1       uch 	for (i = 1; i <= sz; i++) {
    172       1.1       uch 		if (a[i] == "") {
    173       1.1       uch 			continue
    174       1.1       uch 		}
    175       1.1       uch 		if (LIBRARIES != "") {
    176       1.1       uch 			LIBRARIES=LIBRARIES " "
    177       1.1       uch 		}
    178       1.1       uch 		LIBRARIES=LIBRARIES a[i] ".lib"
    179       1.1       uch 	}
    180       1.1       uch 
    181       1.1       uch 	sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
    182       1.1       uch 	DEBUG_LIBPATH=""
    183       1.1       uch 	RELEASE_LIBPATH=""
    184       1.1       uch 	for (i = 1; i <= sz; i++) {
    185       1.1       uch 		if (a[i] == "") {
    186       1.1       uch 			continue
    187       1.1       uch 		}
    188       1.1       uch 		if (i > 1) {
    189       1.1       uch 			DEBUG_LIBPATH=DEBUG_LIBPATH " "
    190       1.1       uch 			RELEASE_LIBPATH=RELEASE_LIBPATH " "
    191       1.1       uch 		}
    192       1.1       uch 		DEBUG_LIBPATH=DEBUG_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSDbg\""
    193       1.1       uch 		RELEASE_LIBPATH=RELEASE_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSRel\""
    194       1.1       uch 	}
    195       1.1       uch }
    196       1.1       uch {
    197       1.1       uch 	gsub("%%% SRCFILES %%%", SRCFILES)
    198       1.1       uch 	gsub("%%% SRCFILES_ARM %%%", SRCFILES_ARM)
    199  1.4.98.1       rjs 	gsub("%%% SRCFILES_ARMV4 %%%", SRCFILES_ARMV4)
    200       1.1       uch 	gsub("%%% SRCFILES_SH3 %%%", SRCFILES_SH3)
    201       1.3       uch 	gsub("%%% SRCFILES_SH4 %%%", SRCFILES_SH4)
    202       1.2       uch 	gsub("%%% SRCFILES_SH %%%", SRCFILES_SH)
    203       1.1       uch 	gsub("%%% SRCFILES_MIPS %%%", SRCFILES_MIPS)
    204       1.1       uch 	gsub("%%% CPPDEFS %%%", CPPDEFS)
    205       1.1       uch 	gsub("%%% INCDIRS %%%", INCDIRS)
    206       1.1       uch 	gsub("%%% LIBRARIES %%%", LIBRARIES)
    207       1.1       uch 	gsub("%%% DEBUG_LIBPATH %%%", DEBUG_LIBPATH)
    208       1.1       uch 	gsub("%%% RELEASE_LIBPATH %%%", RELEASE_LIBPATH)
    209       1.1       uch 	gsub("%%% NAME %%%", NAME)
    210       1.1       uch 	print $0
    211       1.1       uch }
    212