star-hitran

Load line-by-line data from the HITRAN database
git clone git://git.meso-star.fr/star-hitran.git
Log | Files | Refs | README | LICENSE

commit 479e1b5bdf83f253b754f7446d317e6d2717f63a
parent 25890b163528bcceb71008b5b3077c30fd01a629
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 15 Dec 2025 15:49:44 +0100

Write a POSIX Makefile to replace CMake

The build procedure is written in POSIX make, which the user can
configure via the config.mk file. A pkg-config file is provided to link
the library as an external dependency.

In addition to the features already provided in its CMake alternative,
this Makefile supports the construction of static libraries and provides
an uninstall target. In any case, the main motivation behind its writing
is to use a good old well-established standard with simple features,
available on all UNIX systems, thus simplifying its portability and
support while being much lighter.

Diffstat:
M.gitignore | 18+++++++++---------
AMakefile | 183+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aconfig.mk | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ashtr.pc.in | 11+++++++++++
4 files changed, 285 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,12 +1,12 @@ -.gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp -[Bb]uild* -*.sw[po] *.[ao] -*.orig +*.d +*.pc +*.so +*.sw[po] +*.t *~ +.config +.gitignore tags - +test_* +!test_*.c diff --git a/Makefile b/Makefile @@ -0,0 +1,183 @@ +# Copyright (C) 2022 CNRS - LMD +# Copyright (C) 2022 |Meso|Star> (contact@meso-star.com) +# Copyright (C) 2022 Université Paul Sabatier - IRIT +# Copyright (C) 2022 Université Paul Sabatier - Laplace +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +LIBNAME_STATIC = libshtr.a +LIBNAME_SHARED = libshtr.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +default: library +all: library tests + +################################################################################ +# Library building +################################################################################ +SRC = \ + src/shtr.c \ + src/shtr_isotope_metadata.c \ + src/shtr_line_list.c \ + src/shtr_line_view.c \ + src/shtr_log.c \ + src/shtr_param.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +CFLAGS_LIB = $(CFLAGS_SO) $(INCS) -DSHTR_SHARED_BUILD +LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS) -lm + +library: .config $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ + $$(if [ -n "$(LIBNAME)" ]; then\ + echo "$(LIBNAME)";\ + else\ + echo "$(LIBNAME_SHARED)";\ + fi) + +$(DEP) $(OBJ): config.mk + +$(LIBNAME_SHARED): $(OBJ) + $(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB) + +$(LIBNAME_STATIC): libshtr.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +libshtr.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +.config: config.mk + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys + echo "config done" > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS_LIB) -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g' \ + -e 's#@VERSION@#$(VERSION)#g' \ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \ + shtr.pc.in > shtr.pc + +shtr-local.pc: shtr.pc.in + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#' \ + -e 's#^libdir=.*#libdir=./#' \ + -e 's#@VERSION@#$(VERSION)#g' \ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \ + shtr.pc.in > $@ + +install: library pkg + install() { mode="$$1"; prefix="$$2"; shift 2; \ + mkdir -p "$${prefix}"; \ + cp "$$@" "$${prefix}"; \ + printf '%s\n' "$${@}" | while read -r i; do \ + chmod "$${mode}" "$${prefix}/$${i##*/}"; \ + done; \ + }; \ + if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \ + install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \ + install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" shtr.pc; \ + install 644 "$(DESTDIR)$(INCPREFIX)/star" src/shtr.h; \ + install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-hitran" COPYING README.md + +uninstall: + rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)" + rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/shtr.pc" + rm -f "$(DESTDIR)$(INCPREFIX)/star/shtr.h" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-hitran/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-hitran/README.md" + +clean: clean_test + rm -f $(OBJ) $(DEP) $(LIBNAME) + rm -f .config libshtr.o shtr.pc shtr-local.pc + rm -f test_isotope_metadata.txt + +lint: + +################################################################################ +# Tests +################################################################################ +TEST_SRC = \ + src/test_shtr.c \ + src/test_shtr_isotope_metadata.c \ + src/test_shtr_lines.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) +TEST_TGT = $(TEST_SRC:.c=.t) + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys shtr-local) +LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys shtr-local) + +CFLAGS_TEST = $(CFLAGS_EXE) $(INCS_TEST) +LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) -lm + +tests: library $(TEST_DEP) $(TEST_TGT) + @$(MAKE) -fMakefile \ + $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ + $$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \ + test_list + +$(TEST_TGT): + @{ \ + exe="$$(basename "$@" ".t")"; \ + printf '%s: %s\n' "$${exe}" $(@:.t=.o); \ + printf 'test_list: %s\n' "$${exe}"; \ + } > $@ + +$(TEST_DEP): config.mk shtr-local.pc + @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(TEST_OBJ): config.mk shtr-local.pc + $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ + +test_shtr \ +test_shtr_isotope_metadata \ +test_shtr_lines \ +: config.mk shtr-local.pc $(LIBNAME) + $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) + +clean_test: + rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT) + for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done + +test: tests + @err=0; \ + for i in $(TEST_SRC); do \ + test="$$(basename "$${i}" ".c")"; \ + printf '%s' "$${test}"; \ + if "./$${test}" > /dev/null 2>&1; then \ + printf '\n'; \ + else \ + printf ': error %s\n' "$$?"; \ + err=$$((err+1)); \ + fi \ + done; \ + [ "$${err}" -eq 0 ] diff --git a/config.mk b/config.mk @@ -0,0 +1,82 @@ +VERSION = 0.0 +PREFIX = /usr/local + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +BINPREFIX = $(PREFIX)/bin +LIBPREFIX = $(PREFIX)/lib +INCPREFIX = $(PREFIX)/include +MANPREFIX = $(PREFIX)/share/man + +################################################################################ +# Tools +################################################################################ +AR = ar +CC = cc +LD = ld +OBJCOPY = objcopy +PKG_CONFIG = pkg-config +RANLIB = ranlib + +################################################################################ +# Dependencies +################################################################################ +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + +RSYS_VERSION = 0.14 + +INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +CFLAGS_HARDENED =\ + -std=c89\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON=\ + -pedantic\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) + +CFLAGS_SO = $(CFLAGS) -fPIC +CFLAGS_EXE = $(CFLAGS) -fPIE + +################################################################################ +# Linker options +################################################################################ +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) + +LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined +LDFLAGS_EXE = $(LDFLAGS) -pie + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +BOCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/shtr.pc.in b/shtr.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@ +Name: Star-STL +Description: Star HITRAN library +Version: @VERSION@ +Libs: -L${libdir} -lshtr +Libs.private: -lm +CFlags: -I${includedir}