star-cem

Compute the position of the sun
git clone git://git.meso-star.fr/star-cem.git
Log | Files | Refs | README | LICENSE

Makefile (6157B)


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