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