rnsl

Load a list of strings expanded by the shell
git clone git://git.meso-star.fr/rnsl.git
Log | Files | Refs | README | LICENSE

Makefile (5272B)


      1 # Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique
      2 # Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace
      3 # Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris
      4 # Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com)
      5 # Copyright (C) 2022, 2023 Observatoire de Paris
      6 # Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne
      7 # Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin
      8 # Copyright (C) 2022, 2023 Université Paul Sabatier
      9 #
     10 # This program is free software: you can redistribute it and/or modify
     11 # it under the terms of the GNU General Public License as published by
     12 # the Free Software Foundation, either version 3 of the License, or
     13 # (at your option) any later version.
     14 #
     15 # This program is distributed in the hope that it will be useful,
     16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     18 # GNU General Public License for more details.
     19 #
     20 # You should have received a copy of the GNU General Public License
     21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     22 
     23 .POSIX:
     24 .SUFFIXES: # Clean up default inference rules
     25 
     26 include config.mk
     27 
     28 LIBNAME_STATIC = librnsl.a
     29 LIBNAME_SHARED = librnsl.so
     30 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     31 
     32 ################################################################################
     33 # Library building
     34 ################################################################################
     35 SRC = src/rnsl.c src/rnsl_log.c
     36 OBJ = $(SRC:.c=.o)
     37 DEP = $(SRC:.c=.d)
     38 
     39 build_library: .config $(DEP)
     40 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     41 	$$(if [ -n "$(LIBNAME)" ]; then \
     42 	     echo "$(LIBNAME)"; \
     43 	   else \
     44 	     echo "$(LIBNAME_SHARED)"; \
     45 	   fi)
     46 
     47 $(DEP) $(OBJ): config.mk
     48 
     49 $(LIBNAME_SHARED): $(OBJ)
     50 	$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(RSYS_LIBS)
     51 
     52 $(LIBNAME_STATIC): librnsl.o
     53 	$(AR) -rc $@ $?
     54 	$(RANLIB) $@
     55 
     56 librnsl.o: $(OBJ)
     57 	$(LD) -r $(OBJ) -o $@
     58 	$(OBJCOPY) $(OCPFLAGS) $@
     59 
     60 .config: config.mk
     61 	@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
     62 	  echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
     63 	@echo "config done" > $@
     64 
     65 .SUFFIXES: .c .d .o
     66 .c.d:
     67 	@$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     68 
     69 .c.o:
     70 	$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -DRNSL_SHARED_BUILD -c $< -o $@
     71 
     72 ################################################################################
     73 # Installation
     74 ################################################################################
     75 pkg:
     76 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
     77 	    -e 's#@VERSION@#$(VERSION)#g'\
     78 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     79 	    rnsl.pc.in > rnsl.pc
     80 
     81 rnsl-local.pc: rnsl.pc.in
     82 	sed -e '1d'\
     83 	    -e 's#^includedir=.*#includedir=./src/#'\
     84 	    -e 's#^libdir=.*#libdir=./#'\
     85 	    -e 's#@VERSION@#$(VERSION)#g'\
     86 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     87 	    rnsl.pc.in > $@
     88 
     89 install: build_library pkg
     90 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
     91 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" rnsl.pc
     92 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/rad-net" src/rnsl.h
     93 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/rnsl" COPYING README.md
     94 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" rnsl.5
     95 
     96 uninstall:
     97 	rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
     98 	rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/rnsl.pc"
     99 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/rnsl/COPYING"
    100 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/rnsl/README.md"
    101 	rm -f "$(DESTDIR)$(PREFIX)/include/rad-net/rnsl.h"
    102 	rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/rnsl.5"
    103 
    104 ################################################################################
    105 # Miscellaneous targets
    106 ################################################################################
    107 all: build_library build_tests
    108 
    109 clean: clean_test
    110 	rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
    111 	rm -f .config .test librnsl.o rnsl.pc rnsl-local.pc
    112 
    113 distclean: clean
    114 	rm -f $(DEP) $(TEST_DEP)
    115 
    116 lint:
    117 	shellcheck -o all make.sh
    118 	mandoc -Tlint -Wall rnsl.5 || [ $$? -le 1 ]
    119 
    120 ################################################################################
    121 # Tests
    122 ################################################################################
    123 TEST_SRC =\
    124  src/test_rnsl.c\
    125  src/test_rnsl_load.c
    126 TEST_OBJ = $(TEST_SRC:.c=.o)
    127 TEST_DEP = $(TEST_SRC:.c=.d)
    128 
    129 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    130 RNSL_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rnsl-local.pc)
    131 RNSL_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rnsl-local.pc)
    132 
    133 test: build_tests
    134 	@$(SHELL) make.sh run_test $(TEST_SRC)
    135 
    136 build_tests: build_library $(TEST_DEP) .test
    137 	@$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
    138 
    139 .test: Makefile make.sh
    140 	@$(SHELL) make.sh config_test $(TEST_SRC) > $@
    141 
    142 clean_test:
    143 	$(SHELL) make.sh clean_test $(TEST_SRC) file.txt
    144 
    145 $(TEST_DEP): config.mk rnsl-local.pc
    146 	@$(CC) $(CFLAGS_EXE) $(RNSL_CFLAGS) $(RSYS_CFLAGS) \
    147 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    148 
    149 $(TEST_OBJ): config.mk rnsl-local.pc
    150 	$(CC) $(CFLAGS_EXE) $(RNSL_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@
    151 
    152 test_rnsl test_rnsl_load: config.mk rnsl-local.pc $(LIBNAME)
    153 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(RNSL_LIBS) $(RSYS_LIBS)