65 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/env python3
 | |
| 
 | |
| from subprocess import getoutput, run
 | |
| from os import getcwd
 | |
| from os.path import expandvars
 | |
| from pathlib import Path
 | |
| from sys import argv
 | |
| from functools import reduce
 | |
| import tomllib
 | |
| 
 | |
| #TODO: support for default pack override
 | |
| #TODO: automatic full rebuild on git head change (such as new commits)
 | |
| 
 | |
| has_ninja = getoutput("command -v ninja") != ""
 | |
| has_clang = getoutput("command -v clang") != ""
 | |
| 
 | |
| target_web = "--target=web" in argv
 | |
| 
 | |
| #TODO: infer what "native" means for current env
 | |
| build_dir_arg = reduce(lambda c, n: c if c.startswith("--build_dir=") else n, argv + [""], "")
 | |
| build_dir = "build/web" if target_web else build_dir_arg.split("=")[1] if build_dir_arg else "build/native"
 | |
| build_dir += "" if build_dir_arg else "/release" if "--release" in argv else "/debug"
 | |
| 
 | |
| cmake = ["emcmake", "cmake"] if target_web else ["cmake"]
 | |
| # cmake configuration command
 | |
| command = []
 | |
| 
 | |
| # check whether clang is around (it's just better)
 | |
| if has_clang and not target_web:
 | |
|     command += ["-DCMAKE_C_COMPILER=clang"]
 | |
| # check whether ninja is around (you better start running)
 | |
| if has_ninja:
 | |
|     command += ["-G", "Ninja"]
 | |
| 
 | |
| command += ["-B", build_dir]
 | |
| 
 | |
| # TODO: have it --fast=1 instead, where separate --debug=0 would mean stripping the debug info
 | |
| if "--release" in argv:
 | |
|     command += ["-DCMAKE_BUILD_TYPE=Release"]
 | |
| elif "--debug" in argv:
 | |
|     command += ["-DCMAKE_BUILD_TYPE=Debug"]
 | |
| 
 | |
| if "--unified=1" in argv:
 | |
|     command += ["-DTWN_FEATURE_DYNLIB_GAME=ON"]
 | |
| elif "--unified=0" in argv:
 | |
|     command += ["-DTWN_FEATURE_DYNLIB_GAME=OFF"]
 | |
| 
 | |
| if "--sanitize=1" in argv:
 | |
|     command += ["-DTWN_SANITIZE=ON"]
 | |
| elif "--sanitize=0" in argv:
 | |
|     command += ["-DTWN_SANITIZE=OFF"]
 | |
| 
 | |
| command += [f"-DTWN_OUT_DIR={getcwd()}"]
 | |
| # pass arbitrary arguments over
 | |
| if "--" in argv:
 | |
|     command += argv[argv.index("--")+1:]
 | |
| 
 | |
| # if no root cmake file is present, infer it from `twn.toml:game.interpreter`
 | |
| if not Path("CMakeLists.txt").is_file():
 | |
|     config = tomllib.loads(Path("data/twn.toml").read_text())
 | |
|     command += ["-S", expandvars(config["game"]["interpreter"])]
 | |
| 
 | |
| run(cmake + command, check=True)
 | |
| run(["cmake"] + ["--build", build_dir, "--parallel"], check=True)
 |