shithub: femtolisp

ref: 62389c8990cafb8e99ae29b2bccbcd100ce4c7f0
dir: /meson.build/

View raw version
project(
	'femtolisp',
	'c',
	version: '0.999',
	meson_version: '>=1.1.0',
	default_options: [
		'c_std=c2x',
		'warning_level=3',
		'buildtype=debugoptimized',
		'b_ndebug=if-release'
		#'b_coverage=true',
	],
)

add_project_arguments(
	#'-Wcast-align=strict',
	#'-Wcast-qual',
	#'-Wconversion',
	#'-Wfloat-equal',
	#'-Wmissing-noreturn',
	#'-Wsign-conversion',
	#'-Wsuggest-attribute=const',
	#'-Wsuggest-attribute=malloc',
	#'-Wsuggest-attribute=noreturn',
	#'-Wsuggest-attribute=pure',
	#'-Wsuggest-attribute=returns_nonnull',
	'-Waggregate-return',
	'-Werror=odr',
	'-Werror=strict-aliasing',
	'-Wformat=2',
	'-Wint-to-pointer-cast',
	'-Wmissing-prototypes',
	'-Wno-format-y2k',
	'-Wpointer-arith',
	'-Wpointer-to-int-cast',
	'-Wredundant-decls',
	'-Wsequence-point',
	'-Wshadow',
	'-Wstrict-prototypes',
	'-Wundef',
	'-Wunused-but-set-parameter',
	'-Wunused-parameter',
	'-Wwrite-strings',
	'-D_DEFAULT_SOURCE',
	'-DBLZ_NO_LUT=1', # breaks on m68k - disable for everything
	'-DCOMPUTED_GOTO',
	language: 'c',
)

cc = meson.get_compiler('c')

if cc.get_id() == 'clang'
	add_project_arguments(
		'-D__wchar_t=__please_no_wchar_t_thank_you',
		'-Wunused-const-variable',
		language: 'c',
	)
else
	add_project_arguments(
		'-Wformat-truncation=2',
		'-Wlogical-op',
		'-Wunused-const-variable=2',
		'-Werror=lto-type-mismatch',
		language: 'c',
	)
endif

platform = 'posix'

if host_machine.system() == 'macos'
	platform = 'macos'
	flisp_exe_name = 'flisp.code.bin'
	add_languages(
		'cpp',
		native: false,
		required: true,
	)
	cpp = meson.get_compiler('cpp')
	add_project_arguments(
		'-DINITIAL_HEAP_SIZE=128*1024',
		'-DALLOC_LIMIT_TRIGGER=64*1024',
		'-D__thread=', # does not make sense anyway
		language: 'c',
	)
	if host_machine.cpu() == 'm68k'
		add_project_arguments(
			# don't expect allocated pointers to be aligned by 8 bytes
			'-DMEM_NEED_ALIGNED',
			language: 'c',
		)
	endif
	extras = [
		cpp.find_library('RetroConsole', required: true),
	]
else
	flisp_exe_name = 'flisp'
	add_project_arguments(
		'-DINITIAL_HEAP_SIZE=8*1024*1024',
		'-DALLOC_LIMIT_TRIGGER=1*1024*1024',
		language: 'c',
	)
	extras = []
endif

src = [
	'3rd/fn.c',
	'3rd/mt19937-64.c',
	'3rd/spooky.c',
	'3rd/tbl.c',
	'bitvector.c',
	'builtins.c',
	'compress.c',
	'cvalues.c',
	'equal.c',
	'equalhash.c',
	'flisp.c',
	'flmain.c',
	'hashing.c',
	'htable.c',
	'ios.c',
	'iostream.c',
	'opcodes.c',
	'operators.c',
	'print.c',
	'ptrhash.c',
	'random.c',
	'read.c',
	'string.c',
	'sys_' + platform + '.c',
	'table.c',
	'types.c',
	'utf8.c',
]

math = cc.find_library('m', required: false)

boot = custom_target(
	'boot',
	capture: true,
	input: [
		'flisp.boot.builtin',
	],
	output: [
		'flisp.boot.h',
	],
	command: [
		'boot2h.sh', '@INPUT@',
	],
)

builtins = custom_target(
	'builtins',
	capture: true,
	input: [
		src,
	],
	output: [
		'builtin_fns.h',
	],
	command: [
		'builtins2h.sh', '@INPUT@',
	],
)

brieflz = static_library(
	'brieflz',
	[
		'3rd/brieflz/brieflz.c',
		'3rd/brieflz/depacks.c',
	],
	include_directories: include_directories(
		'3rd/brieflz',
		platform,
	),
)

common = static_library(
	'common',
	[
		'mem.c',
	],
	include_directories: include_directories(
		platform,
	),
)

mp = static_library(
	'mp',
	[
		'3rd/mp/mpadd.c',
		'3rd/mp/mpaux.c',
		'3rd/mp/mpcmp.c',
		'3rd/mp/mpdigdiv.c',
		'3rd/mp/mpdiv.c',
		'3rd/mp/mpexp.c',
		'3rd/mp/mpextendedgcd.c',
		'3rd/mp/mpfmt.c',
		'3rd/mp/mpinvert.c',
		'3rd/mp/mpleft.c',
		'3rd/mp/mplogic.c',
		'3rd/mp/mpmod.c',
		'3rd/mp/mpmodop.c',
		'3rd/mp/mpmul.c',
		'3rd/mp/mprand.c',
		'3rd/mp/mpright.c',
		'3rd/mp/mpsub.c',
		'3rd/mp/mptobe.c',
		'3rd/mp/mptober.c',
		'3rd/mp/mptod.c',
		'3rd/mp/mptoi.c',
		'3rd/mp/mptoui.c',
		'3rd/mp/mptouv.c',
		'3rd/mp/mptov.c',
		'3rd/mp/mpvecadd.c',
		'3rd/mp/mpveccmp.c',
		'3rd/mp/mpvecdigmuladd.c',
		'3rd/mp/mpvecsub.c',
		'3rd/mp/mpvectscmp.c',
		'3rd/mp/strtomp.c',
		'3rd/mp/u16.c',
	],
	include_directories: include_directories(
		'3rd/mp',
		platform,
	),
)

utf = static_library(
	'utf',
	[
		'3rd/utf/rune.c',
		'3rd/utf/runeistype.c',
		'3rd/utf/runetotype.c',
		'3rd/utf/utfnlen.c',
	],
	include_directories: include_directories(
		'3rd/utf',
		platform,
	),
)

flisp = executable(
	flisp_exe_name,
	sources: [
		src,
		boot,
		builtins,
	],
	dependencies: [
		math,
	] + extras,
	include_directories: include_directories(
		'3rd',
		'3rd/brieflz',
		'3rd/mp',
		'3rd/utf',
		platform,
	),
	link_with: [
		brieflz,
		common,
		mp,
		utf,
	],
)

if platform == 'macos'
	if host_machine.cpu() == 'm68k'
		template = 'femtolispm68k.r'
		rez_data = '--copy'
		rezflags = []
		flisp_code = flisp
	else
		template = 'femtolispppc.r'
		rez_data = '--data'
		rezflags = ['-DTARGET_API_MAC_CARBON=1']
		flisp_code = custom_target(
			'flisp.pef',
			input: [
				flisp
			],
			output: [
				'flisp.pef',
			],
			command: [
				meson.get_external_property('makepef'),
				'@INPUT@',
				'-o', '@OUTPUT@',
			],
		)
	endif
	rincludes = meson.get_external_property('rincludes')
	template = join_paths(meson.global_source_root(), 'macos', template)

	flisp_bin = custom_target(
		'flisp.bin',
		input: [
			flisp_code,
			template,
		],
		output: [
			'flisp.bin',
			'flisp.dsk',
		],
		command: [
			meson.get_external_property('rez'),
			'-I' + rincludes,
		] + rezflags + [
			template,
			'-DCFRAG_NAME="flisp"',
			'-o', 'flisp.bin',
			'-t', 'APPL',
			'-c', '????',
			rez_data, '@INPUT@',
			'--cc', 'flisp.dsk',
		],
		build_by_default: true,
	)
endif

build_tests = get_option('build-tests')
if build_tests.enabled()
	mptest = executable(
		'mptest',
		sources: [
			'3rd/mp/test.c',
		],
		include_directories: include_directories(
			platform,
		),
		link_with: [
			common,
			mp,
		],
	)
	test('mp', mptest)
	mptest2 = executable(
		'mptest2',
		sources: [
			'3rd/mp/test/convtest.c',
			'3rd/mp/test/gen.tab.c',
			'3rd/mp/test/ld.c',
			'3rd/mp/test/main.c',
		],
		include_directories: include_directories(
			'3rd/mp',
			'3rd/mp/test',
			platform,
		),
		link_with: [
			common,
			mp,
		],
	)
	test('mp2', mptest2, timeout: -1)
endif

tests_dir = join_paths(meson.current_source_dir(), 'test')

test('argv.lsp', flisp, args: ['argv.lsp'], workdir: tests_dir)
test('bench.lsp', flisp, args: ['bench.lsp'], workdir: tests_dir)
test('hashtest.lsp', flisp, args: ['hashtest.lsp'], workdir: tests_dir)
test('mp.lsp', flisp, args: ['mp.lsp'], workdir: tests_dir)
test('perf.lsp', flisp, args: ['perf.lsp'], workdir: tests_dir, timeout: -1)
test('tme.lsp', flisp, args: ['tme.lsp'], workdir: tests_dir)
test('torture.lsp', flisp, args: ['torture.scm'], workdir: tests_dir, timeout: -1)
test('torus.lsp', flisp, args: ['torus.lsp'], workdir: tests_dir)
test('unit.lsp', flisp, args: ['unittest.lsp'], workdir: tests_dir)