Esempio n. 1
0
def am_find_srcs(target, deps, am, cond):
    dist = 0
    base, ext = split_filename(target)
    f = target
    pf = f
    while ext != "h" and f in deps:
        f = deps[f][0]
        b, ext = split_filename(f)
        if ext in automake_ext:
            pf = f

    # built source if has dep and ext != cur ext
    if not(cond) and pf in deps and pf not in am['BUILT_SOURCES']:
        pfb, pfext = split_filename(pf)
        sfb, sfext = split_filename(deps[pf][0])
        if sfext != pfext:
            if pfext in automake_ext:
                dist = None
                am['BUILT_SOURCES'].append(pf)
                am['CLEAN'].append(pf)
    b, ext = split_filename(pf)
    if ext in automake_ext:
        if ext in ['tab.c', 'tab.h']:
            dist = True
        return dist, pf
    return dist, ""
Esempio n. 2
0
def msc_dep(fd, tar, deplist, msc):
    t = msc_translate_ext(tar)
    b, ext = split_filename(t)
    tf = msc_translate_file(t, msc)
    sep = tf + ": "
    _in = []
    for d in deplist:
        if not os.path.isabs(d):
            dep = msc_translate_dir(
                msc_translate_ext(msc_translate_file(d, msc)), msc)
            if dep[-3:] == '.in':
                if dep not in msc['_IN']:
                    _in.append((d[:-3], dep))
                dep = d[:-3]
            if dep != t:
                fd.write('%s"%s"' % (sep, dep))
                sep = " "
        else:
            print("!WARNING: dropped absolute dependency " + d)
    if sep == " ":
        fd.write("\n")
    for x, y in _in:
        # TODO
        # replace this hack by something like configure ...
        fd.write('%s: "$(TOPDIR)\\winconfig_conds.py" "%s"\n' % (x, y))
        fd.write('\t$(CONFIGURE) "%s" > "%s"\n' % (y, x))
        msc['_IN'].append(y)
    getsrc = ""
    src = msc_translate_dir(
        msc_translate_ext(msc_translate_file(deplist[0], msc)), msc)
    if '\\' in src:
        getsrc = '\t$(INSTALL) "%s" "%s"\n' % (src, src.split('\\')[-1])
    if ext == "tab.h":
        fd.write(getsrc)
        x, de = split_filename(deplist[0])
        of = b + '.' + de
        fd.write(
            '\t$(BISON) -o %s.tmpc.c --defines=%s.tab.h $(YFLAGS) $(AM_YFLAGS) %s\n'
            % (b, b, of))
        fd.write('\trm -f %s.tmpc.c\n' % b)
    elif ext == "tab.c":
        fd.write(getsrc)
        x, de = split_filename(deplist[0])
        of = b + '.' + de
        fd.write(
            '\t$(BISON) -o %s.tab.c --defines=%s.tmph.h $(YFLAGS) $(AM_YFLAGS) %s\n'
            % (b, b, of))
        fd.write('\trm -f %s.tmph.h\n' % b)
    elif ext in ("obj", "tab.obj"):
        target, name = msc_find_target(tar, msc)
        if name[0] == '_':
            name = name[1:]
        if target == "LIB":
            d, dext = split_filename(deplist[0])
            if dext in ("c", "tab.c"):
                fd.write(
                    '\t$(CC) /EHsc $(CFLAGS) $(%s_CFLAGS) $(GENDLL) -D_CRT_SECURE_NO_WARNINGS -DLIB%s "-Fo%s" -c "%s"\n'
                    % (split_filename(msc_basename(src))[0], name, t, src))
    elif ext == 'res':
        fd.write("\t$(RC) -fo%s %s\n" % (t, src))
Esempio n. 3
0
def msc_find_hdrs(target, deps, hdrs):
    base, ext = split_filename(target)
    f = target
    pf = f
    while ext != "h" and f in deps:
        f = deps[f][0]
        b, ext = split_filename(f)
        if ext in automake_ext:
            pf = f
    return pf
Esempio n. 4
0
def msc_find_srcs(target, deps, msc):
    base, ext = split_filename(target)
    f = target
    pf = f
    while ext != "h" and f in deps:
        f = deps[f][0]
        b, ext = split_filename(f)
        if ext in automake_ext:
            pf = f
    # built source if has dep and ext != cur ext
    if pf in deps and pf not in msc['BUILT_SOURCES']:
        pfb, pfext = split_filename(pf)
        sfb, sfext = split_filename(deps[pf][0])
        if sfext != pfext:
            msc['BUILT_SOURCES'].append(pf)
    return pf
Esempio n. 5
0
def readfilepart(f, ext):
    dir, file = os.path.split(f)
    fn, fext = split_filename(file)
    src = open(f, 'r')
    buf = src.read()
    src.close()
    return buf
Esempio n. 6
0
def codegen(tree, cwd, topdir, incdirsmap):
    includes = {}
    incmap = {}
    if 'INCLUDES' in tree:
        includes, incmap = collect_includes(tree["INCLUDES"], cwd, topdir)

    deps = {}
    for i, v in tree.items():
        targets = []
        if type(v) is type({}) and "SOURCES" in v:
            for f in v["SOURCES"]:
                base, ext = split_filename(f)
                if f not in targets:
                    targets.append(f)
            targets = do_code_gen(targets, deps, code_gen)
            if i[0:4] == "lib_" or i == "LIBS":
                targets = do_code_gen(targets, deps, lib_code_gen)
            if i[0:4] == "bin_" or i == "BINS":
                targets = do_code_gen(targets, deps, bin_code_gen)
            do_deps(targets, deps, includes, incmap, cwd, incdirsmap)
            v["TARGETS"] = targets
            v["DEPS"] = deps

    for i, v in tree.items():
        if type(v) is type({}) and "SOURCES" in v:
            if i[0:4] == "lib_":
                lib = i[4:] + "_LIBS"
                if lib[0] == "_":
                    lib = lib[1:]
Esempio n. 7
0
def am_find_hdrs(am, map):
    if 'HEADERS' in map:
        hdrs_ext = map['HEADERS']
        for target in map['TARGETS']:
            t, ext = split_filename(target)
            if ext in hdrs_ext and not target in am['HDRS']:
                am['HDRS'].append(target)
            am_find_hdrs_r(am, target, map['DEPS'], am['HDRS'], hdrs_ext, map)
Esempio n. 8
0
def am_find_hdrs_r(am, target, deps, hdrs, hdrs_ext, map):
    if target in deps:
        tdeps = deps[target]
        for dtarget in tdeps:
            t, ext = split_filename(dtarget)
            org = find_org(deps, dtarget)
            if org in map['SOURCES']:
                if ext in hdrs_ext and dtarget not in hdrs and '/' not in dtarget:
                    hdrs.append(dtarget)
                am_find_hdrs_r(am, dtarget, deps, hdrs, hdrs_ext, map)
Esempio n. 9
0
def msc_find_target(target, msc):
    tree = msc['TREE']
    for t, v in tree.items():
        if type(v) is type({}) and 'TARGETS' in v:
            targets = v['TARGETS']
            if target in targets:
                if t == "BINS" or t[0:4] == "bin_":
                    return "BIN", "BIN"
                elif (t[0:4] == "lib_"):
                    return "LIB", t[4:].upper()
                elif t == "LIBS":
                    name, ext = split_filename(target)
                    return "LIB", name.upper()
    return "UNKNOWN", "UNKNOWN"
Esempio n. 10
0
def msc_headers(fd, var, headers, msc):

    sd = "includedir"
    if "DIR" in headers:
        sd = headers["DIR"][0]  # use first name given
    sd = msc_translate_dir(sd, msc)

    hdrs_ext = headers['HEADERS']
    deps = []
    for d, srcs in headers['DEPS'].items():
        for s in srcs:
            if s in headers['SOURCES']:
                deps.append(d)
                break
    for header in uniq(headers['TARGETS'] + deps):
        h, ext = split_filename(header)
        if ext in hdrs_ext:
            if os.path.isfile(os.path.join(msc['cwd'], header + '.in')):
                inf = '$(srcdir)\\%s.in' % header
                if inf not in msc['_IN']:
                    # TODO
                    # replace this hack by something like configure ...
                    fd.write('%s: "$(TOPDIR)\\winconfig_conds.py" "%s"\n' %
                             (header, inf))
                    fd.write('\t$(CONFIGURE) "%s" > "%s"\n' % (inf, header))
                    msc['_IN'].append(inf)
            elif os.path.isfile(os.path.join(msc['cwd'], header)):
                fd.write('%s: "$(srcdir)\\%s"\n' % (header, header))
                ##                fd.write('\t$(INSTALL) "$(srcdir)\\%s" "%s"\n' % (header, header))
                ##                fd.write('\tif not exist "%s" if exist "$(srcdir)\\%s" $(INSTALL) "$(srcdir)\\%s" "%s"\n' % (header, header, header, header))
                fd.write('\t$(INSTALL) "$(srcdir)\\%s" "%s"\n' %
                         (header, header))
            if 'COND' in headers:
                condname = 'defined(' + ') && defined('.join(
                    headers['COND']) + ')'
                mkname = header.replace('.', '_').replace('-', '_')
                fd.write('!IF %s\n' % condname)
                fd.write('C_%s = %s\n' % (mkname, header))
                fd.write('!ELSE\n')
                fd.write('C_%s =\n' % mkname)
                fd.write('!ENDIF\n')
                cheader = '$(C_%s)' % mkname
            else:
                cheader = header
                condname = ''
            msc['INSTALL'][header] = header, '', sd, '', condname
            msc['SCRIPTS'].append(header)
            if header not in headers['SOURCES']:
                msc['BUILT_SOURCES'].append(cheader)
Esempio n. 11
0
def am_headers(fd, var, headers, am):

    sd = "includedir"
    if "DIR" in headers:
        sd = headers["DIR"][0] # use first name given
    sd = am_translate_dir(sd, am)

    hdrs_ext = headers['HEADERS']
    deps = []
    for d,srcs in headers['DEPS'].items():
        for s in srcs:
            if s in headers['SOURCES']:
                deps.append(d)
                break
    for header in uniq(headers['TARGETS'] + deps):
        h, ext = split_filename(header)
        if ext not in hdrs_ext:
            continue
        cond = ''
        h = header
        if 'COND' in headers:
            cond = '#' + '+'.join(headers['COND'])
            mkname = am_normalize(header.replace('.', '_'))
            for condname in headers['COND']:
                fd.write('if %s\n' % condname)
            fd.write('C_%s = %s\n' % (mkname, header))
            h = '$(C_%s)' % mkname
            for condname in headers['COND']:
                fd.write('endif\n')
        if cond:
            fd.write("uninstall-local-:\n")
            fd.write("install-exec-local-:\n")
        fd.write("install-exec-local-%s: %s\n" % (header, header))
        fd.write("\t-mkdir -p $(DESTDIR)%s\n" % sd)
        fd.write("\t-$(RM) $(DESTDIR)%s/%s\n" % (sd, header))
        fd.write("\t$(INSTALL_DATA) $< $(DESTDIR)%s/%s\n\n" % (sd, header))
        fd.write("uninstall-local-%s: \n" % header)
        fd.write("\t$(RM) $(DESTDIR)%s/%s\n\n" % (sd, header))
        am['INSTALL'].append(h)
        am['UNINSTALL'].append(h)
        if header not in headers['SOURCES']:
            am['BUILT_SOURCES'].append(h)
            am['CLEAN'].append(h)
        am['InstallList'].append("\t%s/%s%s\n" % (sd, header, cond))

    am_find_ins(am, headers)
    am_deps(fd, headers['DEPS'], am)
    for src in headers['SOURCES']:
        am['EXTRA_DIST'].append(src)
Esempio n. 12
0
def do_scan_target(target, targets, deps, incmap, cwd, incs):
    base, ext = split_filename(target)
    if target not in incs:
        inc_files = []
        if ext in scan_map:
            org = os.path.join(cwd, find_org(deps, target))
            if os.path.exists(org):
                b = readfilepart(org, ext)
                pat, sep, incext = scan_map[ext]
                res = pat.search(b)
                while res is not None:
                    p, e = res.span('fnd')
                    if sep is not None:
                        ressep = sep.search(b, p, e)
                        while ressep is not None:
                            n = ressep.start(0)
                            fnd1 = b[p:n]
                            p = ressep.end(0)  # start of next file
                            if fnd1 + incext in deps or fnd1 + incext in targets:
                                if fnd1 + incext not in inc_files:
                                    inc_files.append(fnd1 + incext)
                            elif fnd1 + incext in incmap:
                                if fnd1 + incext not in inc_files:
                                    inc_files.append(
                                        os.path.join(incmap[fnd1 + incext],
                                                     fnd1 + incext))
                            ressep = sep.search(b, p, e)
                    fnd = b[p:e]
                    if fnd + incext in deps or fnd + incext in targets:
                        if fnd + incext not in inc_files:
                            inc_files.append(fnd + incext)
                    elif fnd + incext in incmap:
                        if fnd + incext not in inc_files:
                            inc_files.append(
                                os.path.join(incmap[fnd + incext],
                                             fnd + incext))
                    elif os.path.exists(os.path.join(cwd, fnd + incext)):
                        if fnd + incext not in inc_files:
                            inc_files.append(fnd + incext)
                        if fnd + incext not in incs:
                            incs[fnd + incext] = []


##                     else:
##                         print fnd + incext + " not in deps or incmap"
                    res = pat.search(b, res.end(0))
        incs[target] = inc_files
Esempio n. 13
0
def do_code_gen(targets, deps, code_map):
    changes = 1
    while changes:
        ntargets = []
        changes = 0
        for f in targets:
            base, ext = split_filename(f)
            if ext in code_map:
                changes = 1
                for newext in code_map[ext]:
                    newtarget = base + newext
                    if newtarget not in ntargets:
                        ntargets.append(newtarget)
                    if newtarget in deps:
                        if (f not in deps[newtarget]):
                            deps[newtarget].append(f)
                    else:
                        deps[newtarget] = [f]
            elif f not in ntargets:
                ntargets.append(f)
        targets = ntargets
    return targets
Esempio n. 14
0
def am_binary(fd, var, binmap, am):

    if type(binmap) == type([]):
        name = var[4:]
        if name == 'SCRIPTS':
            for script in binmap:
                if script not in am['BIN_SCRIPTS']:
                    am['BIN_SCRIPTS'].append(script)
            am['INSTALL'].append(name)
            am['UNINSTALL'].append(name)
            am['ALL'].append(name)
            for i in binmap:
                am['InstallList'].append("\t$(bindir)/%s\n" % i)
        else: # link
            binmap = binmap[0]
            if '?' in binmap:
                cond, binmap = binmap.split('?', 1)
            else:
                cond = ''
            src = binmap[4:]
            if cond:
                fd.write('if %s\n' % cond)
                cond = '#'+cond
            fd.write("install-exec-local-%s: %s\n" % (name, src))
            fd.write("\t-mkdir -p $(DESTDIR)$(bindir)\n")
            fd.write("\t-$(RM) $(DESTDIR)$(bindir)/%s\n" % name)
            fd.write("\tcd $(DESTDIR)$(bindir); $(LN_S) %s %s\n\n" % (src, name))
            fd.write("uninstall-local-%s: \n" % name)
            fd.write("\t$(RM) $(DESTDIR)$(bindir)/%s\n\n" % name)
            am['INSTALL'].append(name)
            am['UNINSTALL'].append(name)
            am['InstallList'].append("\t$(bindir)/"+name+cond+"\n")

            fd.write("all-local-%s: %s\n" % (name, src))
            fd.write("\t-$(RM) %s\n" % name)
            fd.write("\t$(LN_S) %s %s\n\n" % (src, name))
            am['CLEAN'].append(name)
            if cond:
                fd.write('else\n')
                fd.write("install-exec-local-%s:\n" % name)
                fd.write("uninstall-local-%s:\n" % name)
                fd.write("all-local-%s:\n" % name)
                fd.write('endif\n')
            am['ALL'].append(name)
        return

    SCRIPTS = []
    scripts_ext = []
    if 'SCRIPTS' in binmap:
        scripts_ext = binmap['SCRIPTS']

    name = var[4:]
    if "NAME" in binmap:
        binname = binmap['NAME'][0]
    else:
        binname = name
    norm_binname = am_normalize(binname)

    bd = 'bindir'
    if "DIR" in binmap:
        bd = binmap["DIR"][0] # use first name given
    bd = am_translate_dir(bd, am)
    fd.write("%sdir = %s\n" % (norm_binname, bd))

    cname = name
    cond = ''
    if 'COND' in binmap:
        for condname in binmap['COND']:
            fd.write("if %s\n" % condname)
        cond = '#' + '+'.join(binmap['COND'])
        fd.write(" C_%s = %s\n" % (name,name))
        fd.write(" %s_PROGRAMS =%s\n" % (norm_binname,  binname))
        for condname in binmap['COND']:
            fd.write("endif\n")
        cname = "$(C_" + name + ")"
    elif 'CONDINST' in binmap:
        for condname in binmap['CONDINST']:
            fd.write("if %s\n" % condname)
        cond = '#' + '+'.join(binmap['CONDINST'])
        fd.write(" C_inst_%s = %s\n" % (name, name))
        fd.write(" C_noinst_%s = \n" % (name))
        for condname in binmap['CONDINST']:
            fd.write("endif\n")

        for condname in binmap['CONDINST']:
            fd.write("if !%s\n" % condname)
        fd.write(" C_inst_%s = \n" % (name))
        fd.write(" C_noinst_%s = %s\n" % (name, name))
        for condname in binmap['CONDINST']:
            fd.write("endif\n")
        cname = "$(C_inst_" + name + ")"
        am['BINS'].append(cname)
        cname = "$(C_noinst_" + name + ")"
        am['NBINS'].append(cname)
        cname = ''
    elif 'NOINST' in binmap:
        am['NBINS'].append(binname)
    else:
        am['BINS'].append(binname)

    am['InstallList'].append("\t%s/%s%s\n" % (bd, binname, cond))

    if 'MTSAFE' in binmap:
        fd.write("CFLAGS %s $(THREAD_SAVE_FLAGS)\n" % am_assign)

    if "LIBS" in binmap:
        fd.write(am_additional_libs(norm_binname, "", "BIN", binmap["LIBS"], am))

    if "LDFLAGS" in binmap:
        ldflags = binmap["LDFLAGS"][:]
    else:
        ldflags = []
    ldflags.append('-export-dynamic')
    if 'NOINST' in binmap:
        ldflags.append('-no-install')
    fd.write(am_additional_flags(norm_binname, "", "BIN", ldflags, am))

    for src in binmap['SOURCES']:
        base, ext = split_filename(src)
        am['EXTRA_DIST'].append(src)

    nsrcs = "nodist_"+norm_binname+"_SOURCES ="
    srcs = "dist_"+norm_binname+"_SOURCES ="
    for target in binmap['TARGETS']:
        t, ext = split_filename(target)
        if ext in scripts_ext:
            if target not in SCRIPTS:
                SCRIPTS.append(target)
        elif ext in ('o', 'tab.o'):
            dist, src = am_find_srcs(target, binmap['DEPS'], am, cond)
            if src in binmap['SOURCES']:
                dist = True
            if dist:
                srcs = srcs + " " + src
            else:
                nsrcs = nsrcs + " " + src

    fd.write(nsrcs + "\n")
    fd.write(srcs + "\n")
    if len(SCRIPTS) > 0:
        fd.write("%s_scripts =%s\n" % (norm_binname, am_list2string(SCRIPTS, " ", "")))
        am['BUILT_SOURCES'].append("$(" + name + "_scripts)")
        fd.write("all-local-%s: $(%s_scripts)\n" % (name, name))
        am['ALL'].append(cname)

    am_find_hdrs(am, binmap)
    am_find_ins(am, binmap)

    am_deps(fd, binmap['DEPS'], am)
Esempio n. 15
0
def am_bins(fd, var, binsmap, am):

    lbins = []
    scripts_ext = []
    if 'SCRIPTS' in binsmap:
        scripts_ext = binsmap['SCRIPTS']

    name = ""
    if "NAME" in binsmap:
        name = binsmap["NAME"][0] # use first name given
    if 'MTSAFE' in binsmap:
        fd.write("CFLAGS %s $(THREAD_SAVE_FLAGS)\n" % am_assign)
    for binsrc in binsmap['SOURCES']:
        SCRIPTS = []
        bin, ext = split_filename(binsrc)
        am['EXTRA_DIST'].append(binsrc)

        if 'CONDINST' in binsmap:
            for condname in binsmap['CONDINST']:
                fd.write("if %s\n" % condname)
            cond = '#' + '+'.join(binsmap['CONDINST'])
            fd.write(" C_inst_%s = %s\n" % (bin, bin))
            fd.write(" C_noinst_%s = \n" % (bin))
            for condname in binsmap['CONDINST']:
                fd.write("endif\n")

            for condname in binsmap['CONDINST']:
                fd.write("if !%s\n" % condname)
            cond = '#!' + '+'.join(binsmap['CONDINST'])
            fd.write(" C_inst_%s = \n" % (bin))
            fd.write(" C_noinst_%s = %s\n" % (bin, bin))
            for condname in binsmap['CONDINST']:
                fd.write("endif\n")
            cname = "$(C_inst_" + bin + ")"
            am['BINS'].append(cname)
            cname = "$(C_noinst_" + bin + ")"
            am['NBINS'].append(cname)
            cname = ''
        elif 'NOINST' in binsmap:
            am['NBINS'].append(bin)
        else:
            am['BINS'].append(bin)
            if "DIR" in binsmap:
                lbins.append(bin)

        if bin + "_LIBS" in binsmap:
            fd.write(am_additional_libs(bin, "", "BIN", binsmap[bin + "_LIBS"], am))
        elif "LIBS" in binsmap:
            fd.write(am_additional_libs(bin, "", "BIN", binsmap["LIBS"], am))

        if "LDFLAGS" in binsmap:
            ldflags = binsmap["LDFLAGS"][:]
        else:
            ldflags = []
        ldflags.append('-export-dynamic')
        if 'NOINST' in binsmap:
            ldflags.append('-no-install')
        fd.write(am_additional_flags(bin, "", "BIN", ldflags, am))

        nsrcs = "nodist_"+am_normalize(bin)+"_SOURCES ="
        srcs = "dist_"+am_normalize(bin)+"_SOURCES ="
        for target in binsmap['TARGETS']:
            t, ext = split_filename(target)
            if t == bin:
                t, ext = split_filename(target)
                if ext in scripts_ext:
                    if target not in SCRIPTS:
                        SCRIPTS.append(target)
                else:
                    dist, src = am_find_srcs(target, binsmap['DEPS'], am, None)
                    if src == binsrc:
                        dist = True
                    if dist:
                        srcs = srcs + " " + src
                    else:
                        nsrcs = nsrcs + " " + src
        fd.write(nsrcs + "\n")
        fd.write(srcs + "\n")

        if len(SCRIPTS) > 0:
            fd.write("%s_scripts = %s\n\n" % (name, am_list2string(SCRIPTS, " ", "")))
            am['BUILT_SOURCES'].append("$(" + name + "_scripts)")
            fd.write("all-local-%s: $(%s_scripts)\n" % (name, name))
            am['ALL'].append(name)

    if (len(lbins) > 0):
        bd = binsmap["DIR"][0] # use first name given
        bd = am_translate_dir(bd, am)
        fd.write("%sdir = %s\n" % (bin, bd))
        fd.write("%s_PROGRAMS =%s\n" % (bin,  am_list2string(lbins, " ", "") ))
        for bn in lbins:
            am['InstallList'].append("\t%s/%s\n" % (bd, bn))

    if 'HEADERS' in binsmap:
        HDRS = []
        hdrs_ext = binsmap['HEADERS']
        for target in binsmap['DEPS'].keys():
            t, ext = split_filename(target)
            if ext in hdrs_ext:
                am['HDRS'].append(target)
                if ext not in automake_ext:
                    am['EXTRA_DIST'].append(target)

    am_find_ins(am, binsmap)
    am_deps(fd, binsmap['DEPS'], am)
Esempio n. 16
0
def msc_library(fd, var, libmap, msc):

    name = var[4:]
    sep = ""
    pref = 'lib'
    dll = '.dll'
    pdb = '.pdb'
    if "NAME" in libmap:
        libname = libmap['NAME'][0]
    else:
        libname = name

    if 'PREFIX' in libmap:
        if libmap['PREFIX']:
            pref = libmap['PREFIX'][0]
        else:
            pref = ''
    instlib = 1

    if (libname[0] == "_"):
        sep = "_"
        libname = libname[1:]
    if 'SEP' in libmap:
        sep = libmap['SEP'][0]

    lib = "lib"
    ld = "LIBDIR"
    if "DIR" in libmap:
        lib = libname
        ld = libmap["DIR"][0]  # use first name given
    ld = msc_translate_dir(ld, msc)

    HDRS = []
    hdrs_ext = []
    if 'HEADERS' in libmap:
        hdrs_ext = libmap['HEADERS']

    SCRIPTS = []
    scripts_ext = []
    if 'SCRIPTS' in libmap:
        scripts_ext = libmap['SCRIPTS']

    v = sep + libname
    makedll = pref + v + dll
    if 'NOINST' in libmap or 'NOINST_MSC' in libmap:
        if "LIBS" in libmap or "WINLIBS" in libmap:
            print("!WARNING: no sense in having a LIBS section with NOINST")
        makelib = pref + v + '.lib'
    else:
        makelib = makedll
    if 'COND' in libmap:
        condname = 'defined(' + ') && defined('.join(libmap['COND']) + ')'
        mkname = (pref + v).replace('.', '_').replace('-', '_')
        fd.write('!IF %s\n' % condname)
        fd.write('C_%s_dll = %s%s%s\n' % (mkname, pref, v, dll))
        fd.write('C_%s_lib = %s%s.lib\n' % (mkname, pref, v))
        fd.write('!ELSE\n')
        fd.write('C_%s_dll =\n' % mkname)
        fd.write('C_%s_lib =\n' % mkname)
        fd.write('!ENDIF\n')
        makelib = '$(C_%s_lib)' % mkname
        makedll = '$(C_%s_dll)' % mkname
    else:
        condname = ''

    if 'NOINST' in libmap or 'NOINST_MSC' in libmap:
        msc['NLIBS'].append(makelib)
    else:
        msc['LIBS'].append(makelib)
        if instlib:
            i = pref + v + '.lib'
        else:
            i = ''
        if ld != 'LIBDIR':
            msc['INSTALL'][pref + v] = makedll, dll, ld, i, condname
        else:
            msc['INSTALL'][pref + v] = makedll, dll, '$(%sdir)' % lib.replace(
                '-', '_'), i, condname

    if 'MTSAFE' in libmap:
        fd.write("CFLAGS=$(CFLAGS) $(thread_safe_flag_spec)\n")

    dlib = []
    if libname + "_DLIBS" in libmap:
        dlib = libmap[libname + "_DLIBS"]
    liblist = []
    if "LIBS" in libmap:
        liblist = liblist + libmap["LIBS"]
    if "WINLIBS" in libmap:
        liblist = liblist + libmap["WINLIBS"]
    if liblist:
        msc_additional_libs(fd, libname, sep, "LIB", liblist, dlib, msc, pref,
                            dll)

    for src in libmap['SOURCES']:
        base, ext = split_filename(src)
        #if ext not in automake_ext:
        msc['EXTRA_DIST'].append(src)

    srcs = '%s%s%s_OBJS =' % (pref, sep, libname)
    deps = '%s%s%s_DEPS = $(%s%s%s_OBJS)' % (pref, sep, libname, pref, sep,
                                             libname)
    for dep in libmap.get('XDEPS', []):
        deps = deps + ' ' + dep
    deffile = ''
    for target in libmap['TARGETS']:
        if target == "@LIBOBJS@":
            srcs = srcs + " $(LIBOBJS)"
        else:
            t, ext = split_filename(target)
            if ext == "o":
                srcs = srcs + " " + t + ".obj"
            elif ext == "tab.o":
                srcs = srcs + " " + t + ".tab.obj"
            elif ext == "yy.o":
                srcs = srcs + " " + t + ".yy.obj"
            elif ext == "pm.o":
                srcs = srcs + " " + t + ".pm.obj"
            elif ext == 'res':
                srcs = srcs + " " + t + ".res"
            elif ext in hdrs_ext:
                HDRS.append(target)
            elif ext in scripts_ext:
                if target not in SCRIPTS:
                    SCRIPTS.append(target)
            elif ext == 'def':
                deffile = ' "-DEF:%s"' % target
                deps = deps + " " + target
    fd.write(srcs + "\n")
    fd.write(deps + "\n")
    ln = pref + sep + libname
    if 'NOINST' in libmap or 'NOINST_MSC' in libmap:
        ln_ = ln.replace('-', '_')
        fd.write("%s.lib: $(%s_DEPS)\n" % (ln, ln_))
        fd.write('\t$(ARCHIVER) /out:"%s.lib" $(%s_OBJS) $(%s_LIBS)\n' %
                 (ln, ln_, ln_))
    else:
        fd.write("%s.lib: %s%s\n" % (ln, ln, dll))
        fd.write("%s%s: $(%s_DEPS) \n" % (ln, dll, ln.replace('-', '_')))
        fd.write(
            '\tpython "$(TOPDIR)\\..\\NT\\wincompile.py" $(CC) $(CFLAGS) -LD -Fe%s%s @<< /link @<<\n$(%s_OBJS)\n<<\n$(%s_LIBS)%s\n<<\n'
            % (ln, dll, ln.replace('-', '_'), ln.replace('-', '_'), deffile))
        fd.write(
            "\tif exist [email protected] $(MT) -manifest [email protected] -outputresource:$@;2\n"
        )
    fd.write("\n")

    if SCRIPTS:
        fd.write(
            libname.replace('-', '_') + "_SCRIPTS =" +
            msc_space_sep_list(SCRIPTS))
        msc['BUILT_SOURCES'].append("$(" + name.replace('-', '_') +
                                    "_SCRIPTS)")

    if 'HEADERS' in libmap:
        for h in HDRS:
            msc['HDRS'].append(h)

    msc_deps(fd, libmap['DEPS'], ".obj", msc)
Esempio n. 17
0
def msc_bins(fd, var, binsmap, msc):

    HDRS = []
    hdrs_ext = []
    if 'HEADERS' in binsmap:
        hdrs_ext = binsmap['HEADERS']

    SCRIPTS = []
    scripts_ext = []
    if 'SCRIPTS' in binsmap:
        scripts_ext = binsmap['SCRIPTS']

    name = ""
    if "NAME" in binsmap:
        name = binsmap["NAME"][0]  # use first name given
    if 'MTSAFE' in binsmap:
        fd.write("CFLAGS=$(CFLAGS) $(thread_safe_flag_spec)\n")

    for binsrc in binsmap['SOURCES']:
        bin, ext = split_filename(binsrc)
        #if ext not in automake_ext:
        msc['EXTRA_DIST'].append(binsrc)
        bin2 = bin.replace('-', '_')

        if "DIR" in binsmap:
            bd = binsmap["DIR"][0]  # use first name given
            fd.write("%sdir = %s\n" % (bin2, msc_translate_dir(bd, msc)))
        else:
            fd.write("%sdir = $(bindir)\n" % (bin2))

        if 'CONDINST' in binsmap:
            condname = 'defined(' + ') && defined('.join(
                binsmap['CONDINST']) + ')'
            fd.write('!IF %s\n' % condname)
            fd.write('C_inst_%s_exe = %s.exe\n' % (bin2, bin))
            fd.write('C_noinst_%s_exe = \n' % (bin2))
            fd.write('!ELSE\n')
            fd.write('C_inst_%s_exe = \n' % (bin2))
            fd.write('C_noinst_%s_exe = %s.exe\n' % (bin2, bin))
            fd.write('!ENDIF\n')
            msc['BINS'].append((bin, '$(C_inst_%s_exe)' % bin2, condname))
            condname = '!defined(' + ') && !defined('.join(
                binsmap['CONDINST']) + ')'
            msc['NBINS'].append((bin, '$(C_noinst_%s_exe)' % bin2, condname))
        elif 'NOINST' in binsmap:
            msc['NBINS'].append((bin, bin, ''))
        else:
            msc['BINS'].append((bin, bin, ''))

        if bin + "_LIBS" in binsmap:
            msc_additional_libs(fd, bin, "", "BIN", binsmap[bin + "_LIBS"], [],
                                msc, '', '.exe')
        else:
            binslist = []
            if "LIBS" in binsmap:
                binslist = binslist + binsmap["LIBS"]
            if "WINLIBS" in binsmap:
                binslist = binslist + binsmap["WINLIBS"]
            if binslist:
                msc_additional_libs(fd, bin, "", "BIN", binslist, [], msc, '',
                                    '.exe')

        srcs = bin + "_OBJS ="
        for target in binsmap['TARGETS']:
            t, ext = split_filename(target)
            if t == bin:
                t, ext = split_filename(target)
                if ext == "o":
                    srcs = srcs + " " + t + ".obj"
                elif ext == "tab.o":
                    srcs = srcs + " " + t + ".tab.obj"
                elif ext == "yy.o":
                    srcs = srcs + " " + t + ".yy.obj"
                elif ext == 'res':
                    srcs = srcs + " " + t + ".res"
                elif ext in hdrs_ext:
                    HDRS.append(target)
                elif ext in scripts_ext:
                    if target not in SCRIPTS:
                        SCRIPTS.append(target)
        fd.write(srcs + "\n")
        fd.write("%s.exe: $(%s_OBJS)\n" % (bin, bin.replace('-', '_')))
        fd.write('\t$(CC) $(CFLAGS)')
        fd.write(
            " -Fe%s.exe $(%s_OBJS) /link $(%s_LIBS) /subsystem:console /NODEFAULTLIB:LIBC\n"
            % (bin, bin.replace('-', '_'), bin.replace('-', '_')))
        fd.write(
            "\tif exist [email protected] $(MT) -manifest [email protected] -outputresource:$@;1\n\n"
        )

    if SCRIPTS:
        fd.write(
            name.replace('-', '_') + "_SCRIPTS =" +
            msc_space_sep_list(SCRIPTS))
        msc['BUILT_SOURCES'].append("$(" + name.replace('-', '_') +
                                    "_SCRIPTS)")

    if 'HEADERS' in binsmap:
        for h in HDRS:
            msc['HDRS'].append(h)

    msc_deps(fd, binsmap['DEPS'], ".obj", msc)
Esempio n. 18
0
def am_library(fd, var, libmap, am):
    name = var[4:]

    sep = ""
    pref = 'lib'
    if "NAME" in libmap:
        libname = libmap['NAME'][0]
    else:
        libname = name

    if "PREFIX" in libmap:
        if libmap['PREFIX']:
            pref = libmap['PREFIX'][0]
        else:
            pref = ''

    if libname[0] == "_":
        sep = "_"
        libname = libname[1:]
    if 'SEP' in libmap:
        sep = libmap['SEP'][0]

    cname = libname
    cond = ''
    condname = ''
    if 'COND' in libmap:
        if len(libmap['COND']) == 1 and libmap['COND'][0] in ('WIN32', 'NATIVE_WIN32'):
            return
        for condname in libmap['COND']:
            fd.write("if %s\n" % condname)
        fd.write(" C_%s = %s\n" % (libname, libname))
        cname = "$(C_" + libname + ")"
        cond = '#' + condname

    if name[0] == '_':
        name = name[1:]
    fd.write("lib%s%s_la_CFLAGS=-DLIB%s $(AM_CFLAGS)\n" % (sep,libname,name.upper()))

    ld = "libdir"
    if "DIR" in libmap:
        ld = libmap["DIR"][0] # use first name given

    SCRIPTS = []
    scripts_ext = []
    if 'SCRIPTS' in libmap:
        scripts_ext = libmap['SCRIPTS']

    ld = am_translate_dir(ld, am)
    fd.write("%sdir = %s\n" % (libname, ld))
    if 'NOINST' in libmap:
        am['NLIBS'].append((pref, libname, sep))
    else:
        am['LIBS'].append((pref, libname, sep, libmap.get('COND', ())))
        am['InstallList'].append("\t%s/%s%s%s.so%s\n" % (ld, pref, sep, libname, cond))

    if 'MTSAFE' in libmap:
        fd.write("CFLAGS %s $(THREAD_SAVE_FLAGS)\n" % am_assign)

    if "LIBS" in libmap:
        fd.write(am_additional_libs(libname, sep, "LIB", libmap["LIBS"], am, pref))
        fd.write(am_additional_install_libs(libname, sep, libmap["LIBS"], am))

    ldflags = []
    if 'MODULE' in libmap:
        ldflags.append('-module')
        ldflags.append('-avoid-version')
    if 'NOINST' not in libmap:
        ldflags.append('@NO_UNDEFINED@')
    if "LDFLAGS" in libmap:
        for x in libmap["LDFLAGS"]:
            ldflags.append(x)
    if 'VERSION' in libmap:
        ldflags.append('-version-info')
        ldflags.append(libmap['VERSION'][0])

    for src in libmap['SOURCES']:
        base, ext = split_filename(src)
        am['EXTRA_DIST'].append(src)

    if cond:
        for condname in libmap['COND']:
            fd.write("endif\n")

    fullpref = pref+sep+libname+'_la'
    nsrcs = "nodist_"+fullpref+"_SOURCES ="
    srcs = "dist_"+fullpref+"_SOURCES ="
    deps = []
    for target in libmap['TARGETS']:
        t, ext = split_filename(target)
        if ext in scripts_ext:
            if target not in SCRIPTS:
                SCRIPTS.append(target)
        else:
            dist, src = am_find_srcs(target, libmap['DEPS'], am, cond)
            if src in libmap['SOURCES']:
                dist = True
            if dist:
                srcs = srcs + " " + src
            else:
                nsrcs = nsrcs + " " + src
            if target[-2:] == '.o' and target in libmap['DEPS']:
                am_dep(fd, target, libmap['DEPS'][target], am, fullpref+"-")
                basename = target[:-2]
                fd.write('\t$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(%s_CFLAGS) $(CFLAGS) $(%s_CFLAGS) -c -o %s-%s.lo `test -f \'%s.c\' || echo \'$(srcdir)/\'`%s.c\n' % (fullpref, basename, fullpref, basename, basename, basename))
            elif target[-4:] == '.def':
                ldflags.append("-export-symbols")
                ldflags.append(target)
                deps.append(target)
    fd.write(nsrcs + "\n")
    fd.write(srcs + "\n")
    if 'XDEPS' in libmap:
        fd.write(fullpref + '_DEPENDENCIES =')
        for dep in libmap['XDEPS']:
            fd.write(' ')
            fd.write(dep)
        fd.write('\n')

    if deps:
        fd.write(am_additional_deps(libname, sep, "LIB", deps, am, pref))
    if ldflags:
        fd.write(am_additional_flags(libname, sep, "LIB", ldflags, am, pref))

    if len(SCRIPTS) > 0:
        fd.write("%s_scripts = %s\n" % (libname, am_list2string(SCRIPTS, " ", "")))
        am['BUILT_SOURCES'].append("$(" + libname + "_scripts)")
        fd.write("all-local-%s: $(%s_scripts)\n" % (libname, libname))
        am['ALL'].append(cname)

    am_find_hdrs(am, libmap)
    am_find_ins(am, libmap)

    am_deps(fd, libmap['DEPS'], am)
Esempio n. 19
0
def msc_binary(fd, var, binmap, msc):

    if type(binmap) == type([]):
        name = var[4:]
        if name == 'SCRIPTS':
            for i in binmap:
                if os.path.isfile(os.path.join(msc['cwd'], i + '.in')):
                    # TODO
                    # replace this hack by something like configure ...
                    fd.write(
                        '%s: "$(TOPDIR)\\winconfig_conds.py" "$(srcdir)\\%s.in"\n'
                        % (i, i))
                    fd.write('\t$(CONFIGURE) "$(srcdir)\\%s.in" > "%s"\n' %
                             (i, i))
                elif os.path.isfile(os.path.join(msc['cwd'], i)):
                    fd.write('%s: "$(srcdir)\\%s"\n' % (i, i))
                    fd.write('\t$(INSTALL) "$(srcdir)\\%s" "%s"\n' % (i, i))
                msc['INSTALL'][i] = i, '', '$(bindir)', '', ''
        else:  # link
            binmap = binmap[0]
            if '?' in binmap:
                cond, binmap = binmap.split('?', 1)
                condname = 'defined(%s)' % cond
            else:
                cond = condname = ''
            src = binmap[4:]
            if cond:
                fd.write('!IF %s\n' % condname)
            fd.write('%s: "%s"\n' % (name, src))
            fd.write('\t$(CP) "%s" "%s"\n\n' % (src, name))
            if cond:
                fd.write('!ELSE\n')
                fd.write('%s:\n' % name)
                fd.write('!ENDIF\n')
            n_nme, n_ext = split_filename(name)
            s_nme, s_ext = split_filename(src)
            if n_ext and s_ext and n_ext == s_ext:
                ext = ''
            else:
                ext = '.exe'
            msc['INSTALL'][name] = src + ext, ext, '$(bindir)', '', condname
            msc['SCRIPTS'].append(name)
        return

    if 'MTSAFE' in binmap:
        fd.write("CFLAGS=$(CFLAGS) $(thread_safe_flag_spec)\n")

    HDRS = []
    hdrs_ext = []
    if 'HEADERS' in binmap:
        hdrs_ext = binmap['HEADERS']

    SCRIPTS = []
    scripts_ext = []
    if 'SCRIPTS' in binmap:
        scripts_ext = binmap['SCRIPTS']

    name = var[4:]
    if "NAME" in binmap:
        binname = binmap['NAME'][0]
    else:
        binname = name
    binname2 = binname.replace('-', '_').replace('.', '_')

    if 'COND' in binmap:
        condname = 'defined(' + ') && defined('.join(binmap['COND']) + ')'
        fd.write('!IF %s\n' % condname)
        fd.write('C_%s_exe = %s.exe\n' % (binname2, binname))
        msc['BINS'].append((binname, '$(C_%s_exe)' % binname2, condname))
    elif 'CONDINST' in binmap:
        condname = 'defined(' + ') && defined('.join(binmap['CONDINST']) + ')'
        fd.write('!IF %s\n' % condname)
        fd.write('C_inst_%s_exe = %s.exe\n' % (binname2, binname))
        fd.write('C_noinst_%s_exe = \n' % (binname2))
        fd.write('!ELSE\n')
        fd.write('C_inst_%s_exe = \n' % (binname2))
        fd.write('C_noinst_%s_exe = %s.exe\n' % (binname2, binname))
        fd.write('!ENDIF\n')
        msc['BINS'].append((binname, '$(C_inst_%s_exe)' % binname2, condname))
        condname = '!defined(' + ') && !defined('.join(
            binmap['CONDINST']) + ')'
        msc['NBINS'].append(
            (binname, '$(C_noinst_%s_exe)' % binname2, condname))
    else:
        condname = ''
        if 'NOINST' in binmap:
            msc['NBINS'].append((binname, binname, condname))
        else:
            msc['BINS'].append((binname, binname, condname))

    if "DIR" in binmap:
        bd = binmap["DIR"][0]  # use first name given
        fd.write("%sdir = %s\n" % (binname2, msc_translate_dir(bd, msc)))
    else:
        fd.write("%sdir = $(bindir)\n" % binname2)

    binlist = []
    if "LIBS" in binmap:
        binlist = binlist + binmap["LIBS"]
    if "WINLIBS" in binmap:
        binlist = binlist + binmap["WINLIBS"]
    if binlist:
        msc_additional_libs(fd, binname, "", "BIN", binlist, [], msc, '',
                            '.exe')

    srcs = binname2 + "_OBJS ="
    for target in binmap['TARGETS']:
        t, ext = split_filename(target)
        if ext == "o":
            srcs = srcs + " " + t + ".obj"
        elif ext == "tab.o":
            srcs = srcs + " " + t + ".tab.obj"
        elif ext == "yy.o":
            srcs = srcs + " " + t + ".yy.obj"
        elif ext == 'def':
            srcs = srcs + ' ' + target
        elif ext == 'res':
            srcs = srcs + " " + t + ".res"
        elif ext in hdrs_ext:
            HDRS.append(target)
        elif ext in scripts_ext:
            if target not in SCRIPTS:
                SCRIPTS.append(target)
    fd.write(srcs + "\n")
    fd.write("%s.exe: $(%s_OBJS)\n" % (binname, binname2))
    fd.write('\t$(CC) $(CFLAGS)')
    fd.write(
        " -Fe%s.exe $(%s_OBJS) /link $(%s_LIBS) /subsystem:console /NODEFAULTLIB:LIBC\n"
        % (binname, binname2, binname2))
    fd.write("\t$(EDITBIN) $@ /HEAP:1048576,1048576 /LARGEADDRESSAWARE\n")
    fd.write(
        "\tif exist [email protected] $(MT) -manifest [email protected] -outputresource:$@;1\n"
    )
    fd.write('\n')

    if SCRIPTS:
        fd.write(binname2 + "_SCRIPTS =" + msc_space_sep_list(SCRIPTS))
        msc['BUILT_SOURCES'].append("$(" + binname2 + "_SCRIPTS)")

    if 'HEADERS' in binmap:
        for h in HDRS:
            msc['HDRS'].append(h)

    msc_deps(fd, binmap['DEPS'], ".obj", msc)