makefile                
            उन्नत मेकफाइल
        
        
            
    खोज…
अलग-अलग स्रोत फ़ोल्डर से अलग-अलग लक्ष्य फ़ोल्डर में बिल्डिंग
इस मेकफाइल की मुख्य विशेषताएं:
- निर्दिष्ट फ़ोल्डरों में सी स्रोतों का स्वचालित पता लगाना
- एकाधिक स्रोत फ़ोल्डर
- ऑब्जेक्ट और निर्भरता फ़ाइलों के लिए एकाधिक संगत लक्ष्य फ़ोल्डर
- प्रत्येक लक्ष्य फ़ोल्डर के लिए स्वचालित नियम निर्माण
- जब वे मौजूद न हों तो लक्ष्य फ़ोल्डरों का निर्माण
-  साथ निर्भरता प्रबंधन gcc: बिल्ड केवल क्या आवश्यक है
-  UnixऔरDOSसिस्टम पर काम करता है
- जीएनयू मेक के लिए लिखा
इस प्रकार की संरचना के साथ प्रोजेक्ट बनाने के लिए इस मेकफाइल का उपयोग किया जा सकता है:
\---Project
    +---Sources
    |   +---Folder0
    |   |       main.c
    |   |       
    |   +---Folder1
    |   |       file1_1.c
    |   |       file1_1.h
    |   |       
    |   \---Folder2
    |           file2_1.c
    |           file2_1.h
    |           file2_2.c
    |           file2_2.h
    \---Build
        |   Makefile
        |   myApp.exe
        |   
        +---Folder0
        |       main.d
        |       main.o
        |       
        +---Folder1
        |       file1_1.d
        |       file1_1.o
        |       
        \---Folder2
                file2_1.d
                file2_1.o
                file2_2.d
                file2_2.o
makefile
# Set project directory one level above of Makefile directory. $(CURDIR) is a GNU make variable containing the path to the current working directory
PROJDIR := $(realpath $(CURDIR)/..)
SOURCEDIR := $(PROJDIR)/Sources
BUILDDIR := $(PROJDIR)/Build
# Name of the final executable
TARGET = myApp.exe
# Decide whether the commands will be shwon or not
VERBOSE = TRUE
# Create the list of directories
DIRS = Folder0 Folder1 Folder2
SOURCEDIRS = $(foreach dir, $(DIRS), $(addprefix $(SOURCEDIR)/, $(dir)))
TARGETDIRS = $(foreach dir, $(DIRS), $(addprefix $(BUILDDIR)/, $(dir)))
# Generate the GCC includes parameters by adding -I before each source folder
INCLUDES = $(foreach dir, $(SOURCEDIRS), $(addprefix -I, $(dir)))
# Add this list to VPATH, the place make will look for the source files
VPATH = $(SOURCEDIRS)
# Create a list of *.c sources in DIRS
SOURCES = $(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.c))
# Define objects for all sources
OBJS := $(subst $(SOURCEDIR),$(BUILDDIR),$(SOURCES:.c=.o))
# Define dependencies files for all objects
DEPS = $(OBJS:.o=.d)
# Name the compiler
CC = gcc
# OS specific part
ifeq ($(OS),Windows_NT)
    RM = del /F /Q 
    RMDIR = -RMDIR /S /Q
    MKDIR = -mkdir
    ERRIGNORE = 2>NUL || true
    SEP=\\
else
    RM = rm -rf 
    RMDIR = rm -rf 
    MKDIR = mkdir -p
    ERRIGNORE = 2>/dev/null
    SEP=/
endif
# Remove space after separator
PSEP = $(strip $(SEP))
# Hide or not the calls depending of VERBOSE
ifeq ($(VERBOSE),TRUE)
    HIDE =  
else
    HIDE = @
endif
# Define the function that will generate each rule
define generateRules
$(1)/%.o: %.c
    @echo Building $$@
    $(HIDE)$(CC) -c $$(INCLUDES) -o $$(subst /,$$(PSEP),$$@) $$(subst /,$$(PSEP),$$<) -MMD
endef
.PHONY: all clean directories 
all: directories $(TARGET)
$(TARGET): $(OBJS)
    $(HIDE)echo Linking $@
    $(HIDE)$(CC) $(OBJS) -o $(TARGET)
# Include dependencies
-include $(DEPS)
# Generate rules
$(foreach targetdir, $(TARGETDIRS), $(eval $(call generateRules, $(targetdir))))
directories: 
    $(HIDE)$(MKDIR) $(subst /,$(PSEP),$(TARGETDIRS)) $(ERRIGNORE)
# Remove all objects, dependencies and executable files generated during the build
clean:
    $(HIDE)$(RMDIR) $(subst /,$(PSEP),$(TARGETDIRS)) $(ERRIGNORE)
    $(HIDE)$(RM) $(TARGET) $(ERRIGNORE)
    @echo Cleaning done ! 
इस Makefile का उपयोग कैसे करें इस Makefile को अपनी परियोजना में अनुकूलित करने के लिए:
-  अपने लक्षित नाम से मिलान करने के लिए TARGETचर बदलें
-  SourcesऔरBuildफ़ोल्डर का नामSOURCEDIRऔरBUILDDIR
- मेकफिल में मेकफिल के वर्बोसिटी लेवल को स्वयं या मेक कॉल में बदलें
-  अपने स्रोतों से मिलान करने और फ़ोल्डरों के निर्माण के लिए DIRSमें फ़ोल्डरों का नाम बदलें
- यदि आवश्यक हो, तो संकलक और झंडे बदलें
जिपिंग सूची
 जीएनयू बनाते हैं 
    
    
    
    
     इस pairmap कार्य में तीन तर्क होते हैं: 
- एक फ़ंक्शन नाम
- पहली अंतरिक्ष-पृथक सूची
- दूसरी अंतरिक्ष-पृथक सूची
सूचियों में प्रत्येक ज़िप्ड टपल के लिए यह निम्न तर्कों के साथ फ़ंक्शन को कॉल करेगा:
- पहली सूची से टपल तत्व
- दूसरी सूची से टपल तत्व
यह फ़ंक्शन विस्तार की एक अंतरिक्ष-पृथक सूची में विस्तारित होगा।
list-rem = $(wordlist 2,$(words $1),$1)
pairmap = $(and $(strip $2),$(strip $3),$(call \
    $1,$(firstword $2),$(firstword $3)) $(call \
    pairmap,$1,$(call list-rem,$2),$(call list-rem,$3)))
उदाहरण के लिए, यह:
LIST1 := foo bar baz
LIST2 := 1 2 3
func = $1-$2
all:
    @echo $(call pairmap,func,$(LIST1),$(LIST2))
.PHONY: all
 foo-1 bar-2 baz-3 प्रिंट करेगा। 
Modified text is an extract of the original Stack Overflow Documentation
        के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
        से संबद्ध नहीं है Stack Overflow