-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (123 loc) · 6.76 KB
/
Copy pathMakefile
File metadata and controls
142 lines (123 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/make -f
SHELL := /bin/bash
# Local path overrides — copy config.mk.example to config.mk and edit.
-include config.mk
# Point at the GRASS GIS source tree.
# Override in config.mk or on the command line: make MODULE_TOPDIR=/path/to/grass
MODULE_TOPDIR ?= $(HOME)/dev/grass
# Derived GRASS paths (mirrors grass-addons convention)
GRASS_PREFIX := $(shell ls -d /usr/local/grass[0-9]* 2>/dev/null | sort -V | tail -1)
ifeq ($(GRASS_PREFIX),)
GRASS_PREFIX := /usr/local/grass86
endif
# Install target: default is the running GRASS installation.
# For user-level: make install INST_DIR=~/.grass8/addons
INST_DIR ?= $(GRASS_PREFIX)
CSPICE_SRC := $(CURDIR)/cspice-pkg/cspice
CSPICE_BUILD := $(CURDIR)/cspice-pkg/build
# GRASS toolboxes.py has a Python 3 bug: write_text(bytes) instead of write_bytes.
# This prevents user toolboxes (Planetary menu) from ever being written to disk.
# We patch the GRASS source before building and restore it afterwards.
GRASS_TOOLBOXES := $(MODULE_TOPDIR)/gui/wxpython/core/toolboxes.py
GRASS_TOOLBOXES_BAK := $(GRASS_TOOLBOXES).planetary.bak
.PHONY: all cspice utils libs modules install clean clean-obj deb patch-grass unpatch-grass
# ── default ───────────────────────────────────────────────────────────────────
all: cspice utils modules
# ── libcspice.so ──────────────────────────────────────────────────────────────
cspice: $(CSPICE_BUILD)/libcspice.so
$(CSPICE_BUILD)/libcspice.so:
mkdir -p $(CSPICE_BUILD)
gcc -shared -fPIC -O2 -w -std=gnu89 -DNON_UNIX_STDIO \
-I$(CSPICE_SRC)/include \
-o $@ \
$(CSPICE_SRC)/src/cspice/*.c -lm
@echo "=== libcspice.so built ==="
# ── SPICE utility programs ────────────────────────────────────────────────────
utils: $(CSPICE_BUILD)/libcspice.so
$(MAKE) -C cspice-pkg/utils CSPICE_BUILD=$(CSPICE_BUILD) INST_DIR=$(INST_DIR)
# ── GRASS toolboxes.py patch (apply before build, always restore after) ──────
patch-grass:
@if grep -q 'write_text(xml)' $(GRASS_TOOLBOXES) 2>/dev/null; then \
cp $(GRASS_TOOLBOXES) $(GRASS_TOOLBOXES_BAK); \
sed -i 's/Path(menudataFile)\.write_text(xml)/Path(menudataFile).write_bytes(xml)/' \
$(GRASS_TOOLBOXES); \
echo "=== Patched $(GRASS_TOOLBOXES) ==="; \
fi
unpatch-grass:
@if [ -f $(GRASS_TOOLBOXES_BAK) ]; then \
mv $(GRASS_TOOLBOXES_BAK) $(GRASS_TOOLBOXES); \
echo "=== Restored $(GRASS_TOOLBOXES) ==="; \
fi
# ── all modules via GRASS build system ───────────────────────────────────────
# libs/ sub-objects are compiled on demand by each module's DEPENDENCIES.
# Removes stale OBJ.* dirs first to prevent GRASS version hash mismatch.
# The patch/unpatch wrapper ensures toolboxes.py is always restored even if
# the build fails.
modules: clean-obj
python3 scripts/md2html_grass.py planetary/
@$(MAKE) patch-grass
@_exit=0; \
$(MAKE) -C planetary MODULE_TOPDIR=$(MODULE_TOPDIR) || _exit=$$?; \
$(MAKE) unpatch-grass; \
exit $$_exit
# ── libpsunmask.so (ctypes library used by p.illumination.sunfraction) ────────
libpsunmask:
$(MAKE) -C planetary/p.sunmask -f Makefile.standalone \
GISBASE=$(GRASS_PREFIX)
# ── install directly into GRASS (mirrors update.sh workflow) ─────────────────
# Modules land in $(INST_DIR)/bin/ and $(INST_DIR)/scripts/.
# p_lib.py and p_spice.py go to $(INST_DIR)/ so that
# dirname(dirname(abspath(script))) resolves correctly for scripts/.
# Build first with 'make' or 'make all', then 'sudo make install'.
install:
$(MAKE) -C cspice-pkg/utils CSPICE_BUILD=$(CSPICE_BUILD) INST_DIR=$(INST_DIR) install
$(MAKE) -C planetary MODULE_TOPDIR=$(MODULE_TOPDIR) \
INST_DIR=$(INST_DIR) install
mkdir -p $(INST_DIR)/etc/planetary
install -m 0644 data/matter_bands.json $(INST_DIR)/etc/planetary/matter_bands.json
mkdir -p $(INST_DIR)/planetary
for f in bodies/moon.json bodies/mars.json bodies/venus.json; do \
install -m 0644 $$f $(INST_DIR)/planetary/$$(basename $$f); \
done
mkdir -p $(INST_DIR)/planetary/missions
for f in missions/*.json missions/README.md; do \
[ -f "$$f" ] && install -m 0644 $$f \
$(INST_DIR)/planetary/missions/$$(basename $$f) || true; \
done
# ── wxGUI toolboxes → user config dir ─────────────────────────────────
@TBDIR="$(HOME)/.grass8/toolboxes"; \
mkdir -p "$$TBDIR"; \
for f in toolboxes/main_menu.xml toolboxes/toolboxes.xml; do \
dest="$$TBDIR/$$(basename $$f)"; \
if [ -f "$$dest" ]; then \
echo " Backing up $$dest → $$dest.bak"; \
cp "$$dest" "$$dest.bak"; \
fi; \
install -m 0644 $$f "$$dest"; \
echo " Installed $$f → $$dest"; \
done
@echo "=== Installed to $(INST_DIR) ==="
# ── Debian package build ──────────────────────────────────────────────────────
# Stamps a datetime version suffix so dpkg always overwrites installed files.
deb: clean
python3 debian/stamp-version.py
dpkg-buildpackage -us -uc -b
# ── remove stale OBJ dirs (prevents GRASS version hash mismatch) ─────────────
clean-obj:
@find planetary -maxdepth 2 -name 'OBJ.*' -type d -exec rm -rf {} + 2>/dev/null || true
# ── full clean ────────────────────────────────────────────────────────────────
clean:
rm -f $(CSPICE_BUILD)/libcspice.so
$(MAKE) -C cspice-pkg/utils clean 2>/dev/null || true
find planetary -maxdepth 2 -name 'OBJ.*' -type d -exec rm -rf {} + 2>/dev/null || true
$(MAKE) -C planetary MODULE_TOPDIR=$(MODULE_TOPDIR) clean 2>/dev/null || true
$(MAKE) -C planetary/p.sunmask -f Makefile.standalone clean 2>/dev/null || true
$(MAKE) -C planetary/p.horizon.gpu -f Makefile.standalone clean 2>/dev/null || true
find planetary -name '__pycache__' -exec rm -rf {} + 2>/dev/null || true
find planetary -name '*.pyc' -delete 2>/dev/null || true
find planetary -maxdepth 3 -name '*.html' -delete 2>/dev/null || true
find planetary -name '.pytest_cache' -exec rm -rf {} + 2>/dev/null || true
rm -rf debian/.debhelper debian/debhelper-build-stamp \
debian/grass-planetary-addons debian/planetary-cspice \
debian/*.substvars debian/*.debhelper.log debian/files
@echo "=== Clean done ==="