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

Makefile (6768B)


      1 # Copyright (C) 2022, 2025, 2026 |Méso|Star> (contact@meso-star.com)
      2 # Copyright (C) 2025, 2026 Université de Lorraine
      3 # Copyright (C) 2022 Centre National de la Recherche Scientifique
      4 # Copyright (C) 2022 Université Paul Sabatier
      5 #
      6 # This program is free software: you can redistribute it and/or modify
      7 # it under the terms of the GNU General Public License as published by
      8 # the Free Software Foundation, either version 3 of the License, or
      9 # (at your option) any later version.
     10 #
     11 # This program is distributed in the hope that it will be useful,
     12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     14 # GNU General Public License for more details.
     15 #
     16 # You should have received a copy of the GNU General Public License
     17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     18 
     19 .POSIX:
     20 .SUFFIXES: # Clean up default inference rules
     21 
     22 include config.mk
     23 
     24 LIBNAME_STATIC = libshtr.a
     25 LIBNAME_SHARED = libshtr.so
     26 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     27 
     28 default: library
     29 all: library tests utils
     30 
     31 ################################################################################
     32 # Library building
     33 ################################################################################
     34 SRC = \
     35  src/shtr.c \
     36  src/shtr_cache.c \
     37  src/shtr_isotope_metadata.c \
     38  src/shtr_line_list.c \
     39  src/shtr_param.c
     40 OBJ = $(SRC:.c=.o)
     41 DEP = $(SRC:.c=.d)
     42 
     43 CFLAGS_LIB = -std=c99 $(CFLAGS_SO) $(INCS) -DSHTR_SHARED_BUILD
     44 LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS) -lm
     45 
     46 library: .config $(DEP)
     47 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     48 	$$(if [ -n "$(LIBNAME)" ]; then\
     49 	     echo "$(LIBNAME)";\
     50 	   else\
     51 	     echo "$(LIBNAME_SHARED)";\
     52 	   fi)
     53 
     54 $(DEP) $(OBJ): config.mk
     55 
     56 $(LIBNAME_SHARED): $(OBJ)
     57 	$(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB)
     58 
     59 $(LIBNAME_STATIC): libshtr.o
     60 	$(AR) -rc $@ $?
     61 	$(RANLIB) $@
     62 
     63 libshtr.o: $(OBJ)
     64 	$(LD) -r $(OBJ) -o $@
     65 	$(OBJCOPY) $(OCPFLAGS) $@
     66 
     67 .config: config.mk
     68 	$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
     69 	$(PKG_CONFIG) --atleast-version $(ZLIB_VERSION) zlib
     70 	echo "config done" > $@
     71 
     72 .SUFFIXES: .c .d .o
     73 .c.d:
     74 	@$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     75 
     76 .c.o:
     77 	$(CC) $(CFLAGS_LIB) -c $< -o $@
     78 
     79 ################################################################################
     80 # Utils
     81 ################################################################################
     82 UTIL_SRC = src/shtr_main.c
     83 UTIL_OBJ = $(UTIL_SRC:.c=.o)
     84 UTIL_DEP = $(UTIL_SRC:.c=.d)
     85 
     86 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
     87 
     88 INCS_UTIL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys shtr-local)
     89 LIBS_UTIL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys shtr-local)
     90 
     91 CFLAGS_UTIL = -std=c89 $(CFLAGS_EXE) $(INCS_UTIL)
     92 LDFLAGS_UTIL = $(LDFLAGS_EXE) $(LIBS_UTIL)
     93 
     94 utils: library $(UTIL_DEP)
     95 	@$(MAKE) -fMakefile \
     96 	$$(for i in $(UTIL_DEP); do printf -- '-f%s\n' "$${i}"; done) \
     97 	shtr
     98 
     99 shtr: config.mk shtr-local.pc src/shtr_main.o $(LIBNAME)
    100 	$(CC) $(CFLAGS_UTIL) -o $@ src/shtr_main.o $(LDFLAGS_UTIL)
    101 
    102 $(UTIL_DEP): config.mk shtr-local.pc
    103 	$(CC) $(CFLAGS_UTIL) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    104 
    105 $(UTIL_OBJ): config.mk shtr-local.pc
    106 	$(CC) $(CFLAGS_UTIL) -c $(@:.o=.c) -o $@
    107 
    108 ################################################################################
    109 # Installation
    110 ################################################################################
    111 pkg:
    112 	sed -e 's#@PREFIX@#$(PREFIX)#g' \
    113 	    -e 's#@VERSION@#$(VERSION)#g' \
    114 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
    115 	    -e 's#@ZLIB_VERSION@#$(ZLIB_VERSION)#g' \
    116 	    shtr.pc.in > shtr.pc
    117 
    118 shtr-local.pc: shtr.pc.in
    119 	sed -e '1d'\
    120 	    -e 's#^includedir=.*#includedir=./src/#' \
    121 	    -e 's#^libdir=.*#libdir=./#' \
    122 	    -e 's#@VERSION@#$(VERSION)#g' \
    123 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
    124 	    -e 's#@ZLIB_VERSION@#$(ZLIB_VERSION)#g' \
    125 	    shtr.pc.in > $@
    126 
    127 install: library pkg utils
    128 	install() { mode="$$1"; prefix="$$2"; shift 2; \
    129 	  mkdir -p "$${prefix}"; \
    130 	  cp "$$@" "$${prefix}"; \
    131 	  printf '%s\n' "$${@}" | while read -r i; do \
    132 	    chmod "$${mode}" "$${prefix}/$${i##*/}"; \
    133 	  done; \
    134 	}; \
    135 	if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \
    136 	install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \
    137 	install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" shtr.pc; \
    138 	install 755 "$(DESTDIR)$(BINPREFIX)" shtr; \
    139 	install 644 "$(DESTDIR)$(INCPREFIX)/star" src/shtr.h; \
    140 	install 644 "$(DESTDIR)$(MANPREFIX)/man1" doc/shtr.1; \
    141 	install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-hitran" COPYING README.md
    142 
    143 uninstall:
    144 	rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
    145 	rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/shtr.pc"
    146 	rm -f "$(DESTDIR)$(BINPREFIX)/shtr"
    147 	rm -f "$(DESTDIR)$(INCPREFIX)/star/shtr.h"
    148 	rm -f "$(DESTDIR)$(MANPREFIX)/man1/shtr.1"
    149 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-hitran/COPYING"
    150 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-hitran/README.md"
    151 
    152 clean: clean_test
    153 	rm -f $(OBJ) $(DEP) $(LIBNAME)
    154 	rm -f $(UTIL_OBJ) $(UTIL_DEP) shtr
    155 	rm -f .config libshtr.o shtr.pc shtr-local.pc
    156 
    157 lint:
    158 	mandoc -Tlint doc/shtr.1
    159 
    160 ################################################################################
    161 # Tests
    162 ################################################################################
    163 TEST_SRC = \
    164  src/test_shtr.c \
    165  src/test_shtr_isotope_metadata.c \
    166  src/test_shtr_lines.c
    167 TEST_OBJ = $(TEST_SRC:.c=.o)
    168 TEST_DEP = $(TEST_SRC:.c=.d)
    169 TEST_TGT = $(TEST_SRC:.c=.t)
    170 
    171 INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys shtr-local)
    172 LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys shtr-local)
    173 
    174 CFLAGS_TEST = -std=c89 $(CFLAGS_EXE) $(INCS_TEST)
    175 LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) -lm
    176 
    177 tests: library $(TEST_DEP) $(TEST_TGT)
    178 	@$(MAKE) -fMakefile \
    179 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    180 	$$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \
    181 	test_list
    182 
    183 $(TEST_TGT):
    184 	@{ \
    185 	  exe="$$(basename "$@" ".t")"; \
    186 	  printf '%s: %s\n' "$${exe}" $(@:.t=.o); \
    187 	  printf 'test_list: %s\n' "$${exe}"; \
    188 	} > $@
    189 
    190 $(TEST_DEP): config.mk shtr-local.pc
    191 	@$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    192 
    193 $(TEST_OBJ): config.mk shtr-local.pc
    194 	$(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@
    195 
    196 test_shtr \
    197 test_shtr_isotope_metadata \
    198 test_shtr_lines \
    199 : config.mk shtr-local.pc $(LIBNAME)
    200 	$(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST)
    201 
    202 clean_test:
    203 	rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT)
    204 	rm -f test_isotope_metadata.txt test_lines.txt
    205 	for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done
    206 
    207 test: tests
    208 	@err=0; \
    209 	for i in $(TEST_SRC); do \
    210 	  test="$$(basename "$${i}" ".c")"; \
    211 	  printf '%s' "$${test}"; \
    212 	  if "./$${test}" > /dev/null 2>&1; then \
    213 	    printf '\n'; \
    214 	  else \
    215 	    printf ': error %s\n' "$$?"; \
    216 	    err=$$((err+1)); \
    217 	  fi \
    218 	done; \
    219 	[ "$${err}" -eq 0 ]