mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-11 07:00:58 +08:00
Merge pull request #91 from ThakeeNathees/scons-removed
SConstruct file removed and build scripts refactored
This commit is contained in:
commit
2e7ede104d
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,11 +4,6 @@
|
||||
.vscode/
|
||||
build/
|
||||
|
||||
# It's a convinent batch script to run pyton script
|
||||
# changing directory and run another script.
|
||||
# Which are compile wasm and generate pages.
|
||||
docs/build.bat
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
|
185
SConstruct
185
SConstruct
@ -1,185 +0,0 @@
|
||||
#!python
|
||||
## Copyright (c) 2020-2021 Thakee Nathees
|
||||
## Distributed Under The MIT License
|
||||
|
||||
from os.path import join
|
||||
import os, sys
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## PROJECT CONFIGURATIONS
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
PROJECT_NAME = 'pocketlang'
|
||||
|
||||
def CONFIGURE_ENV(env):
|
||||
variant_dir = env['variant_dir']
|
||||
binary_dir = join(variant_dir, 'bin/')
|
||||
binary_name = 'pocket'
|
||||
|
||||
## The executable to run with the current configuration.
|
||||
env.RUN_TARGET = join(variant_dir, 'bin', binary_name)
|
||||
env.SOURCE_DIRS = ('../src/', '../src/include/', '../cli/', '../cli/modules/')
|
||||
|
||||
## PocketLang source files
|
||||
PK_SOURCES = Glob(join(variant_dir, 'src/*.c'))
|
||||
|
||||
if env['shared_lib']:
|
||||
## Compile pocketlang dynamic lib.
|
||||
dll = env.SharedLibrary(
|
||||
target = join(binary_dir),
|
||||
source = PK_SOURCES,
|
||||
CPPDEFINES = [env['CPPDEFINES'], 'PK_DLL', 'PK_COMPILE'],
|
||||
)
|
||||
else:
|
||||
## Compile pocketlang static lib.
|
||||
lib = env.Library(
|
||||
target = join(binary_dir, binary_name),
|
||||
source = PK_SOURCES,
|
||||
)
|
||||
|
||||
## Test executable
|
||||
test = env.Program(
|
||||
target = join(binary_dir, binary_name),
|
||||
source = Glob(join(variant_dir, 'cli/*.c')),
|
||||
CPPPATH = [ join(variant_dir, 'src/include/') ],
|
||||
LIBPATH = binary_dir,
|
||||
LIBS = binary_name,
|
||||
)
|
||||
Requires(test, lib)
|
||||
|
||||
## Adding CPPPATH here to make VS be able to find the included files.
|
||||
env.Append(CPPPATH=['../src/include/'])
|
||||
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## COMMAND LINE ARGUMENTS
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
opts = Variables([], ARGUMENTS)
|
||||
|
||||
## Define our options.
|
||||
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx']))
|
||||
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['debug', 'release']))
|
||||
opts.Add(EnumVariable('bits', "output program bits", '64', ['32', '64']))
|
||||
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", False))
|
||||
opts.Add(BoolVariable('use_mingw', "Use Mingw compiler", False))
|
||||
opts.Add(BoolVariable('vsproj', "make a visual studio project", False))
|
||||
opts.Add(BoolVariable('shared_lib', "Compile as a shared library (only).", False))
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## SETUP ENVIRONMENT
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
## VariantDir.
|
||||
variant_dir = ARGUMENTS.get('target', 'debug') + '/'
|
||||
VariantDir(variant_dir, '../', duplicate=0)
|
||||
|
||||
## Setup the Environment.
|
||||
DefaultEnvironment(tools=[]) ## Not using any tools.
|
||||
env = Environment()
|
||||
|
||||
## Updates the environment with the option variables.
|
||||
opts.Update(env)
|
||||
|
||||
if env['use_llvm']:
|
||||
env['CC'] = 'clang'
|
||||
env['CXX'] = 'clang++'
|
||||
elif env['use_mingw']:
|
||||
env['tools'] = ['mingw']
|
||||
|
||||
## Find platform.
|
||||
if env['platform'] == '':
|
||||
if sys.platform == 'win32':
|
||||
env['platform'] = 'windows'
|
||||
elif sys.platform in ('x11', 'linux', 'linux2'):
|
||||
env['platform'] = 'linux'
|
||||
elif sys.platform == 'darwin':
|
||||
env['platform'] = 'osx'
|
||||
else:
|
||||
print("platform(%s) not supported." % sys.platform)
|
||||
quit()
|
||||
|
||||
if env['target'] == 'debug':
|
||||
env.Append(CPPDEFINES=['DEBUG'])
|
||||
|
||||
## Check our platform specifics
|
||||
if env['platform'] == "osx":
|
||||
if env['target'] == 'debug':
|
||||
env.Append(CCFLAGS=['-g', '-O2', '-arch', 'x86_64'])
|
||||
env.Append(LINKFLAGS=['-arch', 'x86_64'])
|
||||
else:
|
||||
env.Append(CCFLAGS=['-g', '-O3', '-arch', 'x86_64'])
|
||||
env.Append(LINKFLAGS=['-arch', 'x86_64'])
|
||||
|
||||
elif env['platform'] == 'x11':
|
||||
env.Append(LIBS=['m'])
|
||||
if env['target'] == 'debug':
|
||||
env.Append(CCFLAGS=['-fPIC', '-g3', '-Og'])
|
||||
else:
|
||||
env.Append(CCFLAGS=['-fPIC', '-g', '-O3'])
|
||||
|
||||
elif env['platform'] == "windows":
|
||||
env.Append(CPPDEFINES=['_CRT_SECURE_NO_WARNINGS'])
|
||||
env.Append(CPPDEFINES=['WIN32', '_WIN32', '_WINDOWS'])
|
||||
env.Append(CCFLAGS=['-W3', '-GR', '/FS'])
|
||||
env.Append(LINKFLAGS='-SUBSYSTEM:CONSOLE')
|
||||
env.Append(LIBS=[])
|
||||
|
||||
if env['bits'] == '32': env['TARGET_ARCH'] = 'x86'
|
||||
else: env['TARGET_ARCH'] = 'x86_64'
|
||||
|
||||
if env['target'] == 'debug':
|
||||
env.Append(CCFLAGS=['-EHsc', '-MDd', '-ZI'])
|
||||
env.Append(LINKFLAGS=['-DEBUG'])
|
||||
else:
|
||||
env.Append(CPPDEFINES=['NDEBUG'])
|
||||
env.Append(CCFLAGS=['-O2', '-EHsc', '-MD'])
|
||||
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## UPDATE ENV WITH PROJECT CONFIG
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
env['variant_dir'] = variant_dir
|
||||
CONFIGURE_ENV(env)
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## MSVS PROJECT FILE GENERATION
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
def msvc_build_commandline(commands):
|
||||
common_build_prefix = [
|
||||
'cmd /V /C set "bits=64"',
|
||||
'(if "$(PlatformTarget)"=="x86" (set "bits=32"))']
|
||||
return " ^& ".join(common_build_prefix + [commands])
|
||||
|
||||
def collect_source_files(dirs, ext):
|
||||
ret = []
|
||||
for dir in dirs:
|
||||
ret += [
|
||||
join(dir, file) for file in os.listdir(dir) if file.endswith(ext)
|
||||
]
|
||||
return ret
|
||||
|
||||
if env['vsproj']:
|
||||
env["MSVSBUILDCOM"] = msvc_build_commandline(
|
||||
"scons --directory=\"$(ProjectDir.TrimEnd('\\'))\" platform=windows target=$(Configuration) bits=!bits!")
|
||||
env["MSVSREBUILDCOM"] = msvc_build_commandline(
|
||||
"scons --directory=\"$(ProjectDir.TrimEnd('\\'))\" platform=windows target=$(Configuration) bits=!bits! vsproj=yes")
|
||||
env["MSVSCLEANCOM"] = msvc_build_commandline(
|
||||
"scons --directory=\"$(ProjectDir.TrimEnd('\\'))\" --clean platform=windows bits=!bits! target=$(Configuration)")
|
||||
|
||||
targets = [ env.RUN_TARGET ] * 4
|
||||
variants = ["debug|Win32", "debug|x64", "release|Win32", "release|x64"]
|
||||
|
||||
env.MSVSProject(
|
||||
target = PROJECT_NAME + env['MSVSPROJECTSUFFIX'],
|
||||
srcs = collect_source_files(env.SOURCE_DIRS, ('.c', '.cpp', '.cc', '.cxx')),
|
||||
incs = collect_source_files(env.SOURCE_DIRS, ('.h', '.hpp')),
|
||||
variant = variants,
|
||||
runfile = targets,
|
||||
buildtarget = targets,
|
||||
)
|
||||
|
||||
## Generates help for the -h scons option.
|
||||
Help(opts.GenerateHelpText(env))
|
20
build.bat
20
build.bat
@ -4,12 +4,6 @@
|
||||
|
||||
@echo off
|
||||
|
||||
:: To set color. (Ref : https://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line)
|
||||
SETLOCAL EnableDelayedExpansion
|
||||
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
|
||||
set "DEL=%%a"
|
||||
)
|
||||
|
||||
:: ----------------------------------------------------------------------------
|
||||
:: PARSE COMMAND LINE ARGS
|
||||
:: ----------------------------------------------------------------------------
|
||||
@ -172,19 +166,5 @@ goto :END
|
||||
:END
|
||||
endlocal
|
||||
goto :eof
|
||||
:: ----------------------------------------------------------------------------
|
||||
:: PRINT COLORED MESSAGE
|
||||
:: ----------------------------------------------------------------------------
|
||||
|
||||
:: Usage:
|
||||
::call :ColorText 0a "Compilation Success"
|
||||
::echo.
|
||||
|
||||
:: Reference - https://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line)
|
||||
:::ColorText
|
||||
::echo off
|
||||
::<nul set /p ".=%DEL%" > "%~2"
|
||||
::findstr /v /a:%1 /R "^$" "%~2" nul
|
||||
::del "%~2" > nul 2>&1
|
||||
::goto :eof
|
||||
|
||||
|
@ -56,7 +56,10 @@ def check_fnv1_hash(sources):
|
||||
hash = hex(fnv1a_hash(name))
|
||||
|
||||
if val == hash: continue
|
||||
report_error(f"{location(file, line_no)} - hash mismatch. "
|
||||
|
||||
## Path of the file relative to top-level.
|
||||
file_path = os.path.relpath(file, join(THIS_PATH, '..'))
|
||||
report_error(f"{location(file_path, line_no)} - hash mismatch. "
|
||||
f"hash('{name}') = {hash} not {val}")
|
||||
|
||||
fp.close()
|
||||
@ -73,27 +76,32 @@ def check_static(dirs):
|
||||
|
||||
fp = open(join(dir, file), 'r')
|
||||
|
||||
## Path of the file relative to top-level.
|
||||
file_path = os.path.relpath(join(dir, file), join(THIS_PATH, '..'))
|
||||
|
||||
## This will be set to true if the last line is empty.
|
||||
is_last_empty = False; line_no = 0
|
||||
for line in fp.readlines():
|
||||
line_no += 1; line = line[:-1] # remove the line ending.
|
||||
|
||||
_location = location(join(dir, file), line_no)
|
||||
|
||||
## Check if the line contains any tabs.
|
||||
if '\t' in line:
|
||||
_location = location(file_path, line_no)
|
||||
report_error(f"{_location} - contains tab(s) ({repr(line)}).")
|
||||
|
||||
if len(line) >= 80:
|
||||
if 'http://' in line or 'https://' in line: continue
|
||||
_location = location(file_path, line_no)
|
||||
report_error(
|
||||
f"{_location} - contains {len(line)} (> 79) characters.")
|
||||
|
||||
if line.endswith(' '):
|
||||
_location = location(file_path, line_no)
|
||||
report_error(f"{_location} - contains trailing white space.")
|
||||
|
||||
if line == '':
|
||||
if is_last_empty:
|
||||
_location = location(file_path, line_no)
|
||||
report_error(f"{_location} - consequent empty lines.")
|
||||
is_last_empty = True
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user