Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7174427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:02:56+00:00 2026-05-28T16:02:56+00:00

I am trying to write a make function to touch/create an empty file and/or

  • 0

I am trying to write a make function to touch/create an empty file and/or set the permissions, user and group, where possible, or warn if not. However, every conditional check within my function seems to evaluate to true.

The essentials of my Makefile are

INSTALL_USER  := fileUser
INSTALL_GROUP := fileGroup

.PHONY: test
test:
    $(call touchFile,~/test.ini)

define touchFile
$(eval fileName := $(strip $(1)))
-touch $(fileName)
-chmod -c 664 $(fileName)

$(info filename info $(fileName))
$(info $(shell stat -c "%a %U:%G" $(fileName)))

$(if ifeq  "foo" "bar", @echo match is broken, @echo match works)
$(if ifneq "foo" "bar", @echo match works, @echo match is broken)

$(if ifneq ($(shell stat -c %a $(fileName)),664), $(warning Error - $(fileName) does not have expected permissions of 664))
-chgrp -c $(INSTALL_GROUP) $(fileName)
$(if ifneq ($(shell stat -c %G $(fileName)),$(INSTALL_GROUP)), $(warning Error - $(fileName) does not belong to $(INSTALL_GROUP) group))
-chown -c $(INSTALL_USER) $(fileName)
$(if ifneq ($(shell stat -c %U $(fileName)),$(INSTALL_USER)), $(warning Error - $(fileName) does not belong to $(INSTALL_USER) user))
endef

Running make test outputs

filename info ~/test.ini
664 myUserName:myGroup
Makefile:7: Error - ~/test.ini does not have expected permissions of 664
Makefile:7: Error - ~/test.ini does not belong to common group
Makefile:7: Error - ~/test.ini does not belong to netserve user
touch ~/test.ini
chmod -c 664 ~/test.ini
match is broken
match works
chgrp -c fileGroup ~/test.ini
changed group of `/home/myUserName/test.ini' to fileGroup
chown -c fileUser ~/test.ini
chown: changing ownership of `/home/myUserName/test.ini': Operation not permitted
make: [test] Error 1 (ignored)

I’ve considered/tried the following:

  • $(if …) is evaluated at “compile-time”, before the function is called with a parameter. But, the hard-coded ifeq "foo" "bar" also gives an invalid result. Additionally, $(info ...) correctly evaluates $(fileName) at “compile-time”.
  • The documentation doesn’t actually give examples, so in addition to $(if ifeq...), I also tried $(ifeq ...), which seemed to be ignored.
  • “Non-functional” if (i.e., the ifeq without the $(if...)) inside a function gives /bin/sh: ifeq: command not found.

Can someone help identify why my conditionals aren’t behaving as I expect (or why I’m expecting the wrong thing)?

Caveat: I know there are still bugs to be worked out if the file doesn’t exist, but that should be trivial compared to this hurdle.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:02:58+00:00Added an answer on May 28, 2026 at 4:02 pm

    $(if ...) conditional function evaluates to true when the first argument passed to it is non-empty. In you case the condition is literal text: ifeq "foo" "bar", which is, obviously, non-empty.

    ifeq/ifneq conditionals are in fact directives, not functions. They can’t be used inside variable definition and in functions.

    Back to your example, to test string for equality inside the condition use functions like filter and findstring:

    $(if $(filter foo,bar),@echo match is broken,@echo match works)
    $(if $(filter-out foo,bar),@echo match works,@echo match is broken)
    

    BTW this could be also turned into an inline form for better readability:

    @echo match $(if $(filter foo,bar),is broken,works)
    @echo match $(if $(filter-out foo,bar),works,is broken)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a C# function and make it accept any type parameter.
i am trying to write a function that will make DataRow[column] return nullable typed
So i am trying to make a function that searches trough an xml file,
I am trying to modify the example http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-reading-files to make function handleFileSelect(evt) return reader.result;
I am trying to make this function download file from the internet. I pass
I have been trying to write a constructor function that would make an object
I'm trying to write a macro to make a specific usage of callbacks in
I'm trying to write a stored procedure in SQL that will : Make a
Trying to write a couple of functions that will encrypt or decrypt a file
Im trying to write a single byte at a certain location in a file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.