#!/bin/env python3

rlib_cc_magic = 90713
def getSerialNumber():
    global rlib_cc_magic
    rlib_cc_magic += 1
    return rlib_cc_magic

def genDefList(idarr):
    s = '#if'
    cter = 1
    for i in idarr:
        s += ' defined(' + i + ')'
        if cter != len(idarr):
            s += ' ||'
        cter += 1
    return s

print('// Generated by cc_codegen.py. Do not edit it by hand.')

with open("cc_list") as fd:
    osarr=fd.read().split('\n')
    for i in osarr:
        if i == '':
            continue
        if i[0] == '#':
            continue
        iarr=i.split(' ')
        if len(iarr) < 2:
            continue
        print('#ifndef RLIB_COMPILER_ID')
        print(genDefList(iarr[:-1:]))
        print('#define RLIB_COMPILER_ID', 'CC_' + iarr[-1])
        print('#endif')
        print('#endif')
        print('#define CC_' + iarr[-1], getSerialNumber())
        print('')

print('#ifndef RLIB_COMPILER_ID')
print('#define RLIB_COMPILER_ID CC_UNKNOWN')
print('#endif')
print('#define CC_UNKNOWN', getSerialNumber())

