Last active
August 29, 2015 14:13
ycm_extra_conf.py for OpenBSD src tree / Makefiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on | |
# https://github.com/Valloric/ycmd/blob/master/cpp/ycm/.ycm_extra_conf.py | |
############################################# | |
# HOWTO | |
############################################# | |
# | |
# =============== Step 1 ==================== | |
# | |
# For kernel .c files, CFLAGS / CPPFLAGS from | |
# the actual kernel configuration are used. | |
# These are gathered via uname(1). | |
# | |
# If you want a specific arch/config, override | |
# them with 'default_arch' / 'default_config' | |
# | |
# NOTE: The choosen kernel configuration must | |
# exist. | |
import os | |
import ycm_core | |
default_arch = None | |
default_config = None | |
# You can add additional CFLAGS / CPPFLAGS here. | |
additional_userland_flags = [ | |
# "-Weverything" | |
] | |
additional_kernel_flags = [ | |
"-Weverything", | |
] | |
owndir = os.path.dirname( os.path.abspath( __file__ ) ) | |
srcdir = "/usr/src" | |
sysdir = os.path.join(srcdir, "sys") | |
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): | |
if not working_directory: | |
return list( flags ) | |
new_flags = [] | |
make_next_absolute = False | |
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] | |
for flag in flags: | |
new_flag = flag | |
if make_next_absolute: | |
make_next_absolute = False | |
if not flag.startswith( '/' ): | |
new_flag = os.path.join( working_directory, flag ) | |
for path_flag in path_flags: | |
if flag == path_flag: | |
make_next_absolute = True | |
break | |
if flag.startswith( path_flag ): | |
path = flag[ len( path_flag ): ] | |
new_flag = path_flag + os.path.join( working_directory, path ) | |
break | |
if new_flag: | |
new_flags.append( new_flag ) | |
return new_flags | |
def GetKernelFlags( darch, dconfig ): | |
if darch != None: | |
arch = darch | |
else: | |
arch = os.popen("uname -m").read().rstrip() | |
if dconfig != None: | |
config = dconfig | |
else: | |
config = os.popen("uname -v").read().split('#')[0] | |
makefiledir = "arch/%s/compile/%s" % ( arch, config ) | |
makefiledir = os.path.join(sysdir, makefiledir) | |
return GetFlags( makefiledir ) | |
def GetUserlandFlags( filename ): | |
makefiledir = os.path.dirname( filename ) | |
while not "Makefile" in os.listdir( makefiledir ): | |
makefiledir = os.path.join(makefiledir, "..") | |
return GetFlags( makefiledir ) | |
def GetFlags( makefiledir ): | |
make_flags = "myshowvar=\"CFLAGS CPPFLAGS\" myshow" | |
cd_cmd = "cd %s" % makefiledir | |
make_cmd = "make -f Makefile -f %s %s" % \ | |
(os.path.join(owndir, ".ycm_myshow.mk"), make_flags) | |
flags = os.popen("%s && %s" % (cd_cmd, make_cmd)).read().split() | |
return MakeRelativePathsInFlagsAbsolute( flags, makefiledir ) | |
def FlagsForFile( filename ): | |
if filename.startswith( sysdir ): | |
final_flags = GetKernelFlags( default_arch , default_config ) | |
final_flags.extend( additional_kernel_flags ) | |
elif filename.startswith( srcdir ): | |
final_flags = GetUserlandFlags( filename ) | |
final_flags.extend( additional_userland_flags ) | |
return { | |
'flags': final_flags, | |
'do_cache': True | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myshow: | |
.for v in ${myshowvar} | |
@echo ${$v} | |
.endfor | |
.PHONY: myshow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment