htcp

Properties of water suspended in clouds
git clone git://git.meso-star.fr/htcp.git
Log | Files | Refs | README | LICENSE

Makefile (6886B)


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