GNU make and NetBSD's bmake (which is also used by FreeBSD) 
support this.

This is based on the implementation from bmake.


Index: usr.bin/make/config.h
===================================================================
RCS file: /cvs/src/usr.bin/make/config.h,v
retrieving revision 1.20
diff -u -p -u -r1.20 config.h
--- usr.bin/make/config.h       18 Oct 2014 07:50:06 -0000      1.20
+++ usr.bin/make/config.h       8 Nov 2015 20:17:13 -0000
@@ -64,6 +64,12 @@
 #define SYSVVARSUB
 
 /*
+ * GMAKEEXPORT
+ *     Recognize gmake like variable export directives [export <VAR>=<VALUE>]
+ */
+#define GMAKEEXPORT
+
+/*
  * SUNSHCMD
  *     Recognize SunOS and Solaris:
  *             VAR :sh= CMD    # Assign VAR to the command substitution of CMD
@@ -94,6 +100,11 @@
 #else
 #define DOFEATURE_SYSVVARSUB   0
 #endif
+#ifdef GMAKEEXPORT
+#define DOFEATURE_GMAKEEXPORT  FEATURE_GMAKEEXPORT
+#else
+#define DOFEATURE_GMAKEEXPORT  0
+#endif
 #ifdef SUNSHCMD
 #define DOFEATURE_SUNSHCMD     FEATURE_SUNSHCMD
 #else
@@ -101,7 +112,10 @@
 #endif
 
 #ifndef DEFAULT_FEATURES
-#define DEFAULT_FEATURES       (FEATURE_UPPERLOWER | DOFEATURE_SYSVVARSUB | 
DOFEATURE_SYSVINCLUDE | DOFEATURE_SUNSHCMD | FEATURE_RECVARS | 
FEATURE_CONDINCLUDE)
+#define DEFAULT_FEATURES       (FEATURE_UPPERLOWER | DOFEATURE_SYSVVARSUB | \
+                                DOFEATURE_SYSVINCLUDE | DOFEATURE_SUNSHCMD | \
+                                FEATURE_RECVARS | FEATURE_CONDINCLUDE | \
+                                DOFEATURE_GMAKEEXPORT)
 #endif
 
 #define FEATURES(x)    ((DEFAULT_FEATURES & (x)) != 0)
@@ -116,6 +130,7 @@
 #define FEATURE_CONDINCLUDE    256
 #define FEATURE_ASSIGN         512
 #define FEATURE_EXECMOD                1024
+#define FEATURE_GMAKEEXPORT    2048
 
 /*
  * There are several places where expandable buffers are used (parse.c and
Index: usr.bin/make/parse.c
===================================================================
RCS file: /cvs/src/usr.bin/make/parse.c,v
retrieving revision 1.112
diff -u -p -u -r1.112 parse.c
--- usr.bin/make/parse.c        23 Jan 2015 22:35:57 -0000      1.112
+++ usr.bin/make/parse.c        8 Nov 2015 20:17:13 -0000
@@ -151,6 +151,7 @@ static bool lookup_bsd_include(const cha
 static void lookup_sysv_style_include(const char *, const char *, bool);
 static void lookup_sysv_include(const char *, const char *);
 static void lookup_conditional_include(const char *, const char *);
+static void handle_gmake_export(char *, const char *);
 static bool parse_as_special_line(Buffer, Buffer, const char *);
 static unsigned int parse_operator(const char **);
 
@@ -1226,6 +1227,28 @@ lookup_conditional_include(const char *f
        lookup_sysv_style_include(file, directive, false);
 }
 
+static void
+handle_gmake_export(char *line, const char *directive)
+{
+       char *variable = line;
+       char *value;
+
+       while (isspace((unsigned char)*variable))
+               variable++;
+
+       for (value = variable; *value && *value != '='; value++)
+               continue;
+
+       if (*value != '=') {
+               Parse_Error(PARSE_FATAL,
+                       "Variable/Value missing from \"%s\"", directive);
+               return;
+       }
+       *value++ = '\0';
+
+       value = Var_Subst(value, NULL, false);
+       setenv(variable, value, 1);
+}
 
 /***
  ***   BSD-specific . constructs
@@ -1469,6 +1492,13 @@ parse_as_special_line(Buffer buf, Buffer
            ISSPACE(line[8]) &&
            strchr(line, ':') == NULL) {
                lookup_conditional_include(line+8, "-include");
+               return true;
+       }
+       if (FEATURES(FEATURE_GMAKEEXPORT) &&
+           strncmp(line, "export", 6) == 0 &&
+           ISSPACE(line[6]) &&
+           strchr(line, ':') == NULL) {
+               handle_gmake_export((char *)line+6, "export");
                return true;
        }
        return false;
Index: usr.bin/make/make.1
===================================================================
RCS file: /cvs/src/usr.bin/make/make.1,v
retrieving revision 1.120
diff -u -p -u -r1.120 make.1
--- usr.bin/make/make.1 13 Mar 2015 19:58:41 -0000      1.120
+++ usr.bin/make/make.1 8 Nov 2015 20:17:13 -0000
@@ -974,6 +974,14 @@ in
 .At V
 variable substitutions is not mandated by POSIX, though it is
 fairly common.
+.Pp
+The
+.Ic export
+directive can be used to export a variable to the environment,
+using the syntax:
+.Bd -unfilled -offset indent
+.Ic export Ar NAME Ns = Ns Ar value
+.Ed
 .Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
 Makefile inclusion, conditional structures and for loops reminiscent
 of the C programming language are provided in


-- 
Carlin

Reply via email to