1 # 2 # CDDL HEADER START 3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the License). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at src/CDDL.txt 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at src/CDDL.txt. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets [] replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # ident "@(#)source.mk 1.42 08/06/05 SMI" 27 # 28 29 SUNMAKE = $(shell echo x | tr x \\043) 30 GNUMAKE :sh = echo \\043 31 32 $(SUNMAKE)OSVER:sh = uname -pr | cut -d. -f2 | awk '{print "Sol_"$1"/"$2}' 33 $(GNUMAKE)OSVER = $(shell uname -pr | cut -d. -f2 | awk '{print "Sol_"$1"/"$2}') 34 35 $(SUNMAKE)OS:sh = uname -s | tr "[a-z]" "[A-Z]" 36 $(GNUMAKE)OS = $(shell uname -s | tr "[a-z]" "[A-Z]") 37 38 BLDDIR = . 39 40 TC_TARGET = $(TC_NAME:%=$(BLDDIR)/%) 41 TC_CSRCS = $(TC_NAME:%=%.c) $(TC_NUMS:%=$(TC_NAME)_%.c) 42 TARGET += $(TC_TARGET) 43 44 #$(LD_NAME:%=$(BLDDIR)/lib%.so) 45 46 47 INC_TET_CTI = -I$(CTI_PROTO)/inc/tet3 -I$(CTI_PROTO)/contrib/ctitools/include 48 INC_TSET = $(INC_TET_CTI) -I../../../include -I../../include 49 INC_COMMON = -I../include 50 51 CFLAGS += $(INC_TSET) $(INC_COMMON) 52 53 #========================================================================== 54 # Generic rules 55 #========================================================================== 56 57 all : $(CTI_PROTO) $(TARGET) 58 59 ALLCSRCS = $(CSRCS) $(TC_CSRCS) $(COMMON_CSRCS) 60 61 lint : $(CTI_PROTO) $(ALLCSRCS:.c=.ln) $(CCSRCS:.cc=.ln) 62 cstyle : $(ALLCSRCS:.c=.cstyle) $(CCSRCS:.cc=.ccstyle) 63 64 proto pkgproto : $(CTI_PROTO) $(BLDDIR) $(TARGET) clean-proto 65 66 clobber : clean 67 /bin/ls core *% 2>/dev/null | xargs /bin/rm -f || continue 68 69 clean : clean-proto clean-ln 70 /bin/rm -f $(TARGET) $(GENSRCS) 71 72 clean-proto : clean-o clean-class 73 @rmdir $(BLDDIR) > /dev/null 2>&1 && \ 74 echo "rm $(BLDDIR)" || continue 75 76 clean-ln clean-o clean-class clean-so : 77 @ls $(BLDDIR)/$(@:clean-%=*.%) >/dev/null 2>&1 && (\ 78 echo "rm $(BLDDIR)/$(@:clean-%=*.%)";\ 79 /bin/rm -f $(BLDDIR)/$(@:clean-%=*.%) ) || continue 80 81 .cc.ln : 82 @echo 83 # $(LINT.c) -errfmt=simple -errhdr=%user -uxm $(CFLAGS) $? 84 85 .c.ln : 86 $(LINT.c) -errfmt=simple -errhdr=%user -uxm $(CFLAGS) $? 87 88 %style : % 89 cstyle -Pp $< 90 91 .c.o : 92 $(CC) $(CFLAGS) $< -o $@ -c 93 94 $(BLDDIR) : 95 mkdir -p $@ 96 97 98 #========================================================================== 99 # *.so compilation rules 100 #========================================================================== 101 102 LDFLAGS_SUNOS += -G 103 LDFLAGS_LINUX += -shared 104 LDFLAGS += $(LDFLAGS_$(OS)) 105 106 %_s.so : $(CSRCS:%.c=$(BLDDIR)/%_s.o) 107 $(LD) $(LDFLAGS) -o $@ $? 108 109 %prog.so : $(CSRCS_PROG:%.c=$(BLDDIR)/%_prog.o) 110 $(LD) $(LDFLAGS) -o $@ $? 111 112 %prog_thr.so : $(CSRCS_PROG:%.c=$(BLDDIR)/%_prog_thr.o) 113 $(LD) $(LDFLAGS) -o $@ $? 114 115 %_thr.so : $(CSRCS:%.c=$(BLDDIR)/%_thr.o) 116 $(LD) $(LDFLAGS) -o $@ $? 117 118 %.so : $(CSRCS:%.c=$(BLDDIR)/%.o) 119 $(LD) $(LDFLAGS) -o $@ $? 120 121 #========================================================================== 122 # *.o compilation rules 123 #========================================================================== 124 125 CFLAGS-sparc = -xarch=v8 126 CFLAGS_THR_SUNOS = -DTET_THREADS -mt 127 CFLAGS_THR_LINUX = -DTET_POSIX_THREADS 128 CFLAGS_THR = -D_REENTRANT $(CFLAGS_THR_$(OS)) 129 130 CFLAGS += $(CFLAGS_$(THREAD:thr=THR)) 131 132 $(BLDDIR)/%_prog_thr.o $(BLDDIR)/%_thr.o : %.c 133 $(CC) $(CFLAGS$(HOST_ARCH)) $(CFLAGS) $(CFLAGS_THR) $? -o $@ -c 134 135 $(BLDDIR)/%_s.o : %.c 136 $(CC) $(CFLAGS$(HOST_ARCH)) $(CFLAGS) -DTET_SHLIB $? -o $@ -c 137 138 $(BLDDIR)/%_prog.o $(BLDDIR)/%.o : %.c 139 $(CC) $(CFLAGS$(HOST_ARCH)) $(CFLAGS) $? -o $@ -c 140 141 142 #========================================================================== 143 # Executable compilation rules 144 #========================================================================== 145 146 _THREAD = $(THREAD:%=_%) 147 148 LIB_CTI = -L$(CTI_PROTO)/contrib/ctitools/lib -lCommonTest$(_THREAD) 149 LIB_TSET = -L../../../lib -L../../lib -L../lib -lDsMcTest$(_THREAD) -lsocket -lnsl $(THREAD:thr=-lthread) 150 151 $(TC_TARGET) : $(TC_CSRCS:%.c=$(BLDDIR)/%.o) $(CTI_PROTO)/lib/tet3/$(THREAD)tcm.o $(CTI_PROTO)/lib/tet3/lib$(THREAD)api.a 152 cd $(@D); $(CC) $(CFLAGS$(HOST_ARCH)) $(LIB_CTI) $(LIB_TSET) -o $@ $(?:$(@D)/%=%) 153 154 155 # binary compilation (./bin/*) 156 157 $(BLDDIR:%/csrc=%/bin)/% : %.c $(COMMON_CSRCS:%.c=$(BLDDIR)/%.o) $(EXT_OBJS) 158 test -d $(@D) || mkdir -p $(@D) 159 $(CC) $(CFLAGS$(HOST_ARCH)) $(CFLAGS) -o $@ $? 160 161 #========================================================================== 162 # java compilation rules 163 #========================================================================== 164 165 $(BLDDIR)/%.jar : $(JSRCS:%.java=%.class) 166 $(JAR) cvf $@ $? ; /bin/rm -f $? 167 168 %.class : %.java 169 $(JAVAC) -classpath $(CTI_PROTO)/lib/java/jet.jar:. $? 170 171 #========================================================================== 172 173 174 175