cflag: remove circular dependency
							parent
							
								
									eb923b4995
								
							
						
					
					
						commit
						3cc7009440
					
				| 
						 | 
					@ -6,6 +6,7 @@ module builder
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	os
 | 
						os
 | 
				
			||||||
	time
 | 
						time
 | 
				
			||||||
 | 
						v.cflag
 | 
				
			||||||
	v.pref
 | 
						v.pref
 | 
				
			||||||
	v.util
 | 
						v.util
 | 
				
			||||||
	term
 | 
						term
 | 
				
			||||||
| 
						 | 
					@ -570,7 +571,7 @@ fn (c &Builder) build_thirdparty_obj_files() {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn (v &Builder) build_thirdparty_obj_file(path string, moduleflags []CFlag) {
 | 
					fn (v &Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CFlag) {
 | 
				
			||||||
	obj_path := os.real_path(path)
 | 
						obj_path := os.real_path(path)
 | 
				
			||||||
	if os.exists(obj_path) {
 | 
						if os.exists(obj_path) {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,25 +1,10 @@
 | 
				
			||||||
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
 | 
					 | 
				
			||||||
// Use of this source code is governed by an MIT license
 | 
					 | 
				
			||||||
// that can be found in the LICENSE file.
 | 
					 | 
				
			||||||
module builder
 | 
					module builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import v.cflag
 | 
				
			||||||
 | 
					 | 
				
			||||||
// parsed cflag
 | 
					 | 
				
			||||||
struct CFlag {
 | 
					 | 
				
			||||||
	mod   string // the module in which the flag was given
 | 
					 | 
				
			||||||
	os    string // eg. windows | darwin | linux
 | 
					 | 
				
			||||||
	name  string // eg. -I
 | 
					 | 
				
			||||||
	value string // eg. /path/to/include
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn (c &CFlag) str() string {
 | 
					 | 
				
			||||||
	return 'CFlag{ name: "$c.name" value: "$c.value" mod: "$c.mod" os: "$c.os" }'
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// get flags for current os
 | 
					// get flags for current os
 | 
				
			||||||
fn (v &Builder) get_os_cflags() []CFlag {
 | 
					fn (v &Builder) get_os_cflags() []cflag.CFlag {
 | 
				
			||||||
	mut flags := []CFlag
 | 
						mut flags := []cflag.CFlag
 | 
				
			||||||
	mut ctimedefines := []string
 | 
						mut ctimedefines := []string
 | 
				
			||||||
	if v.pref.compile_defines.len > 0 {
 | 
						if v.pref.compile_defines.len > 0 {
 | 
				
			||||||
		ctimedefines << v.pref.compile_defines
 | 
							ctimedefines << v.pref.compile_defines
 | 
				
			||||||
| 
						 | 
					@ -38,8 +23,8 @@ fn (v &Builder) get_os_cflags() []CFlag {
 | 
				
			||||||
	return flags
 | 
						return flags
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn (v &Builder) get_rest_of_module_cflags(c &CFlag) []CFlag {
 | 
					fn (v &Builder) get_rest_of_module_cflags(c &cflag.CFlag) []cflag.CFlag {
 | 
				
			||||||
	mut flags := []CFlag
 | 
						mut flags := []cflag.CFlag
 | 
				
			||||||
	cflags := v.get_os_cflags()
 | 
						cflags := v.get_os_cflags()
 | 
				
			||||||
	for flag in cflags {
 | 
						for flag in cflags {
 | 
				
			||||||
		if c.mod == flag.mod {
 | 
							if c.mod == flag.mod {
 | 
				
			||||||
| 
						 | 
					@ -52,67 +37,3 @@ fn (v &Builder) get_rest_of_module_cflags(c &CFlag) []CFlag {
 | 
				
			||||||
	return flags
 | 
						return flags
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// format flag
 | 
					 | 
				
			||||||
fn (cf &CFlag) format() string {
 | 
					 | 
				
			||||||
	mut value := cf.value
 | 
					 | 
				
			||||||
	if cf.name in ['-l', '-Wa', '-Wl', '-Wp'] && value.len > 0 {
 | 
					 | 
				
			||||||
		return '${cf.name}${value}'.trim_space()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// convert to absolute path
 | 
					 | 
				
			||||||
	if cf.name == '-I' || cf.name == '-L' || value.ends_with('.o') {
 | 
					 | 
				
			||||||
		value = '"' + os.real_path(value) + '"'
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return '$cf.name $value'.trim_space()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// TODO: implement msvc specific c_options_before_target and c_options_after_target ...
 | 
					 | 
				
			||||||
fn (cflags []CFlag) c_options_before_target_msvc() string {
 | 
					 | 
				
			||||||
	return ''
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn (cflags []CFlag) c_options_after_target_msvc() string {
 | 
					 | 
				
			||||||
	return ''
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn (cflags []CFlag) c_options_before_target() string {
 | 
					 | 
				
			||||||
	// -I flags, optimization flags and so on
 | 
					 | 
				
			||||||
	mut args := []string
 | 
					 | 
				
			||||||
	for flag in cflags {
 | 
					 | 
				
			||||||
		if flag.name != '-l' {
 | 
					 | 
				
			||||||
			args << flag.format()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return args.join(' ')
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn (cflags []CFlag) c_options_after_target() string {
 | 
					 | 
				
			||||||
	// -l flags (libs)
 | 
					 | 
				
			||||||
	mut args := []string
 | 
					 | 
				
			||||||
	for flag in cflags {
 | 
					 | 
				
			||||||
		if flag.name == '-l' {
 | 
					 | 
				
			||||||
			args << flag.format()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return args.join(' ')
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn (cflags []CFlag) c_options_without_object_files() string {
 | 
					 | 
				
			||||||
	mut args := []string
 | 
					 | 
				
			||||||
	for flag in cflags {
 | 
					 | 
				
			||||||
		if flag.value.ends_with('.o') || flag.value.ends_with('.obj') {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		args << flag.format()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return args.join(' ')
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn (cflags []CFlag) c_options_only_object_files() string {
 | 
					 | 
				
			||||||
	mut args := []string
 | 
					 | 
				
			||||||
	for flag in cflags {
 | 
					 | 
				
			||||||
		if flag.value.ends_with('.o') || flag.value.ends_with('.obj') {
 | 
					 | 
				
			||||||
			args << flag.format()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return args.join(' ')
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ module builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import v.pref
 | 
					import v.pref
 | 
				
			||||||
 | 
					import v.cflag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#flag windows -l shell32
 | 
					#flag windows -l shell32
 | 
				
			||||||
#flag windows -l dbghelp
 | 
					#flag windows -l dbghelp
 | 
				
			||||||
| 
						 | 
					@ -304,7 +305,7 @@ pub fn (v mut Builder) cc_msvc() {
 | 
				
			||||||
	os.rm(out_name_obj)
 | 
						os.rm(out_name_obj)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) {
 | 
					fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []cflag.CFlag) {
 | 
				
			||||||
	msvc := find_msvc()or{
 | 
						msvc := find_msvc()or{
 | 
				
			||||||
		println('Could not find visual studio')
 | 
							println('Could not find visual studio')
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
| 
						 | 
					@ -355,7 +356,7 @@ mut:
 | 
				
			||||||
	other_flags []string
 | 
						other_flags []string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn (cflags []CFlag) msvc_string_flags() MsvcStringFlags {
 | 
					fn (cflags []cflag.CFlag) msvc_string_flags() MsvcStringFlags {
 | 
				
			||||||
	mut real_libs := []string
 | 
						mut real_libs := []string
 | 
				
			||||||
	mut inc_paths := []string
 | 
						mut inc_paths := []string
 | 
				
			||||||
	mut lib_paths := []string
 | 
						mut lib_paths := []string
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,83 @@
 | 
				
			||||||
 | 
					// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
 | 
				
			||||||
 | 
					// Use of this source code is governed by an MIT license
 | 
				
			||||||
 | 
					// that can be found in the LICENSE file.
 | 
				
			||||||
 | 
					module cflag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// parsed cflag
 | 
				
			||||||
 | 
					struct CFlag {
 | 
				
			||||||
 | 
						mod   string // the module in which the flag was given
 | 
				
			||||||
 | 
						os    string // eg. windows | darwin | linux
 | 
				
			||||||
 | 
						name  string // eg. -I
 | 
				
			||||||
 | 
						value string // eg. /path/to/include
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn (c &CFlag) str() string {
 | 
				
			||||||
 | 
						return 'CFlag{ name: "$c.name" value: "$c.value" mod: "$c.mod" os: "$c.os" }'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// format flag
 | 
				
			||||||
 | 
					pub fn (cf &CFlag) format() string {
 | 
				
			||||||
 | 
						mut value := cf.value
 | 
				
			||||||
 | 
						if cf.name in ['-l', '-Wa', '-Wl', '-Wp'] && value.len > 0 {
 | 
				
			||||||
 | 
							return '${cf.name}${value}'.trim_space()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// convert to absolute path
 | 
				
			||||||
 | 
						if cf.name == '-I' || cf.name == '-L' || value.ends_with('.o') {
 | 
				
			||||||
 | 
							value = '"' + os.real_path(value) + '"'
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return '$cf.name $value'.trim_space()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: implement msvc specific c_options_before_target and c_options_after_target ...
 | 
				
			||||||
 | 
					fn (cflags []CFlag) c_options_before_target_msvc() string {
 | 
				
			||||||
 | 
						return ''
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn (cflags []CFlag) c_options_after_target_msvc() string {
 | 
				
			||||||
 | 
						return ''
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn (cflags []CFlag) c_options_before_target() string {
 | 
				
			||||||
 | 
						// -I flags, optimization flags and so on
 | 
				
			||||||
 | 
						mut args := []string
 | 
				
			||||||
 | 
						for flag in cflags {
 | 
				
			||||||
 | 
							if flag.name != '-l' {
 | 
				
			||||||
 | 
								args << flag.format()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return args.join(' ')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn (cflags []CFlag) c_options_after_target() string {
 | 
				
			||||||
 | 
						// -l flags (libs)
 | 
				
			||||||
 | 
						mut args := []string
 | 
				
			||||||
 | 
						for flag in cflags {
 | 
				
			||||||
 | 
							if flag.name == '-l' {
 | 
				
			||||||
 | 
								args << flag.format()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return args.join(' ')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn (cflags []CFlag) c_options_without_object_files() string {
 | 
				
			||||||
 | 
						mut args := []string
 | 
				
			||||||
 | 
						for flag in cflags {
 | 
				
			||||||
 | 
							if flag.value.ends_with('.o') || flag.value.ends_with('.obj') {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							args << flag.format()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return args.join(' ')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn (cflags []CFlag) c_options_only_object_files() string {
 | 
				
			||||||
 | 
						mut args := []string
 | 
				
			||||||
 | 
						for flag in cflags {
 | 
				
			||||||
 | 
							if flag.value.ends_with('.o') || flag.value.ends_with('.obj') {
 | 
				
			||||||
 | 
								args << flag.format()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return args.join(' ')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -3,12 +3,12 @@
 | 
				
			||||||
// that can be found in the LICENSE file.
 | 
					// that can be found in the LICENSE file.
 | 
				
			||||||
module table
 | 
					module table
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import v.builder
 | 
					import v.cflag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// check if cflag is in table
 | 
					// check if cflag is in table
 | 
				
			||||||
fn (table &Table) has_cflag(cflag builder.CFlag) bool {
 | 
					fn (table &Table) has_cflag(flag cflag.CFlag) bool {
 | 
				
			||||||
	for cf in table.cflags {
 | 
						for cf in table.cflags {
 | 
				
			||||||
		if cf.os == cflag.os && cf.name == cflag.name && cf.value == cflag.value {
 | 
							if cf.os == flag.os && cf.name == flag.name && cf.value == flag.value {
 | 
				
			||||||
			return true
 | 
								return true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -17,9 +17,9 @@ fn (table &Table) has_cflag(cflag builder.CFlag) bool {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// parse the flags to (table.cflags) []CFlag
 | 
					// parse the flags to (table.cflags) []CFlag
 | 
				
			||||||
// Note: clean up big time (joe-c)
 | 
					// Note: clean up big time (joe-c)
 | 
				
			||||||
pub fn (var table Table) parse_cflag(cflag, mod string, ctimedefines []string) ?bool {
 | 
					pub fn (var table Table) parse_cflag(cflg, mod string, ctimedefines []string) ?bool {
 | 
				
			||||||
	allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L']
 | 
						allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L']
 | 
				
			||||||
	flag_orig := cflag.trim_space()
 | 
						flag_orig := cflg.trim_space()
 | 
				
			||||||
	var flag := flag_orig
 | 
						var flag := flag_orig
 | 
				
			||||||
	if flag == '' {
 | 
						if flag == '' {
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
| 
						 | 
					@ -76,7 +76,7 @@ pub fn (var table Table) parse_cflag(cflag, mod string, ctimedefines []string) ?
 | 
				
			||||||
			hint := if name == '-l' { 'library name' } else { 'path' }
 | 
								hint := if name == '-l' { 'library name' } else { 'path' }
 | 
				
			||||||
			return error('bad #flag `$flag_orig`: missing $hint after `$name`')
 | 
								return error('bad #flag `$flag_orig`: missing $hint after `$name`')
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		cf := builder.CFlag{
 | 
							cf := cflag.CFlag{
 | 
				
			||||||
			mod: mod
 | 
								mod: mod
 | 
				
			||||||
			os: fos
 | 
								os: fos
 | 
				
			||||||
			name: name
 | 
								name: name
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@
 | 
				
			||||||
module table
 | 
					module table
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import v.builder
 | 
					import v.cflag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct Table {
 | 
					pub struct Table {
 | 
				
			||||||
pub mut:
 | 
					pub mut:
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ pub mut:
 | 
				
			||||||
	fns       map[string]Fn
 | 
						fns       map[string]Fn
 | 
				
			||||||
	imports   []string // List of all imports
 | 
						imports   []string // List of all imports
 | 
				
			||||||
	modules   []string // List of all modules registered by the application
 | 
						modules   []string // List of all modules registered by the application
 | 
				
			||||||
	cflags    []builder.CFlag // TODO a different module? importing builder from table feels weird
 | 
						cflags    []cflag.CFlag
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct Fn {
 | 
					pub struct Fn {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue