Skip to content

Commit bc83870

Browse files
committed
Allow goose to be used as a library for folks who want to build their own package management
1 parent 7721703 commit bc83870

7 files changed

Lines changed: 54 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ jobs:
1616
run: make clean && make
1717

1818
- name: Verify binary
19-
run: ./goose --version
19+
run: ./build/goose --version
20+
21+
- name: Verify library
22+
run: test -f build/libgoose.a

.github/workflows/release.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ jobs:
6060
run: make clean && make
6161

6262
- name: Package
63-
run: tar czf ${{ matrix.artifact }}.tar.gz goose
63+
run: |
64+
mkdir -p staging/bin staging/lib staging/include/goose/headers
65+
cp build/goose staging/bin/
66+
cp build/libgoose.a staging/lib/
67+
cp include/goose.h staging/include/goose/
68+
cp src/headers/*.h staging/include/goose/headers/
69+
tar czf ${{ matrix.artifact }}.tar.gz -C staging .
6470
6571
- name: Upload artifact
6672
uses: actions/upload-artifact@v4

Makefile

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
VERSION = $(shell cat VERSION)
22

33
CC = cc
4-
CFLAGS = -Wall -Wextra -std=c11 -Ilibs/libyaml/include -DGOOSE_VERSION_FROM_FILE=\"$(VERSION)\"
4+
CFLAGS = -Wall -Wextra -std=c11 -Isrc -Ilibs/libyaml/include -DGOOSE_VERSION_FROM_FILE=\"$(VERSION)\"
55
LDFLAGS =
66

77
BUILD = build
@@ -10,19 +10,29 @@ OBJDIR = $(BUILD)/obj
1010
YAML_SRC = $(wildcard libs/libyaml/src/*.c)
1111
YAML_OBJ = $(YAML_SRC:libs/libyaml/src/%.c=$(OBJDIR)/yaml_%.o)
1212

13-
SRC = $(wildcard src/*.c)
13+
SRC = $(filter-out src/main.c, $(wildcard src/*.c))
1414
CMD_SRC = $(wildcard src/cmd/*.c)
15-
OBJ = $(SRC:src/%.c=$(OBJDIR)/%.o) $(CMD_SRC:src/cmd/%.c=$(OBJDIR)/cmd/%.o)
15+
LIB_OBJ = $(SRC:src/%.c=$(OBJDIR)/%.o) $(CMD_SRC:src/cmd/%.c=$(OBJDIR)/cmd/%.o) $(YAML_OBJ)
16+
CLI_OBJ = $(OBJDIR)/main.o
17+
18+
LIB = $(BUILD)/libgoose.a
1619
BIN = $(BUILD)/goose
1720

1821
PREFIX ?= /usr/local
1922

20-
.PHONY: all clean install uninstall
23+
.PHONY: all lib cli clean install uninstall
24+
25+
all: lib cli
26+
27+
lib: $(LIB)
28+
29+
cli: $(BIN)
2130

22-
all: $(BIN)
31+
$(LIB): $(LIB_OBJ)
32+
ar rcs $@ $^
2333

24-
$(BIN): $(OBJ) $(YAML_OBJ)
25-
$(CC) $(OBJ) $(YAML_OBJ) -o $@ $(LDFLAGS)
34+
$(BIN): $(CLI_OBJ) $(LIB)
35+
$(CC) $(CLI_OBJ) $(LIB) -o $@ $(LDFLAGS)
2636

2737
$(OBJDIR)/%.o: src/%.c | $(OBJDIR)
2838
$(CC) $(CFLAGS) -c $< -o $@
@@ -42,9 +52,18 @@ $(OBJDIR):
4252
clean:
4353
rm -rf $(BUILD)
4454

45-
install: $(BIN)
55+
install: all
4656
install -d $(PREFIX)/bin
4757
install -m 755 $(BIN) $(PREFIX)/bin/goose
58+
install -d $(PREFIX)/lib
59+
install -m 644 $(LIB) $(PREFIX)/lib/libgoose.a
60+
install -d $(PREFIX)/include/goose/headers
61+
install -m 644 include/goose.h $(PREFIX)/include/goose/goose.h
62+
for h in src/headers/*.h; do \
63+
install -m 644 "$$h" $(PREFIX)/include/goose/headers/; \
64+
done
4865

4966
uninstall:
5067
rm -f $(PREFIX)/bin/goose
68+
rm -f $(PREFIX)/lib/libgoose.a
69+
rm -rf $(PREFIX)/include/goose

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.3
1+
0.1.0

include/goose.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef GOOSE_H
2+
#define GOOSE_H
3+
4+
#include "headers/main.h"
5+
#include "headers/color.h"
6+
#include "headers/config.h"
7+
#include "headers/build.h"
8+
#include "headers/pkg.h"
9+
#include "headers/fs.h"
10+
#include "headers/lock.h"
11+
#include "headers/cmake.h"
12+
#include "headers/cmd.h"
13+
14+
#endif

src/headers/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@
1111
#define GOOSE_PKG_DIR "packages"
1212
#define GOOSE_BUILD "build"
1313

14-
void usage(void);
15-
1614
#endif

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static Command commands[] = {
2525
{NULL, NULL, NULL}
2626
};
2727

28-
void usage(void) {
28+
static void usage(void) {
2929
cprintf(CLR_GREEN, "goose %s", GOOSE_VERSION);
3030
printf(" - A package manager for C\n\n");
3131
printf("Usage: goose <command> [options]\n\n");

0 commit comments

Comments
 (0)