star-gf

Compute Gebhart factors
git clone git://git.meso-star.fr/star-gf.git
Log | Files | Refs | README | LICENSE

Makefile (5518B)


      1 # Copyright (C) 2021, 2024 |Meso|Star> (contact@meso-star.com)
      2 # Copyright (C) 2015-2018 EDF S.A., France (syrthes-support@edf.fr)
      3 #
      4 # This program is free software: you can redistribute it and/or modify
      5 # it under the terms of the GNU General Public License as published by
      6 # the Free Software Foundation, either version 3 of the License, or
      7 # (at your option) any later version.
      8 #
      9 # This program is distributed in the hope that it will be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12 # GNU General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU General Public License
     15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     16 
     17 .POSIX:
     18 .SUFFIXES: .b .c .d .o
     19 
     20 include config.mk
     21 
     22 LIBNAME_STATIC = libsgf.a
     23 LIBNAME_SHARED = libsgf.so
     24 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     25 
     26 default: library
     27 all: default tests
     28 
     29 ################################################################################
     30 # Library
     31 ################################################################################
     32 SRC = src/sgf_device.c src/sgf_estimator.c src/sgf_scene.c
     33 OBJ = $(SRC:.c=.o)
     34 DEP = $(SRC:.c=.d)
     35 
     36 library: .config $(DEP)
     37 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     38 	$$(if [ -n "$(LIBNAME)" ]; then \
     39 	     echo "$(LIBNAME)"; \
     40 	   else \
     41 	     echo "$(LIBNAME_SHARED)"; \
     42 	   fi)
     43 
     44 
     45 .config: Makefile config.mk
     46 	$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
     47 	$(PKG_CONFIG) --atleast-version $(S2D_VERSION) s2d
     48 	$(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d
     49 	$(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp
     50 	echo 'config done' > $@
     51 
     52 $(DEP) $(OBJ): config.mk
     53 
     54 $(LIBNAME_SHARED): $(OBJ)
     55 	$(CC) $(CFLAGS_SO) $(INCS) -o $@ $(OBJ) $(LDFLAGS_SO) $(LIBS)
     56 
     57 $(LIBNAME_STATIC): libsgf.o
     58 	$(AR) -rc $@ $?
     59 	$(RANLIB) $@
     60 
     61 libsgf.o: $(OBJ)
     62 	$(LD) -r $(OBJ) -o $@
     63 	$(OBJCOPY) $(OCPFLAGS) $@
     64 
     65 .c.d:
     66 	@$(CC) $(CFLAGS_SO) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     67 
     68 .c.o:
     69 	$(CC) $(CFLAGS_SO) $(INCS) -DSGF_SHARED_BUILD -c $< -o $@
     70 
     71 ################################################################################
     72 # Miscellaneous
     73 ################################################################################
     74 pkg:
     75 	sed -e 's#@INCDIR@#$(INCDIR)#g'\
     76 	    -e 's#@LIBDIR@#$(LIBDIR)#g'\
     77 	    -e 's#@VERSION@#$(VERSION)#g'\
     78 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     79 	    -e 's#@S2D_VERSION@#$(S2D_VERSION)#g'\
     80 	    -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\
     81 	    -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\
     82 	    sgf.pc.in > sgf.pc
     83 
     84 sgf-local.pc: sgf.pc.in config.mk
     85 	sed -e 's#@INCDIR@#./src#g'\
     86 	    -e 's#@LIBDIR@#./#g'\
     87 	    -e 's#@VERSION@#$(VERSION)#g'\
     88 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     89 	    -e 's#@S2D_VERSION@#$(S2D_VERSION)#g'\
     90 	    -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\
     91 	    -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\
     92 	    sgf.pc.in > $@
     93 
     94 install: library pkg
     95 	mkdir -p "$(DESTDIR)$(LIBDIR)"
     96 	cp $(LIBNAME) "$(DESTDIR)$(LIBDIR)"
     97 	chmod 755 "$(DESTDIR)$(LIBDIR)/$(LIBNAME)"
     98 	mkdir -p "$(DESTDIR)$(LIBDIR)/pkgconfig"
     99 	cp sgf.pc "$(DESTDIR)$(LIBDIR)/pkgconfig"
    100 	chmod 644 "$(DESTDIR)$(LIBDIR)/pkgconfig/sgf.pc"
    101 	mkdir -p "$(DESTDIR)$(INCDIR)/star"
    102 	cp src/sgf.h "$(DESTDIR)$(INCDIR)/star"
    103 	chmod 644 "$(DESTDIR)$(INCDIR)/star/sgf.h"
    104 	mkdir -p "$(DESTDIR)$(DOCDIR)/star-gf"
    105 	cp COPYING README.md "$(DESTDIR)$(DOCDIR)/star-gf"
    106 	chmod 644 "$(DESTDIR)$(DOCDIR)/star-gf/COPYING"
    107 	chmod 644 "$(DESTDIR)$(DOCDIR)/star-gf/README.md"
    108 
    109 uninstall:
    110 	rm -f "$(DESTDIR)$(LIBDIR)/$(LIBNAME)"
    111 	rm -f "$(DESTDIR)$(LIBDIR)/pkgconfig/sgf.pc"
    112 	rm -f "$(DESTDIR)$(INCDIR)/star/sgf.h"
    113 	rm -f "$(DESTDIR)$(DOCDIR)/star-gf/COPYING"
    114 	rm -f "$(DESTDIR)$(DOCDIR)/star-gf/README.md"
    115 
    116 clean: clean_tests
    117 	rm -f $(OBJ) $(DEP) sgf.pc libsgf.o .config
    118 	rm -f $(LIBNAME_STATIC) $(LIBNAME_SHARED)
    119 
    120 ################################################################################
    121 # Tests
    122 ################################################################################
    123 TEST_SRC =\
    124  src/test_sgf_cube.c\
    125  src/test_sgf_device.c\
    126  src/test_sgf_estimator.c\
    127  src/test_sgf_scene.c\
    128  src/test_sgf_square.c\
    129  src/test_sgf_tetrahedron.c
    130 TEST_OBJ = $(TEST_SRC:.c=.o)
    131 TEST_DEP = $(TEST_SRC:.c=.d)
    132 TEST_BIN = $(TEST_SRC:.c=.b)
    133 
    134 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    135 TEST_INCS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys sgf-local star-sp) -fopenmp
    136 TEST_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys sgf-local star-sp) -fopenmp
    137 
    138 test: tests
    139 	@for i in $(TEST_SRC); do \
    140 	  bin="$$(basename "$${i}" ".c")"; \
    141 	  "./$${bin}" > /dev/null 2>&1 \
    142 	    || >&2 printf '%s: error %s\n' "$${bin}" "$$?"; \
    143 	done
    144 	@echo "Tests done"
    145 
    146 tests: library $(TEST_DEP) $(TEST_BIN)
    147 	@$(MAKE) -fMakefile \
    148 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    149 	$$(for i in $(TEST_BIN); do echo -f"$${i}"; done) \
    150 	test_bin
    151 
    152 .c.b:
    153 	@{ \
    154 	  bin="$$(basename "$<" ".c")"; \
    155 	  printf '%s: %s\n' "$${bin}" $(<:.c=.o); \
    156 	  printf 'test_bin: %s\n' "$${bin}"; \
    157 	} > $@
    158 
    159 $(TEST_DEP): config.mk sgf-local.pc
    160 	@$(CC) $(CFLAGS_EXE) $(TEST_INCS)  -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    161 
    162 $(TEST_OBJ): config.mk sgf-local.pc
    163 	$(CC) $(CFLAGS_EXE) $(TEST_INCS) -c $(@:.o=.c) -o $@
    164 
    165 test_sgf_cube \
    166 test_sgf_device \
    167 test_sgf_estimator \
    168 test_sgf_scene \
    169 test_sgf_square \
    170 test_sgf_tetrahedron:
    171 	$(CC) $(CFLAGS_EXE) $(TEST_INCS) -o $@ src/$@.o $(LDFLAGS_EXE) $(TEST_LIBS)
    172 
    173 clean_tests:
    174 	rm -f $(TEST_OBJ) $(TEST_DEP) $(TEST_BIN) sgf-local.pc
    175 	for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done