|
| 1 | +#!/usr/bin/env just --justfile |
| 2 | +# -------------------------------------------------------------- |
| 3 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | +# -------------------------------------------------------------- |
| 5 | +# Build File : justfile |
| 6 | +# File Authors : Aoran Zeng <[email protected]> |
| 7 | +# Contributors : Nul None <[email protected]> |
| 8 | +# | |
| 9 | +# Created On : <2025-06-18> |
| 10 | +# Last Modified : <2025-06-18> |
| 11 | +# |
| 12 | +# just (build) |
| 13 | +# just debug |
| 14 | +# just test |
| 15 | +# |
| 16 | +# just DEBUG=1 # 编译出 debug 版 |
| 17 | +# -------------------------------------------------------------- |
| 18 | + |
| 19 | +set windows-shell := ['cmd', '/c'] |
| 20 | + |
| 21 | +CC := 'gcc' |
| 22 | +DEBUGGER := 'gdb' |
| 23 | + |
| 24 | +CFLAGS_base := '-Iinclude -Ilib' |
| 25 | + |
| 26 | +CFLAGS_for_Clang := if os() == 'windows' { |
| 27 | + if CC == 'clang' { |
| 28 | + '-target x86_64-pc-windows-gnu' |
| 29 | + } else {''} |
| 30 | +} else {''} |
| 31 | + |
| 32 | + |
| 33 | +WARN := '-Wall -Wextra -Wno-unused-variable -Wno-unused-function -Wno-missing-braces -Wno-misleading-indentation' + ' ' + \ |
| 34 | + '-Wno-missing-field-initializers -Wno-unused-parameter -Wno-sign-compare' |
| 35 | +CFLAGS_warn := WARN |
| 36 | + |
| 37 | + |
| 38 | +DEBUG := '0' |
| 39 | +CFLAGS_debug := if DEBUG != '0' { "-g" } else { "" } |
| 40 | + |
| 41 | +Debuggable-Target-Name := 'chsrc-debug' |
| 42 | + |
| 43 | +Target-Name := if DEBUG != '0' { |
| 44 | + Debuggable-Target-Name |
| 45 | +} else { |
| 46 | + 'chsrc' |
| 47 | +} |
| 48 | + |
| 49 | +CI := '0' |
| 50 | +CI_ARTIFACT_NAME := 'chsrc' |
| 51 | + |
| 52 | +# 在 GitHub Actions 时的 Linux 环境下,just CI=1 时触发 |
| 53 | +CFLAGS_static := if os() == 'linux' { |
| 54 | + if CI == '0' { |
| 55 | + "-static" |
| 56 | + } else {''} |
| 57 | +} else {''} |
| 58 | + |
| 59 | + |
| 60 | +CFLAGS := CFLAGS_base + ' ' + CFLAGS_debug + ' ' + CFLAGS_warn + ' ' + CFLAGS_static + ' ' + CFLAGS_for_Clang |
| 61 | + |
| 62 | +CFLAGS_only_promp_for_dev := CFLAGS_base + ' ' + CFLAGS_debug + CFLAGS_static + CFLAGS_for_Clang |
| 63 | + |
| 64 | +#======================= |
| 65 | + |
| 66 | +alias b := build |
| 67 | +alias d := debug |
| 68 | +alias t := test |
| 69 | + |
| 70 | +default: build |
| 71 | + |
| 72 | +build: |
| 73 | + @echo Starting: Compile chsrc executable |
| 74 | + @{{CC}} src/chsrc-main.c {{CFLAGS}} -o {{Target-Name}} |
| 75 | + @echo Finished: Compile chsrc executable using '{{CC}}' {{CFLAGS_only_promp_for_dev}} -o {{Target-Name}} |
| 76 | + |
| 77 | +CI: build |
| 78 | + @mv {{Target-Name}} {{CI_ARTIFACT_NAME}} |
| 79 | + |
| 80 | +debug: |
| 81 | + @{{DEBUGGER}} {{Debuggable-Target-Name}} |
| 82 | + |
| 83 | +test: test-xy test-fw |
| 84 | + |
| 85 | +test-xy: |
| 86 | + @{{CC}} test/xy.c {{CFLAGS}} -o xy |
| 87 | + @./xy |
| 88 | + |
| 89 | +test-fw: |
| 90 | + @{{CC}} test/fw.c {{CFLAGS}} -o fw |
| 91 | + @./fw |
| 92 | + |
| 93 | + |
| 94 | +check: test |
| 95 | + |
| 96 | +fastcheck: |
| 97 | + @perl ./test/cli.pl fastcheck |
| 98 | + |
| 99 | +test-cli: |
| 100 | + @perl ./test/cli.pl |
| 101 | + |
| 102 | +clean: |
| 103 | + -@rm *.exe 2>/dev/null |
| 104 | + -@rm xy 2>/dev/null |
| 105 | + -@rm fw 2>/dev/null |
| 106 | + -@rm chsrc 2>/dev/null |
| 107 | + -@rm README.md.bak* 2>/dev/null |
0 commit comments