Skip to content

Commit f1140d6

Browse files
committed
ci自动发布编译文件
1 parent 43901f2 commit f1140d6

2 files changed

Lines changed: 134 additions & 13 deletions

File tree

.github/workflows/c-cpp.yml

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,110 @@ name: C/C++ CI
33
on:
44
push:
55
branches: [ "master" ]
6+
tags: [ "v*" ]
67
pull_request:
78
branches: [ "master" ]
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
813

914
jobs:
1015
build:
16+
name: Build ${{ matrix.platform }}
17+
runs-on: ${{ matrix.os }}
1118

12-
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- platform: linux-x86_64
24+
os: ubuntu-latest
25+
lib_src: libbeps.so
26+
lib_dst: libbeps-linux-x86_64.so
27+
exe_src: beps
28+
exe_dst: beps-linux-x86_64
29+
- platform: macos-x86_64
30+
os: macos-15-intel
31+
lib_src: libbeps.dylib
32+
lib_dst: libbeps-macos-x86_64.dylib
33+
exe_src: beps
34+
exe_dst: beps-macos-x86_64
35+
- platform: macos-arm64
36+
os: macos-15
37+
lib_src: libbeps.dylib
38+
lib_dst: libbeps-macos-arm64.dylib
39+
exe_src: beps
40+
exe_dst: beps-macos-arm64
41+
- platform: windows-x86_64
42+
os: windows-latest
43+
lib_src: libbeps.dll
44+
lib_dst: libbeps-windows-x86_64.dll
45+
exe_src: beps.exe
46+
exe_dst: beps-windows-x86_64.exe
1347

1448
steps:
15-
- uses: actions/checkout@v3
16-
#- name: configure
17-
# run: ./configure
18-
- name: make
19-
run: make
49+
- uses: actions/checkout@v4
50+
51+
- name: Setup MSYS2
52+
if: runner.os == 'Windows'
53+
uses: msys2/setup-msys2@v2
54+
with:
55+
msystem: MINGW64
56+
update: true
57+
install: make mingw-w64-x86_64-gcc
58+
59+
- name: Build
60+
if: runner.os != 'Windows'
61+
shell: bash
62+
run: make clean strip
63+
64+
- name: Build
65+
if: runner.os == 'Windows'
66+
shell: msys2 {0}
67+
run: make clean strip
68+
69+
- name: Package
70+
if: runner.os != 'Windows'
71+
shell: bash
72+
run: |
73+
mkdir -p dist
74+
cp "${{ matrix.lib_src }}" "dist/${{ matrix.lib_dst }}"
75+
cp "${{ matrix.exe_src }}" "dist/${{ matrix.exe_dst }}"
76+
77+
- name: Package
78+
if: runner.os == 'Windows'
79+
shell: msys2 {0}
80+
run: |
81+
mkdir -p dist
82+
cp "${{ matrix.lib_src }}" "dist/${{ matrix.lib_dst }}"
83+
cp "${{ matrix.exe_src }}" "dist/${{ matrix.exe_dst }}"
84+
85+
- name: Upload artifact
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: beps-${{ matrix.platform }}
89+
path: dist/*
90+
if-no-files-found: error
2091
#- name: make check
2192
# run: make check
2293
#- name: make distcheck
2394
# run: make distcheck
95+
96+
release:
97+
name: Publish release assets
98+
if: startsWith(github.ref, 'refs/tags/')
99+
needs: build
100+
runs-on: ubuntu-latest
101+
102+
steps:
103+
- name: Download build artifacts
104+
uses: actions/download-artifact@v4
105+
with:
106+
path: dist
107+
merge-multiple: true
108+
109+
- name: Upload release assets
110+
uses: softprops/action-gh-release@v2
111+
with:
112+
files: dist/*

Makefile

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22
# make file to compile beps program
33

44
# CFLAGS=-std=c99 -O3 -Wall
5-
CFLAGS=-std=c99 -g -O3 -Iinclude -fPIC
5+
6+
ifeq ($(OS),Windows_NT)
7+
EXE_EXT := .exe
8+
SHLIB_EXT := .dll
9+
SHLIB_FLAGS := -shared
10+
PIC_FLAG :=
11+
else
12+
UNAME_S := $(shell uname -s)
13+
EXE_EXT :=
14+
PIC_FLAG := -fPIC
15+
ifeq ($(UNAME_S),Darwin)
16+
SHLIB_EXT := .dylib
17+
SHLIB_FLAGS := -dynamiclib -Wl,-install_name,@rpath/libbeps$(SHLIB_EXT)
18+
else
19+
SHLIB_EXT := .so
20+
SHLIB_FLAGS := -shared
21+
endif
22+
endif
23+
24+
CFLAGS ?= -std=c99 -O3 -Iinclude $(PIC_FLAG)
25+
LDLIBS ?= -lm
26+
STRIP ?= strip
627

728
ODIR=build
829
IDIR=src
30+
TARGET := beps$(EXE_EXT)
31+
SHLIB := libbeps$(SHLIB_EXT)
32+
33+
.PHONY: all clean strip
934

1035
# first name a variable OBJSects for all OBJSect files
1136
_OBJS = Leaf.o aerodynamic_conductance.o bepsmain_pnt.o Leaf_Temperature.o \
@@ -30,23 +55,30 @@ OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
3055
# now give target as makebeps with OBJSects as variable dependencies + command line
3156

3257
# gcc=/usr/bin/gcc-9
33-
CC=gcc
58+
CC = gcc
3459
# icc -g -lm -o bepsp $(OBJSects)
3560
# echo $(OBJS)
3661

37-
beps.exe: $(OBJS)
38-
echo $(OBJS)
39-
$(CC) -shared $(CFLAGS) -o libbeps.dll $(OBJS) -lm
40-
$(CC) $(CFLAGS) -o beps.exe $(OBJS) -lm
62+
all: $(SHLIB) $(TARGET)
63+
64+
$(SHLIB): $(OBJS)
65+
$(CC) $(SHLIB_FLAGS) -o $@ $(OBJS) $(LDLIBS)
66+
67+
$(TARGET): $(OBJS)
68+
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDLIBS)
4169
# gcc $(CFLAGS) -o beps $(OBJSects) -lm
4270

4371
# list the dependencies for OBJSect files - those header files which help build OBJSects
4472
# how to build all OBJSect files from all dependent source files
4573
$(ODIR)/%.o: $(IDIR)/%.c
74+
mkdir -p $(ODIR)
4675
$(CC) -c -o $@ $< $(CFLAGS)
4776

4877
clean:
49-
-@rm $(OBJS) *.exe *.dll
78+
-@rm -f $(OBJS) beps beps.exe libbeps.dll libbeps.so libbeps.dylib
79+
80+
strip: all
81+
-@$(STRIP) $(SHLIB) $(TARGET)
5082

5183
# $(OBJSects): $(sources)
5284
# icc -g -c $(sources)

0 commit comments

Comments
 (0)