8 QUIETLY := 1>/dev/null 2>/dev/null
13 ##### sources, objects and libraries #####
15 ARFILENAME := $(BINNAME).a
16 ARPATHNAME := $(BINDIR)/$(ARFILENAME)
17 SOBASENAME := $(BINNAME).so
18 SONAME := $(SOBASENAME).$(VERSION_NUMBER)
19 SOFILENAME := $(SONAME).$(MINOR_NUMBER).$(RELEASE_NUMBER)
20 SOPATHNAME := $(BINDIR)/$(SOFILENAME)
21 INCNAME := $(INCDIR)/$(BINNAME).h
22 SRCDIRS := libshared_ansi libshared_memory libshared_misc libshared_porting_abstraction_layer
23 SOURCES := libshared_ansi_strcat.c libshared_ansi_strcat_char.c libshared_ansi_strcat_number.c libshared_ansi_strcpy.c libshared_ansi_strlen.c \
24 libshared_memory_add.c libshared_memory_alloc.c libshared_memory_cleanup.c libshared_memory_init.c libshared_memory_query.c libshared_memory_rollback.c \
25 libshared_misc_query.c \
26 libshared_porting_abstraction_layer_thread_start.c libshared_porting_abstraction_layer_thread_wait.c
27 OBJECTS := $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(SOURCES)))
32 DGFLAGS_MANDATORY := -MM
33 DGFLAGS_OPTIONAL := -std=gnu89
36 CFLAGS_MANDATORY := -c
37 CFLAGS_OPTIONAL := -ffreestanding -std=gnu89 -Wall -Werror -Wno-unknown-pragmas
38 CFLAGS_MANDATORY_COV := -O0 -ggdb -DCOVERAGE -fprofile-arcs -ftest-coverage
39 CFLAGS_MANDATORY_DBG := -O0 -ggdb -D_DEBUG
40 CFLAGS_MANDATORY_PROF := -O0 -ggdb -DPROF -pg
41 CFLAGS_MANDATORY_REL := -O2 -DNDEBUG
42 CFLAGS_MANDATORY_TSAN := -O0 -ggdb -DTSAN -fsanitize=thread -fPIC
46 ARFLAGS_MANDATORY := rcs
50 LDFLAGS_MANDATORY := -shared -Wl,-soname,$(SONAME) -o $(SOPATHNAME)
51 LDFLAGS_OPTIONAL := -nodefaultlibs -nostdlib -std=gnu89 -Wall -Werror
52 LDFLAGS_MANDATORY_COV := -O0 -fprofile-arcs -ftest-coverage
53 LDFLAGS_MANDATORY_DBG := -O0 -ggdb
54 LDFLAGS_MANDATORY_PROF := -O0 -pg
55 LDFLAGS_MANDATORY_REL := -O2 -s
56 LDFLAGS_MANDATORY_TSAN := -O0 -fsanitize=thread -fPIC
58 ##### build variants #####
59 ifeq ($(findstring so,$(MAKECMDGOALS)),so)
60 CFLAGS_MANDATORY += -fPIC
63 # TRD : default to debug
64 ifeq ($(MAKECMDGOALS),)
65 CFLAGS_MANDATORY += $(CFLAGS_MANDATORY_DBG)
66 LDFLAGS_MANDATORY += $(LDFLAGS_MANDATORY_DBG)
69 ifeq ($(findstring cov,$(MAKECMDGOALS)),cov)
70 CFLAGS_MANDATORY += $(CFLAGS_MANDATORY_COV)
71 LDFLAGS_MANDATORY += $(LDFLAGS_MANDATORY_COV)
75 ifeq ($(findstring dbg,$(MAKECMDGOALS)),dbg)
76 CFLAGS_MANDATORY += $(CFLAGS_MANDATORY_DBG)
77 LDFLAGS_MANDATORY += $(LDFLAGS_MANDATORY_DBG)
80 ifeq ($(findstring prof,$(MAKECMDGOALS)),prof)
81 CFLAGS_MANDATORY += $(CFLAGS_MANDATORY_PROF)
82 LDFLAGS_MANDATORY += $(LDFLAGS_MANDATORY_PROF)
85 ifeq ($(findstring rel,$(MAKECMDGOALS)),rel)
86 CFLAGS_MANDATORY += $(CFLAGS_MANDATORY_REL)
87 LDFLAGS_MANDATORY += $(LDFLAGS_MANDATORY_REL)
90 ifeq ($(findstring tsan,$(MAKECMDGOALS)),tsan)
91 CFLAGS_MANDATORY += $(CFLAGS_MANDATORY_TSAN)
92 LDFLAGS_MANDATORY += $(LDFLAGS_MANDATORY_TSAN)
95 ##### search paths #####
96 vpath %.c $(patsubst %,$(SRCDIR)/%:,$(SRCDIRS))
98 ##### implicit rules #####
100 $(DG) $(DGFLAGS_OPTIONAL) $(DGFLAGS) $(DGFLAGS_MANDATORY) $< >$(OBJDIR)/$*.d
101 $(CC) $(CFLAGS_OPTIONAL) $(CFLAGS) $(CFLAGS_MANDATORY) -o $@ $<
103 ##### explicit rules #####
104 $(ARPATHNAME) : $(OBJECTS)
105 $(AR) $(ARFLAGS_OPTIONAL) $(ARFLAGS) $(ARFLAGS_MANDATORY) $(ARPATHNAME) $(OBJECTS)
107 $(SOPATHNAME) : $(OBJECTS)
108 $(LD) $(LDFLAGS_OPTIONAL) $(LDFLAGS) $(LDFLAGS_MANDATORY) $(OBJECTS) -o $(SOPATHNAME)
109 @ln -fs $(SOFILENAME) $(BINDIR)/$(SONAME)
110 @ln -fs $(SOFILENAME) $(BINDIR)/$(SOBASENAME)
113 .PHONY : clean ar_cov ar_dbg ar_prof ar_rel ar_tsan ar_vanilla so_dbg so_prof so_rel so_tsan so_vanilla
116 @rm -f $(BINDIR)/* $(OBJDIR)/*
118 ar_cov : $(ARPATHNAME) # archive (.a), coverage
119 ar_dbg : $(ARPATHNAME) # archive (.a), debug
120 ar_prof : $(ARPATHNAME) # archive (.a), profiling
121 ar_rel : $(ARPATHNAME) # archive (.a), release
122 ar_tsan : $(ARPATHNAME) # archive (.a), thread sanitizer
123 ar_vanilla : $(ARPATHNAME) # archive (.a), no specific-build arguments
125 # TRD : leading backslash to use command rather than alias
126 # as many Linux distros have a built-in alias to force
127 # a prompt ("y/n?") on file overwrite - silent and
128 # unexpected interference which breaks a makefile
129 @mkdir -p $(INSLIBDIR)
130 @\cp $(ARPATHNAME) $(INSLIBDIR)
131 @mkdir -p $(INSINCDIR)
132 @\cp -r $(INCDIR)/* $(INSINCDIR)
134 @rm $(INSLIBDIR)/$(ARFILENAME)
135 @rm -r $(INSINCDIR)/$(BINNAME)
136 @rm -r $(INSINCDIR)/$(BINNAME).h
138 # TRD : so_cov currently disabled as it cannot work with -nostdlib -nodefaultlibs
139 # so_cov : $(SOPATHNAME) # shared (.so), coverage
140 so_dbg : $(SOPATHNAME) # shared (.so), debug
141 so_prof : $(SOPATHNAME) # shared (.so), profiling
142 so_rel : $(SOPATHNAME) # shared (.so), release
143 so_tsan : $(SOPATHNAME) # shared (.so), thread sanitizer
144 so_vanilla : $(SOPATHNAME) # shared (.so), no specific-build arguments
146 @mkdir -p $(INSINCDIR)
147 @\cp $(SOPATHNAME) $(INSLIBDIR)
148 @ldconfig -vn $(INSLIBDIR)
149 @ln -s $(SONAME) $(INSLIBDIR)/$(SOBASENAME)
150 @mkdir -p $(INSLIBDIR)
151 @\cp -r $(INCDIR)/* $(INSINCDIR)
153 @rm -f $(INSLIBDIR)/$(SOFILENAME)
154 @rm -f $(INSLIBDIR)/$(SOBASENAME)
155 @rm -f $(INSLIBDIR)/$(SONAME)
156 @rm -r $(INSINCDIR)/$(BINNAME)
157 @rm -r $(INSINCDIR)/$(BINNAME).h
159 ##### dependencies #####