dynamic works; static works for non cell builds
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
CFLAGS = "-Isource -Wno-incompatible-pointer-types -Wno-missing-braces -Wno-strict-prototypes -Wno-unused-function -Wno-int-conversion"
|
CFLAGS = "-Isource -Wno-incompatible-pointer-types -Wno-missing-braces -Wno-strict-prototypes -Wno-unused-function -Wno-int-conversion"
|
||||||
LDFLAGS = "-lstdc++ -lm"
|
LDFLAGS = "-lstdc++ -lm"
|
||||||
|
|
||||||
[compilation.macOS]
|
[compilation.macos_arm64]
|
||||||
CFLAGS = "-x objective-c"
|
CFLAGS = "-x objective-c"
|
||||||
LDFLAGS = "-framework CoreFoundation -framework CFNetwork"
|
LDFLAGS = "-framework CoreFoundation -framework CFNetwork"
|
||||||
|
|
||||||
@@ -10,4 +10,4 @@ LDFLAGS = "-framework CoreFoundation -framework CFNetwork"
|
|||||||
CFLAGS = "-DMINIZ_NO_TIME -DTARGET_EXTENSION -DTARGET_PLAYDATE -I$PLAYDATE_SDK_PATH/C_API"
|
CFLAGS = "-DMINIZ_NO_TIME -DTARGET_EXTENSION -DTARGET_PLAYDATE -I$PLAYDATE_SDK_PATH/C_API"
|
||||||
|
|
||||||
[compilation.windows]
|
[compilation.windows]
|
||||||
LDFLAGS = "-lbcrypt -lwinhttp -static-libgcc -static-libstdc++"
|
LDFLAGS = "-lws2_32 -lwinmm -liphlpapi -lbcrypt -lwinhttp -static-libgcc -static-libstdc++"
|
||||||
|
|||||||
903
scripts/build.ce
903
scripts/build.ce
File diff suppressed because it is too large
Load Diff
@@ -337,6 +337,12 @@ Build.get_cc = function(target) {
|
|||||||
return 'cc'
|
return 'cc'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Build.get_cpp = function(target) {
|
||||||
|
var tc = Build.get_toolchain(target)
|
||||||
|
if (tc && tc.binaries && tc.binaries.cpp) return tc.binaries.cpp
|
||||||
|
return 'cpp'
|
||||||
|
}
|
||||||
|
|
||||||
// Get archiver command for target
|
// Get archiver command for target
|
||||||
Build.get_ar = function(target) {
|
Build.get_ar = function(target) {
|
||||||
var tc = Build.get_toolchain(target)
|
var tc = Build.get_toolchain(target)
|
||||||
@@ -590,18 +596,20 @@ Build.compile_file = function(src_path, obj_path, options) {
|
|||||||
var src_file = src_path
|
var src_file = src_path
|
||||||
// If src_path is absolute, checking if it is inside module_dir
|
// If src_path is absolute, checking if it is inside module_dir
|
||||||
if (src_path.startsWith(module_dir + '/')) {
|
if (src_path.startsWith(module_dir + '/')) {
|
||||||
src_file = src_path.substring(module_dir.length + 1)
|
src_file = '"' + src_path.substring(module_dir.length + 1) + '"'
|
||||||
} else if (!src_path.startsWith('/')) {
|
} else if (!src_path.startsWith('/')) {
|
||||||
src_file = '"$HERE/' + src_path + '"'
|
src_file = '"$HERE/' + src_path + '"'
|
||||||
} else {
|
} else {
|
||||||
// It's absolute and outside module dir, use as is (or relative to root?)
|
// It's absolute and outside module dir, use as is (quoted)
|
||||||
// If we use absolute path, it should be fine
|
src_file = '"' + src_path + '"'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust output path to be absolute/relative to HERE
|
// Adjust output path to be absolute/relative to HERE
|
||||||
var out_file = obj_path
|
var out_file = obj_path
|
||||||
if (!out_file.startsWith('/')) {
|
if (!out_file.startsWith('/')) {
|
||||||
out_file = '"$HERE/' + out_file + '"'
|
out_file = '"$HERE/' + out_file + '"'
|
||||||
|
} else {
|
||||||
|
out_file = '"' + out_file + '"'
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're changing CWD to module_dir, we need to make sure out_file (if absolute) is still valid?
|
// If we're changing CWD to module_dir, we need to make sure out_file (if absolute) is still valid?
|
||||||
@@ -611,7 +619,7 @@ Build.compile_file = function(src_path, obj_path, options) {
|
|||||||
// Likely in build.ce or shop.cm (build_package).
|
// Likely in build.ce or shop.cm (build_package).
|
||||||
|
|
||||||
var cc_cmd = cc + ' -c' + compile_flags + ' ' + src_file + ' -o ' + out_file
|
var cc_cmd = cc + ' -c' + compile_flags + ' ' + src_file + ' -o ' + out_file
|
||||||
full_cmd = 'HERE=$(pwd); cd ' + module_dir + ' && ' + cc_cmd
|
full_cmd = 'HERE=$(pwd); cd "' + module_dir + '" && ' + cc_cmd
|
||||||
} else {
|
} else {
|
||||||
// Standard compilation from current dir
|
// Standard compilation from current dir
|
||||||
var include_str = ''
|
var include_str = ''
|
||||||
@@ -707,16 +715,23 @@ Build.link_executable = function(objects, output, options) {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get flags from config for a platform
|
// Get flags from config for a platform/target
|
||||||
Build.get_flags = function(config, platform, key) {
|
// Checks: compilation[key], compilation[platform][key], compilation[target][key]
|
||||||
|
Build.get_flags = function(config, platform, key, target) {
|
||||||
var flags = ''
|
var flags = ''
|
||||||
if (config.compilation && config.compilation[key]) {
|
if (config.compilation && config.compilation[key]) {
|
||||||
flags += config.compilation[key]
|
flags += config.compilation[key]
|
||||||
}
|
}
|
||||||
|
// Check platform (e.g., 'macOS', 'darwin', 'Linux')
|
||||||
if (config.compilation && config.compilation[platform] && config.compilation[platform][key]) {
|
if (config.compilation && config.compilation[platform] && config.compilation[platform][key]) {
|
||||||
if (flags != '') flags += ' '
|
if (flags != '') flags += ' '
|
||||||
flags += config.compilation[platform][key]
|
flags += config.compilation[platform][key]
|
||||||
}
|
}
|
||||||
|
// Check target (e.g., 'macos_arm64', 'linux', 'windows')
|
||||||
|
if (target && target != platform && config.compilation && config.compilation[target] && config.compilation[target][key]) {
|
||||||
|
if (flags != '') flags += ' '
|
||||||
|
flags += config.compilation[target][key]
|
||||||
|
}
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -826,6 +826,7 @@ function get_build_dir(pkg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Shop.get_build_dir = get_build_dir
|
Shop.get_build_dir = get_build_dir
|
||||||
|
Shop.get_global_build_dir = get_global_build_dir
|
||||||
|
|
||||||
function get_rel_path(path, pkg) {
|
function get_rel_path(path, pkg) {
|
||||||
if (!pkg) {
|
if (!pkg) {
|
||||||
@@ -1019,7 +1020,7 @@ function resolve_c_symbol(path, package_context)
|
|||||||
if (!static_only) {
|
if (!static_only) {
|
||||||
// Then try dynamic library
|
// Then try dynamic library
|
||||||
var build_dir = get_build_dir(package_context)
|
var build_dir = get_build_dir(package_context)
|
||||||
var local_dl_name = build_dir + '/cellmod' + dylib_ext
|
var local_dl_name = build_dir + '/libcellmod' + dylib_ext
|
||||||
|
|
||||||
if (fd.is_file(local_dl_name)) {
|
if (fd.is_file(local_dl_name)) {
|
||||||
if (!open_dls[local_dl_name])
|
if (!open_dls[local_dl_name])
|
||||||
@@ -1064,7 +1065,7 @@ function resolve_c_symbol(path, package_context)
|
|||||||
// Then try dynamic library for package (skip in static_only mode)
|
// Then try dynamic library for package (skip in static_only mode)
|
||||||
if (!static_only) {
|
if (!static_only) {
|
||||||
var pkg_build_dir = get_build_dir(canon_pkg)
|
var pkg_build_dir = get_build_dir(canon_pkg)
|
||||||
var dl_path = pkg_build_dir + '/cellmod' + dylib_ext
|
var dl_path = pkg_build_dir + '/libcellmod' + dylib_ext
|
||||||
if (fd.is_file(dl_path)) {
|
if (fd.is_file(dl_path)) {
|
||||||
if (!open_dls[dl_path]) open_dls[dl_path] = os.dylib_open(dl_path)
|
if (!open_dls[dl_path]) open_dls[dl_path] = os.dylib_open(dl_path)
|
||||||
if (open_dls[dl_path]) {
|
if (open_dls[dl_path]) {
|
||||||
@@ -1658,6 +1659,21 @@ Shop.module_reload = function(path, package) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter out main*.c files (they're only for static builds)
|
||||||
|
function is_main_file(file) {
|
||||||
|
var basename = file
|
||||||
|
var slash = file.lastIndexOf('/')
|
||||||
|
if (slash >= 0) basename = file.substring(slash + 1)
|
||||||
|
if (basename == 'main.c') return true
|
||||||
|
if (basename.startsWith('main_') && basename.endsWith('.c')) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the core build directory for linking
|
||||||
|
function get_core_build_dir() {
|
||||||
|
return get_global_build_dir() + '/core'
|
||||||
|
}
|
||||||
|
|
||||||
Shop.build_package = function(package)
|
Shop.build_package = function(package)
|
||||||
{
|
{
|
||||||
if (package == 'local') package = null
|
if (package == 'local') package = null
|
||||||
@@ -1686,6 +1702,10 @@ Shop.build_package = function(package)
|
|||||||
|
|
||||||
for (var i=0; i<files.length; i++) {
|
for (var i=0; i<files.length; i++) {
|
||||||
var file = files[i]
|
var file = files[i]
|
||||||
|
|
||||||
|
// Skip main*.c files - they're only for static builds
|
||||||
|
if (is_main_file(file)) continue
|
||||||
|
|
||||||
var src_path
|
var src_path
|
||||||
if (!package) {
|
if (!package) {
|
||||||
src_path = (current_package_path || '.') + '/' + file
|
src_path = (current_package_path || '.') + '/' + file
|
||||||
@@ -1811,21 +1831,32 @@ Shop.build_package = function(package)
|
|||||||
|
|
||||||
// Link if there are C objects
|
// Link if there are C objects
|
||||||
if (c_objects.length > 0) {
|
if (c_objects.length > 0) {
|
||||||
var lib_name = build_dir + '/cellmod' + dylib_ext
|
var lib_name = build_dir + '/libcellmod' + dylib_ext
|
||||||
var lib_meta_path = lib_name + '.meta'
|
var lib_meta_path = lib_name + '.meta'
|
||||||
|
|
||||||
var link_flags = '-fPIC -shared'
|
var link_flags = '-fPIC -shared'
|
||||||
|
|
||||||
|
// Link against core cellmod.dylib
|
||||||
|
var core_build = get_core_build_dir()
|
||||||
|
if (platform == 'macOS') {
|
||||||
|
link_flags += ' -L' + core_build + ' -Wl,-rpath,@loader_path/../../core'
|
||||||
|
} else if (platform == 'Linux' || platform == 'linux') {
|
||||||
|
link_flags += ' -L' + core_build + ' -Wl,-rpath,$ORIGIN/../../core'
|
||||||
|
} else if (platform == 'Windows') {
|
||||||
|
link_flags += ' -L' + core_build
|
||||||
|
}
|
||||||
|
link_flags += ' -lcellmod'
|
||||||
|
|
||||||
var ldflags = get_flags(config, platform, 'LDFLAGS')
|
var ldflags = get_flags(config, platform, 'LDFLAGS')
|
||||||
if (ldflags != '') link_flags += ' ' + ldflags
|
if (ldflags != '') link_flags += ' ' + ldflags
|
||||||
|
|
||||||
var temp_lib = 'cellmod' + dylib_ext
|
var temp_lib = 'libcellmod' + dylib_ext
|
||||||
var objs_str = ''
|
var objs_str = ''
|
||||||
for (var i=0; i<c_objects.length; i++) {
|
for (var i=0; i<c_objects.length; i++) {
|
||||||
objs_str += '"' + c_objects[i] + '" '
|
objs_str += '"' + c_objects[i] + '" '
|
||||||
}
|
}
|
||||||
|
|
||||||
var link_cmd = 'cd ' + module_dir + ' && cc ' + link_flags + ' ' + objs_str + ' -lcell_runtime -lc -lc++ -o ' + temp_lib
|
var link_cmd = 'cd ' + module_dir + ' && cc ' + link_flags + ' ' + objs_str + ' -lc -lc++ -o ' + temp_lib
|
||||||
var link_cmd_hash = get_hash(link_cmd)
|
var link_cmd_hash = get_hash(link_cmd)
|
||||||
|
|
||||||
// Check if we need to relink
|
// Check if we need to relink
|
||||||
|
|||||||
@@ -1,20 +1,45 @@
|
|||||||
// cell update [alias] - Update packages to latest versions
|
// cell update [alias] - Update packages to latest versions and rebuild dynamic libraries
|
||||||
|
//
|
||||||
|
// This command:
|
||||||
|
// 1. Updates all packages from their remote sources
|
||||||
|
// 2. Rebuilds all dynamic libraries via 'cell build -d'
|
||||||
|
|
||||||
var shop = use('shop')
|
var shop = use('shop')
|
||||||
|
var os = use('os')
|
||||||
|
|
||||||
var alias = args.length > 0 ? args[0] : null
|
var target = null
|
||||||
|
|
||||||
|
// Parse arguments
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
if (args[i] == '--target' || args[i] == '-t') {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
target = args[i + 1]
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
} else if (args[i] == '--help' || args[i] == '-h') {
|
||||||
|
log.console("Usage: cell update [options]")
|
||||||
|
log.console("Update packages and rebuild dynamic libraries.")
|
||||||
|
log.console("")
|
||||||
|
log.console("Options:")
|
||||||
|
log.console(" --target, -t <target> Build for specific target platform")
|
||||||
|
log.console("")
|
||||||
|
log.console("This command updates all installed packages from their remote")
|
||||||
|
log.console("sources, then rebuilds all dynamic libraries.")
|
||||||
|
$_.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var packages = shop.list_shop_packages()
|
var packages = shop.list_shop_packages()
|
||||||
|
|
||||||
log.console("Checking for updates (" + packages.length + " packages)...")
|
log.console("Checking for updates (" + packages.length + " packages)...")
|
||||||
|
|
||||||
|
// 1. Update all packages
|
||||||
for (var info of packages) {
|
for (var info of packages) {
|
||||||
var pack = info.package
|
var pack = info.package
|
||||||
if (!pack || pack == 'core') continue
|
if (!pack || pack == 'core') continue
|
||||||
|
|
||||||
log.console("Updating " + pack)
|
log.console("Updating " + pack)
|
||||||
shop.update(pack)
|
shop.update(pack)
|
||||||
shop.build_package(pack)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$_.stop()
|
$_.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user