cheng_bingyuan 发表于 2013-01-01 19:24

关于makefile伪目标的问题

下面“一”中是我下的软件源码中makefile中的一部分,我在linux平台下编译: make linux ,应该只会执行伪目标"linux"下的内容,为什么也会执行伪目标"linuxa"的内容,执行结果见“二”最下方,我发现与些相关的地方就是在伪目标“linux”最后有个“linuxa”,我做了个实验,将linuxa改为abing, 然后手动加了个伪目标abing,执行make linux发现在伪目标“linux”中并不会调用abing,所以不明白在伪目标“linux”是如何调用伪目标“linuxa”的。

一、makefile中的一部分

linuxa:
        @echo 'Making C-Kermit $(CKVER) for Linux 1.2 or later...'
        @echo 'IMPORTANT: Read the comments in the linux section of the'
        @echo 'makefile if you have trouble.'
        $(MAKE) xermit KTARGET=$${KTARGET:-$(@)} "CC = gcc" "CC2 = gcc" \
        "CFLAGS = -O -DLINUX -pipe -funsigned-char -DFNFLOAT -DCK_POSIX_SIG \
        -DCK_NEWTERM -DTCPSOCKET -DLINUXFSSTND -DNOCOTFMC -DPOSIX \
        -DUSE_STRERROR $(KFLAGS)" "LNKFLAGS = $(LNKFLAGS)" \
        "LIBS = $(LIBS) -lm"

# As above but with profiling
linuxp:
        $(MAKE) linuxa KTARGET=$${KTARGET:-$(@)} "KFLAGS=$(KFLAGS) -pg" \
        "LIBS=-pg -lcrypt -lresolv"

#Linux.This entry should work for any Linux distribution on any platform,
#32-bit or 64-bit, except for extremely ancient ones.Automatically detects:
# . curses, ncurses, or no curses
# . Old versus new pty handling (new == glibc 2.1++)
# . Presence or absence of libcrypt.a and <crypt.h>
# . Presence or absence of libresolv.a
# . Transitional Long File API for 32-bit platforms (SUS V2 UNIX 98 LFS).
#Note: The HAVE_PTMX test was previously "if test -c /dev/ptmx" but this was
#not sufficient for Debian 2.1, because although it had /dev/ptmx, it did not
#have grantpt(), unlockpt(), or ptsname(), so has been changed to look for a
#grantpt() prototype in the header files.Modified in 8.0.206 to allow for
#libraries that contain .so's but no .a's, e.g. Mandrake 9.0.
#HAVE_BAUDBOY added in 8.0.210 for Red Hat -- it's like AIX ttylock().
#Modified 17 Aug 2005 to use openpty() if available because the other stuff
#dumps core in 64-bit ia64 and x86_64 builds.
#Long file support for 32-bit builds added in 8.0.212 - if features.h contains
#__USE_LARGEFILE64 then we set the flags that must be set before reading any
#header files; on 32-bit platforms such as i386, this produces a 32-bit build
#capable of accessing, sending, receiving, and managing long (> 2GB) files.
#On 64-bit platforms, it does no harm.
#As of 3 March 2009 we detect automatically if we have curses, ncurses,
#or no curses at all.
#Added HAVE_LOCKDEV as openSuSE >= 11.3 uses ttylock directly instead of
#baudboy 2010/08/23
#OK: 2011/06/18
linux:
        @if test \
        `grep grantpt /usr/include/*.h /usr/include/sys/*.h | wc -l` -gt 0; \
        then if test -c /dev/ptmx; then HAVE_PTMX='-DHAVE_PTMX'; \
        else HAVE_PTMX=''; fi; fi ; \
        if test `grep openpty /usr/include/pty.h | wc -l` -gt 0; \
        then HAVE_OPENPTY='-DHAVE_OPENPTY'; \
        else HAVE_OPENPTY=''; fi ; \
        HAVE_LIBCURSES=''; \
        if test -f /usr/lib64/libncurses.so || \
           test -f /usr/lib/libncurses.a|| \
           test -f /usr/lib/libncurses.so; then \
          HAVE_LIBCURSES='-lncurses'; \
        else if test -f /usr/lib64/libcurses.so || \
           test -f /usr/lib/libcurses.a || \
           test -f /usr/lib/libcurses.so; then \
             HAVE_LIBCURSES='-lcurses'; fi; fi; \
        HAVE_CURSES=''; \
        if test -n '$$HAVE_LIBCURSES'; then \
          if test -f /usr/include/ncurses.h; then \
          HAVE_CURSES='-DCK_NCURSES-I/usr/include/ncurses'; \
          else if test -f /usr/include/curses.h; then \
          HAVE_CURSES='-DCK_CURSES'; \
        fi; fi; fi; \
        if test -f /usr/include/baudboy.h || test -f /usr/include/ttylock.h; \
        then HAVE_LOCKDEV='-DHAVE_LOCKDEV' ; \
        else HAVE_LOCKDEV='' ; fi ; \
        if test -f /usr/include/baudboy.h ; \
        then HAVE_BAUDBOY='-DHAVE_BAUDBOY' ; \
        else HAVE_BAUDBOY='' ; fi ; \
        $(MAKE) KTARGET=$${KTARGET:-$(@)} \
        "KFLAGS=$$HAVE_CURSES $$HAVE_PTMX $$HAVE_LOCKDEV \
        $$HAVE_BAUDBOY $$HAVE_OPENPTY \
        `grep __USE_LARGEFILE64 /usr/include/features.h > /dev/null && \
        echo '-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'` \
        `if test -f /usr/include/crypt.h; then echo -DHAVE_CRYPT_H; fi` \
        $(KFLAGS)" \
        "LIBS=$(LIBS) $$HAVE_LIBCURSES \
        `if test -n '$$HAVE_OPENPTY'; then echo -lutil; fi` \
        `if test -f /usr/lib64/libresolv.a || test -f /usr/lib64/libresolv.so \
        || test -f /usr/lib/libresolv.a || test -f /usr/lib/libresolv.so \
        || test -f /usr/lib/i386-linux-gnu/libresolv.a \
        || test -f /usr/lib/i386-linux-gnu/libresolv.so \
        || ls /lib/x86_64-linux-gnu/libresolv.* > /dev/null 2> /dev/null; \
        then echo -lresolv; fi` \
        `if test -f /usr/lib64/libcrypt.a || test -f /usr/lib64/libcrypt.so \
        || test -f /usr/lib/libcrypt.a || test -f /usr/lib/libcrypt.so \
        || ls /lib/x86_64-linux-gnu/libcrypt.* > /dev/null 2> /dev/null; \
        then echo -lcrypt; fi` \
        `if test -f /usr/lib64/liblockdev.a || \
        test -f /usr/lib64/liblockdev.so || \
        test -f /usr/lib/liblockdev.a || \
        test -f /usr/lib/liblockdev.so; \
        then echo -llockdev; fi`" \
        linuxa



二、在终端输入make linux后执行结果如下:

make: Entering directory `/home/abing/Yunio/GIU800/kermit1'
Making C-Kermit "9.0.302" for Linux 1.2 or later...
IMPORTANT: Read the comments in the linux section of the
makefile if you have trouble.
make xermit KTARGET=${KTARGET:-linuxa} "CC = gcc" "CC2 = gcc" \
"CFLAGS = -O -DLINUX -pipe -funsigned-char -DFNFLOAT -DCK_POSIX_SIG \
-DCK_NEWTERM -DTCPSOCKET -DLINUXFSSTND -DNOCOTFMC -DPOSIX \
-DUSE_STRERROR -DCK_NCURSES-I/usr/include/ncurses -DHAVE_PTMX -DHAVE_LOCKDEV -DHAVE_BAUDBOY -DHAVE_OPENPTY -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CRYPT_H " "LNKFLAGS = " \
"LIBS = -lncurses -lutil -lresolv -lcrypt -llockdev -lm"
make: Entering directory `/home/abing/Yunio/GIU800/kermit1'
gcc-o wermit \
        ckcmai.o ckclib.o ckutio.o ckufio.o \
        ckcfns.o ckcfn2.o ckcfn3.o ckuxla.o \
        ckcpro.o ckucmd.o ckuus2.o ckuus3.o \
        ckuus4.o ckuus5.o ckuus6.o ckuus7.o \
        ckuusx.o ckuusy.o ckuusr.o ckucns.o \
        ckudia.o ckuscr.o ckcnet.o ckusig.o \
        ckctel.o ckcuni.o ckupty.o ckcftp.o \
        ckuath.o ck_crp.o ck_ssl.o -lncurses -lutil -lresolv -lcrypt -llockdev -lm
make: Leaving directory `/home/abing/Yunio/GIU800/kermit1'
make: Leaving directory `/home/abing/Yunio/GIU800/kermit1'
+Done                  gedit makefile
页: [1]
查看完整版本: 关于makefile伪目标的问题