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