Home | History | Annotate | Download | only in utils
      1 #
      2 #  Copyright (c) Red Hat Inc., 2008
      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 2 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
     12 #  the 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, write to the Free Software
     16 #  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     17 #
     18 
     19 # Author: Masatake YAMATO <yamato (at] redhat.com>
     20 # Technique used here is suggested by Ngie Cooper <yaneurabeya (at] gmail.com>
     21 
     22 # Usage:
     23 #
     24 # This makefile snippet is for writing test cases
     25 # for foo16 system calls. Here I assume you already have
     26 # test cases for foo like foo01, foo02.. fooN and I also
     27 # assume the source file name for fooN is fooN.c.
     28 # On the above assumption, this file does:
     29 #
     30 # * adding fooN_16 as MAKE_TARGETS,
     31 # * making *.c depend on compat_16.h if the header file exists,
     32 # * adding rules to build fooN_16 from fooN.c (and compat_16.h), and
     33 # * passing a cpp symbol TST_USE_COMPAT16_SYSCALL to
     34 #   CC when building fooN_16.
     35 #
     36 #
     37 # You can use this file in following procedures:
     38 #
     39 # 1. write fooN.c.
     40 # 2. add the code for 16 bit syscall and wrap
     41 #    it #ifdef TST_USE_COMPAT16_SYSCALL/endif.
     42 # 3. introduce your own compat_16.h if the ifdef
     43 #    block is too large.
     44 # 4. don't forget putting compat_16.h in all fooN.c
     45 #    if you introduced compat_16.h.
     46 # 5. include this file compat_16.mk in your Makefile.
     47 # 6. use `+=' instead of `=' as assignment operator for MAKE_TARGETS.
     48 # 7. Added extra definitions to CFLAGS in %_16 target if needed.
     49 #
     50 # See Makefile of setuid test case.
     51 #
     52 
     53 CPPFLAGS		+= -I$(abs_srcdir) -I$(abs_srcdir)/../utils
     54 
     55 SRCS			?= $(wildcard $(abs_srcdir)/*.c)
     56 
     57 MAKE_TARGETS		:= $(notdir $(patsubst %.c,%,$(SRCS)))
     58 MAKE_TARGETS_OBJS_WO_COMPAT_16	:= $(addsuffix .o,$(MAKE_TARGETS))
     59 
     60 ifneq ($(TST_COMPAT_16_SYSCALL),no)
     61 MAKE_TARGETS		+= $(addsuffix _16,$(MAKE_TARGETS))
     62 endif
     63 
     64 # XXX (garrcoop): This code should be put in question as it cannot be applied
     65 # (no .h file, no TST_USE_NEWER64_SYSCALL def).
     66 DEF_16			:= TST_USE_COMPAT16_SYSCALL
     67 
     68 COMPAT_16_H		:= $(abs_srcdir)/../utils/compat_16.h
     69 
     70 ifneq ($(wildcard $(COMPAT_16_H)),)
     71 HAS_COMPAT_16		:= 1
     72 
     73 $(MAKE_TARGETS_OBJS_WO_COMPAT_16): $(COMPAT_16_H)
     74 .INTERMEDIATE: $(MAKE_TARGETS_OBJS_WO_COMPAT_16)
     75 
     76 else
     77 HAS_COMPAT_16		:= 0
     78 endif
     79 
     80 %_16: CPPFLAGS += -D$(DEF_16)=1
     81 # XXX (garrcoop): End section of code in question..
     82 
     83 %_16.o: %.c $(COMPAT_16_H)
     84 	$(COMPILE.c) $(OUTPUT_OPTION) $<
     85