1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

simplify cflag parsing

This commit is contained in:
joe-conigliaro 2019-12-15 14:18:14 +11:00 committed by Alexander Medvednikov
parent be60193588
commit 717740cfcf
4 changed files with 16 additions and 27 deletions

View File

@ -74,6 +74,7 @@ fn (table mut Table) parse_cflag(cflag string, mod string) ?bool {
allowed_flags := [
'framework',
'library',
'Wl',
'I', 'l', 'L',
]
flag_orig := cflag.trim_space()
@ -82,14 +83,13 @@ fn (table mut Table) parse_cflag(cflag string, mod string) ?bool {
return true
}
mut fos := ''
mut name := ''
if flag.starts_with('linux') || flag.starts_with('darwin') || flag.starts_with('freebsd') || flag.starts_with('windows') {
pos := flag.index(' ') or { return none }
fos = flag[..pos].trim_space()
flag = flag[pos..].trim_space()
}
for {
mut index := -1
mut name := ''
mut value := ''
if flag[0] == `-` {
for f in allowed_flags {
@ -101,34 +101,23 @@ fn (table mut Table) parse_cflag(cflag string, mod string) ?bool {
}
}
}
if i := flag.index(' ') {
if index == -1 || i < index {
index = i
}
}
if i := flag.index(',') {
if index == -1 || i < index {
index = i
}
}
if index != -1 && flag[index] == ` ` && flag[index+1] == `-` {
mut index := flag.index(' -') or { -1 }
for index > -1 {
mut has_next := false
for f in allowed_flags {
j := index+f.len
if j < flag.len && f == flag[index..j] {
index = j
i := index+2+f.len
if i <= flag.len && f == flag[index+2..i] {
value = flag[..index+1].trim_space()
flag = flag[index+1..].trim_space()
has_next = true
break
}
}
value = flag[..index].trim_space()
flag = flag[index..].trim_space()
if has_next { break }
index = flag.index_after(' -', index+1)
}
else if index != -1 && index < flag.len-2 && flag[index] == `,` {
value = flag[..index].trim_space()
flag = flag[index+1..].trim_space()
}
else {
if index == -1 {
value = flag.trim_space()
index = -1
}
if (name in ['-I', '-l', '-L']) && value == '' {
hint := if name == '-l' { 'library name' } else { 'path' }

View File

@ -18,7 +18,7 @@ import (
#flag darwin -I/usr/local/include/freetype2
#flag darwin -I/opt/local/include/freetype2
#flag freebsd -I/usr/local/include/freetype2
#flag freebsd -Wl,-L/usr/local/lib
#flag freebsd -Wl -L/usr/local/lib
#flag -lfreetype
//#flag -I @VROOT/thirdparty/freetype

View File

@ -5,7 +5,7 @@
module http
#flag windows -I @VROOT/thirdparty/vschannel
#flag -l ws2_32, crypt32, secur32
#flag -l ws2_32 -l crypt32 -l secur32
#include "vschannel.c"

View File

@ -2,7 +2,7 @@ module sqlite
#flag -lsqlite3
#flag freebsd -I/usr/local/include
#flag freebsd -Wl,-L/usr/local/lib,-lsqlite3
#flag freebsd -Wl -L/usr/local/lib -lsqlite3
#include "sqlite3.h"
struct C.sqlite3